2016-07-14 08:47:50 +00:00
|
|
|
<?php
|
|
|
|
|
2017-02-14 06:53:02 +00:00
|
|
|
namespace Tests\Feature;
|
|
|
|
|
2016-07-14 08:47:50 +00:00
|
|
|
use App\Models\Song;
|
|
|
|
use App\Services\YouTube;
|
|
|
|
use GuzzleHttp\Client;
|
|
|
|
use GuzzleHttp\Psr7\Response;
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
|
|
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
2016-07-30 15:34:34 +00:00
|
|
|
use Mockery as m;
|
2017-02-14 06:53:02 +00:00
|
|
|
use Tests\BrowserKitTestCase;
|
2016-07-14 08:47:50 +00:00
|
|
|
use YouTube as YouTubeFacade;
|
|
|
|
|
2017-02-14 06:53:02 +00:00
|
|
|
class YouTubeTest extends BrowserKitTestCase
|
2016-07-14 08:47:50 +00:00
|
|
|
{
|
|
|
|
use DatabaseTransactions, WithoutMiddleware;
|
|
|
|
|
|
|
|
public function testSearch()
|
|
|
|
{
|
|
|
|
$this->withoutEvents();
|
|
|
|
|
|
|
|
$client = m::mock(Client::class, [
|
2017-02-14 06:53:02 +00:00
|
|
|
'get' => new Response(200, [], file_get_contents(__DIR__.'../../blobs/youtube/search.json')),
|
2016-07-14 08:47:50 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
$api = new YouTube(null, $client);
|
|
|
|
$response = $api->search('Lorem Ipsum');
|
|
|
|
|
|
|
|
$this->assertEquals('Slipknot - Snuff [OFFICIAL VIDEO]', $response->items[0]->snippet->title);
|
|
|
|
|
|
|
|
// Is it cached?
|
2016-12-12 02:43:14 +00:00
|
|
|
$this->assertNotNull(cache('1492972ec5c8e6b3a9323ba719655ddb'));
|
2016-07-14 08:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testSearchVideosRelatedToSong()
|
|
|
|
{
|
|
|
|
$this->createSampleMediaSet();
|
|
|
|
$song = Song::first();
|
|
|
|
|
|
|
|
// We test on the facade here
|
2016-07-30 15:49:14 +00:00
|
|
|
YouTubeFacade::shouldReceive('searchVideosRelatedToSong')->once();
|
2016-07-14 08:47:50 +00:00
|
|
|
|
2017-02-14 06:53:02 +00:00
|
|
|
$this->getAsUser("/api/youtube/search/song/{$song->id}");
|
2016-07-14 08:47:50 +00:00
|
|
|
}
|
|
|
|
}
|