Exemplo n.º 1
0
 public function testImgurFail()
 {
     $imgurClient = $this->getMockBuilder('Imgur\\Client')->disableOriginalConstructor()->getMock();
     $imgurClient->expects($this->any())->method('api')->will($this->throwException(new \Guzzle\Http\Exception\RequestException()));
     $imgur = new Imgur($imgurClient);
     $logHandler = new TestHandler();
     $logger = new Logger('test', array($logHandler));
     $imgur->setLogger($logger);
     $imgur->match('http://imgur.com/gallery/IoKwI7E');
     $this->assertEmpty($imgur->getContent());
     $this->assertTrue($logHandler->hasWarning('Imgur extract failed for: IoKwI7E'), 'Warning message matched');
 }
Exemplo n.º 2
0
 public function testContentBadResponse()
 {
     $twitterOAuth = $this->getMockBuilder('TwitterOAuth\\TwitterOAuth')->disableOriginalConstructor()->getMock();
     $twitterOAuth->expects($this->once())->method('get')->will($this->throwException(new TwitterException()));
     $twitter = new Twitter($twitterOAuth);
     $logHandler = new TestHandler();
     $logger = new Logger('test', array($logHandler));
     $twitter->setLogger($logger);
     $twitter->match('https://twitter.com/DoerteDev/statuses/506522223860277248');
     $this->assertEmpty($twitter->getContent());
     $this->assertTrue($logHandler->hasWarning('Twitter extract failed for: 506522223860277248'), 'Warning message matched');
 }
Exemplo n.º 3
0
 public function testContentWithException()
 {
     $client = new Client();
     $mock = new Mock([new Response(400, [], Stream::factory('oops'))]);
     $client->getEmitter()->attach($mock);
     $camplus = new Camplus();
     $camplus->setClient($client);
     $logHandler = new TestHandler();
     $logger = new Logger('test', array($logHandler));
     $camplus->setLogger($logger);
     $camplus->match('http://campl.us/rL9Q');
     // this one will catch an exception
     $this->assertEmpty($camplus->getContent());
     $this->assertTrue($logHandler->hasWarning('Camplus extract failed for: rL9Q'), 'Warning message matched');
 }
Exemplo n.º 4
0
 public function testContentWithException()
 {
     $client = new Client();
     $mock = new Mock([new Response(400, [], Stream::factory('oops'))]);
     $client->getEmitter()->attach($mock);
     $deviantart = new Deviantart();
     $deviantart->setClient($client);
     $logHandler = new TestHandler();
     $logger = new Logger('test', array($logHandler));
     $deviantart->setLogger($logger);
     $deviantart->match('http://mibreit.deviantart.com/art/A-Piece-of-Heaven-357105002');
     // this one will catch an exception
     $this->assertEmpty($deviantart->getContent());
     $this->assertTrue($logHandler->hasWarning('Deviantart extract failed for: http://mibreit.deviantart.com/art/A-Piece-of-Heaven-357105002'), 'Warning message matched');
 }
Exemplo n.º 5
0
 public function testPhotoSet()
 {
     $client = new Client();
     $mock = new Mock([new Response(200, [], Stream::factory(json_encode(array('stat' => 'ok', 'photoset' => array('photo' => array(array('title' => 'Super title', 'url_l' => 'https://0.0.0.0/medium.jpg'), array('title' => 'Ugly title', 'url_o' => 'https://0.0.0.0/large.jpg'))))))), new Response(200, [], Stream::factory('')), new Response(400, [], Stream::factory('oops'))]);
     $client->getEmitter()->attach($mock);
     $flickr = new Flickr('apikey');
     $flickr->setClient($client);
     $logHandler = new TestHandler();
     $logger = new Logger('test', array($logHandler));
     $flickr->setLogger($logger);
     // first test fail because we didn't match an url, so FlickrId isn't defined
     $this->assertEmpty($flickr->getContent());
     $flickr->match('https://www.flickr.com/photos/europeanspaceagency/sets/72157638315605535/');
     // consecutive calls
     $this->assertContains('<div><p>Super title</p><img src="https://0.0.0.0/medium.jpg" /></div>', $flickr->getContent());
     // this one will got an empty array
     $this->assertEmpty($flickr->getContent());
     // this one will catch an exception
     $this->assertEmpty($flickr->getContent());
     $this->assertTrue($logHandler->hasWarning('Flickr extract failed for: 72157638315605535'), 'Warning message matched');
 }
Exemplo n.º 6
0
 public function testContent()
 {
     $client = new Client();
     $mock = new Mock([new Response(200, [], Stream::factory(json_encode(array('video' => array('title' => 'my title', 'thumbnail_url' => 'http://0.0.0.0/img.jpg', 'embed_url' => 'http://0.0.0.0/embed'))))), new Response(200, [], Stream::factory('')), new Response(400, [], Stream::factory('oops'))]);
     $client->getEmitter()->attach($mock);
     $vidme = new Vidme();
     $vidme->setClient($client);
     $logHandler = new TestHandler();
     $logger = new Logger('test', array($logHandler));
     $vidme->setLogger($logger);
     // first test fail because we didn't match an url, so VidmeId isn't defined
     $this->assertEmpty($vidme->getContent());
     $vidme->match('https://vid.me/WaJr');
     // consecutive calls
     $this->assertEquals('<div><h2>my title</h2><p><img src="http://0.0.0.0/img.jpg"></p><iframe src="http://0.0.0.0/embed"></iframe></div>', $vidme->getContent());
     // this one will got an empty array
     $this->assertEmpty($vidme->getContent());
     // this one will catch an exception
     $this->assertEmpty($vidme->getContent());
     $this->assertTrue($logHandler->hasWarning('Vidme extract failed for: https://vid.me/WaJr'), 'Warning message matched');
 }
Exemplo n.º 7
0
 public function testContent()
 {
     $client = new Client();
     $mock = new Mock([new Response(200, [], Stream::factory(json_encode(array('title' => 'my title', 'description' => 'my description', 'thumbnail_url' => 'http://0.0.0.0/img.jpg', 'html' => '<iframe/>')))), new Response(200, [], Stream::factory('')), new Response(400, [], Stream::factory('oops'))]);
     $client->getEmitter()->attach($mock);
     $soundCloud = new Soundcloud();
     $soundCloud->setClient($client);
     $logHandler = new TestHandler();
     $logger = new Logger('test', array($logHandler));
     $soundCloud->setLogger($logger);
     // first test fail because we didn't match an url, so SoundcloudUrl isn't defined
     $this->assertEmpty($soundCloud->getContent());
     $soundCloud->match('https://soundcloud.com/birdfeeder/jurassic-park-theme-1000-slower');
     // consecutive calls
     $this->assertEquals('<div><h2>my title</h2><p>my description</p><p><img src="http://0.0.0.0/img.jpg"></p><iframe/></div>', $soundCloud->getContent());
     // this one will got an empty array
     $this->assertEmpty($soundCloud->getContent());
     // this one will catch an exception
     $this->assertEmpty($soundCloud->getContent());
     $this->assertTrue($logHandler->hasWarning('Soundcloud extract failed for: https://soundcloud.com/birdfeeder/jurassic-park-theme-1000-slower'), 'Warning message matched');
 }
Exemplo n.º 8
0
 public function testContent()
 {
     $client = new Client();
     $mock = new Mock([new Response(200, [], Stream::factory(json_encode(array('title' => 'my title', 'thumbnail_url' => 'http://0.0.0.0/img.jpg', 'html' => '<iframe/>')))), new Response(200, [], Stream::factory('')), new Response(400, [], Stream::factory('oops'))]);
     $client->getEmitter()->attach($mock);
     $dailymotion = new Dailymotion();
     $dailymotion->setClient($client);
     $logHandler = new TestHandler();
     $logger = new Logger('test', array($logHandler));
     $dailymotion->setLogger($logger);
     // first test fail because we didn't match an url, so DailymotionUrl isn't defined
     $this->assertEmpty($dailymotion->getContent());
     $dailymotion->match('https://www.dailymotion.com/video/xockol_planete-des-hommes-partie-1-2_travel');
     // consecutive calls
     $this->assertEquals('<div><h2>my title</h2><p><img src="http://0.0.0.0/img.jpg"></p><iframe/></div>', $dailymotion->getContent());
     // this one will got an empty array
     $this->assertEmpty($dailymotion->getContent());
     // this one will catch an exception
     $this->assertEmpty($dailymotion->getContent());
     $this->assertTrue($logHandler->hasWarning('Dailymotion extract failed for: https://www.dailymotion.com/video/xockol_planete-des-hommes-partie-1-2_travel'), 'Warning message matched');
 }
Exemplo n.º 9
0
 public function testContent()
 {
     $client = new Client();
     $mock = new Mock([new Response(200, [], Stream::factory(json_encode(array('gfyItem' => array('title' => 'my title', 'gifUrl' => 'http://0.0.0.0/img.gif'))))), new Response(200, [], Stream::factory('')), new Response(400, [], Stream::factory('oops'))]);
     $client->getEmitter()->attach($mock);
     $gfycat = new Gfycat();
     $gfycat->setClient($client);
     $logHandler = new TestHandler();
     $logger = new Logger('test', array($logHandler));
     $gfycat->setLogger($logger);
     // first test fail because we didn't match an url, so GfycatId isn't defined
     $this->assertEmpty($gfycat->getContent());
     $gfycat->match('http://gfycat.com/SingleUntriedBudgie');
     // consecutive calls
     $this->assertEquals('<div><h2>my title</h2><p><img src="http://0.0.0.0/img.gif"></p></div>', $gfycat->getContent());
     // this one will got an empty array
     $this->assertEmpty($gfycat->getContent());
     // this one will catch an exception
     $this->assertEmpty($gfycat->getContent());
     $this->assertTrue($logHandler->hasWarning('Gfycat extract failed for: SingleUntriedBudgie'), 'Warning message matched');
 }
Exemplo n.º 10
0
 public function testContent()
 {
     $client = new Client();
     $mock = new Mock([new Response(200, ['X-Tumblr-User' => 'test']), new Response(200, ['X-Tumblr-User' => 'test'], Stream::factory(json_encode(array('response' => array('posts' => array(array('body' => '<div>content</div>'))))))), new Response(200, ['X-Tumblr-User' => 'test'], Stream::factory(json_encode(array()))), new Response(400, ['X-Tumblr-User' => 'test'], Stream::factory('oops'))]);
     $client->getEmitter()->attach($mock);
     $tumblr = new Tumblr('apikey');
     $tumblr->setClient($client);
     $logHandler = new TestHandler();
     $logger = new Logger('test', array($logHandler));
     $tumblr->setLogger($logger);
     // first test fail because we didn't match an url, so TumblrId isn't defined
     $this->assertEmpty($tumblr->getContent());
     $tumblr->match('http://thecodinglove.com/post/96365413702/client-giving-us-his-feedback-on-his-new-project');
     // consecutive calls
     $this->assertEquals('<div>content</div>', $tumblr->getContent());
     // this one will got an empty array
     $this->assertEmpty($tumblr->getContent());
     // this one will catch an exception
     $this->assertEmpty($tumblr->getContent());
     $this->assertTrue($logHandler->hasWarning('Tumblr extract failed for: 96365413702 & thecodinglove.com'), 'Warning message matched');
 }
Exemplo n.º 11
0
 public function testContent()
 {
     $client = new Client();
     $mock = new Mock([new Response(200, [], Stream::factory(json_encode(array('title' => 'my title', 'thumbnail_url' => 'http://0.0.0.0/img.jpg', 'html' => '<iframe/>')))), new Response(200, [], Stream::factory('')), new Response(400, [], Stream::factory('oops'))]);
     $client->getEmitter()->attach($mock);
     $spotify = new Spotify();
     $spotify->setClient($client);
     $logHandler = new TestHandler();
     $logger = new Logger('test', array($logHandler));
     $spotify->setLogger($logger);
     // first test fail because we didn't match an url, so SpotifyUrl isn't defined
     $this->assertEmpty($spotify->getContent());
     $spotify->match('https://play.spotify.com/artist/4njdEjTnLfcGImKZu1iSrz');
     // consecutive calls
     $this->assertEquals('<div><h2>my title</h2><p><img src="http://0.0.0.0/img.jpg"></p><iframe/></div>', $spotify->getContent());
     // this one will got an empty array
     $this->assertEmpty($spotify->getContent());
     // this one will catch an exception
     $this->assertEmpty($spotify->getContent());
     $this->assertTrue($logHandler->hasWarning('Spotify extract failed for: https://play.spotify.com/artist/4njdEjTnLfcGImKZu1iSrz'), 'Warning message matched');
 }