Skip to content

Commit

Permalink
Fix Imgur gallery vs album
Browse files Browse the repository at this point in the history
And udpate deps
  • Loading branch information
j0k3r committed May 29, 2015
1 parent bb2f585 commit c52f936
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 18 deletions.
30 changes: 15 additions & 15 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/FeedBundle/Extractor/Imgur.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,16 @@ public function getContent()
try {
switch ($this->type) {
case 'a':
case 'gallery':
$album = $this->imgurClient->api('album')->album($this->hash);
$images = $album->getImages();

$content = '<h2>'.$album->getTitle().'</h2><p>'.$album->getDescription().'</p>';
break;

case 'gallery':
$images[] = $this->imgurClient->api('gallery')->image($this->hash);
break;

default:
$images[] = $this->imgurClient->api('image')->image($this->hash);
break;
Expand Down
43 changes: 41 additions & 2 deletions src/FeedBundle/Tests/Extractor/ImgurTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public function dataMatch()
array('https://imgur.com/a/dLaMy', true),
array('https://imgur.com/a/dLaMy?gallery', true),
array('https://imgur.com/gallery/dLaMy', true),
array('http://imgur.com/gallery/IDuXHMJ', true),
array('https://imgur.com/duziauziaozaoLaMy', false),
array('https://imgur.com/Ay', false),
array('http://imgur.com/UMOCfIk.gifv', true),
Expand Down Expand Up @@ -76,7 +77,7 @@ public function testContentImage()
$this->assertEquals('<div><p>title – description</p><img src="http://localhost" /></div>', $imgur->getContent());
}

public function testContentGallery()
public function testContentAlbum()
{
$imgurClient = $this->getMockBuilder('Imgur\Client')
->disableOriginalConstructor()
Expand Down Expand Up @@ -120,11 +121,49 @@ public function testContentGallery()
->will($this->returnValue($apiAlbum));

$imgur = new Imgur($imgurClient);
$imgur->match('http://imgur.com/gallery/IoKwI7E');
$imgur->match('http://imgur.com/a/IoKwI7E');

$this->assertEquals('<h2>album title</h2><p></p><div><img src="http://localhost" /></div>', $imgur->getContent());
}

public function testContentGallery()
{
$imgurClient = $this->getMockBuilder('Imgur\Client')
->disableOriginalConstructor()
->getMock();

$apiGallery = $this->getMockBuilder('Imgur\Api\Gallery')
->disableOriginalConstructor()
->getMock();

$image = $this->getMockBuilder('Imgur\Api\Model\Image')
->disableOriginalConstructor()
->getMock();

$image->expects($this->any())
->method('getTitle')
->will($this->returnValue(''));
$image->expects($this->any())
->method('getDescription')
->will($this->returnValue(''));
$image->expects($this->any())
->method('getLink')
->will($this->returnValue('http://localhost'));

$apiGallery->expects($this->any())
->method('image')
->will($this->returnValue($image));

$imgurClient->expects($this->any())
->method('api')
->will($this->returnValue($apiGallery));

$imgur = new Imgur($imgurClient);
$imgur->match('http://imgur.com/gallery/IoKwI7E');

$this->assertEquals('<div><img src="http://localhost" /></div>', $imgur->getContent());
}

public function testNoHashNoType()
{
$imgurClient = $this->getMockBuilder('Imgur\Client')
Expand Down

0 comments on commit c52f936

Please sign in to comment.