Skip to content

Commit 6edaff2

Browse files
committed
improved tests
1 parent 72f9ac5 commit 6edaff2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+797
-557
lines changed

composer.json

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,36 @@
11
{
2-
"name": "embed/embed",
3-
"type": "library",
4-
"description": "PHP library to retrieve page info using oembed, opengraph, etc",
5-
"keywords": ["oembed", "opengraph", "twitter cards", "embed", "embedly"],
6-
"homepage": "https://github.com/oscarotero/Embed",
7-
"license": "MIT",
8-
"authors": [
9-
{
10-
"name": "Oscar Otero",
11-
"email": "[email protected]",
12-
"homepage": "http://oscarotero.com",
13-
"role": "Developer"
14-
}
15-
],
16-
"support": {
17-
"email": "[email protected]",
18-
"issues": "https://github.com/oscarotero/Embed/issues"
19-
},
20-
"require": {
21-
"php": ">=5.4.0",
22-
"ext-curl": "*"
23-
},
24-
"require-dev": {
25-
"phpunit/phpunit": "~4.0"
2+
"name": "embed/embed",
3+
"type": "library",
4+
"description": "PHP library to retrieve page info using oembed, opengraph, etc",
5+
"keywords": ["oembed", "opengraph", "twitter cards", "embed", "embedly"],
6+
"homepage": "https://github.com/oscarotero/Embed",
7+
"license": "MIT",
8+
"authors": [
9+
{
10+
"name": "Oscar Otero",
11+
"email": "[email protected]",
12+
"homepage": "http://oscarotero.com",
13+
"role": "Developer"
14+
}
15+
],
16+
"support": {
17+
"email": "[email protected]",
18+
"issues": "https://github.com/oscarotero/Embed/issues"
2619
},
27-
"autoload": {
28-
"psr-4": {
29-
"Embed\\": "src"
30-
}
31-
}
20+
"require": {
21+
"php": ">=5.4.0",
22+
"ext-curl": "*"
23+
},
24+
"require-dev": {
25+
"phpunit/phpunit": "~4.0",
26+
"guzzlehttp/guzzle": "5.x"
27+
},
28+
"suggest": {
29+
"guzzlehttp/[email protected]": "To use Guzzle5 request resolver"
30+
},
31+
"autoload": {
32+
"psr-4": {
33+
"Embed\\": "src"
34+
}
35+
}
3236
}

phpunit.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
<phpunit bootstrap="./tests/bootstrap.php">
2+
<php>
3+
<env name="embed_resolver" value="Guzzle5"/>
4+
</php>
5+
26
<testsuites>
37
<testsuite name="All tests">
48
<directory>./tests/</directory>

src/Adapters/Adapter.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,15 +403,19 @@ public function getImageHeight()
403403
*/
404404
public function getWidth()
405405
{
406-
return Utils::getFirstValue(Utils::getData($this->providers, 'width'));
406+
$val = Utils::getFirstValue(Utils::getData($this->providers, 'width'));
407+
408+
return $val ? (is_numeric($val) ? (int) $val : $val) : null;
407409
}
408410

409411
/**
410412
* {@inheritdoc}
411413
*/
412414
public function getHeight()
413415
{
414-
return Utils::getFirstValue(Utils::getData($this->providers, 'height'));
416+
$val = Utils::getFirstValue(Utils::getData($this->providers, 'height'));
417+
418+
return $val ? (is_numeric($val) ? (int) $val : $val) : null;
415419
}
416420

417421
/**

src/Request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function __construct($url, $resolverClass = null, array $resolverConfig =
2828
{
2929
if ($resolverClass !== null) {
3030
if (!class_exists($resolverClass)) {
31-
throw new \InvalidArgumentException("This class does not exists");
31+
throw new \InvalidArgumentException("The resolver class '{$resolverClass}' does not exists");
3232
}
3333

3434
$reflection = new \ReflectionClass($resolverClass);

src/RequestResolvers/Guzzle5.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ public function __construct($url, array $config)
5454
*
5555
* @return int The http code
5656
*/
57-
public function getHttpCode()
57+
public function getHttpCode()
5858
{
59-
return $this->getResponse()->getStatusCode();
59+
return $this->getResponse()->getStatusCode();
6060
}
6161

6262
/**
@@ -85,7 +85,7 @@ public function getContent()
8585
* @return string The final url
8686
*/
8787
public function getUrl()
88-
{
88+
{
8989
return $this->getResponse()->getEffectiveUrl();
9090
}
9191

tests/AnimotoTest.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ class AnimotoTest extends TestCaseBase
33
{
44
public function testOne()
55
{
6-
$info = $this->getInfo('https://animoto.com/play/JzwsBn5FRVxS0qoqcBP5zA');
7-
8-
$this->assertString($info->title, 'Juno Groove');
9-
$this->assertString($info->width, 640);
10-
$this->assertString($info->height, 360);
11-
$this->assertString($info->type, 'video');
12-
$this->assertString($info->authorName, 'Chris Korhonen');
13-
$this->assertString($info->providerName, 'Animoto');
6+
$this->assertEmbed(
7+
'https://animoto.com/play/JzwsBn5FRVxS0qoqcBP5zA',
8+
[
9+
'title' => 'Juno Groove',
10+
'width' => 640,
11+
'height' => 360,
12+
'type' => 'video',
13+
'authorName' => 'Chris Korhonen',
14+
'providerName' => 'Animoto',
15+
]
16+
);
1417
}
1518
}

tests/AolTest.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,24 @@ class AolTest extends TestCaseBase
33
{
44
public function testOne()
55
{
6-
$info = $this->getInfo('http://on.aol.com/video/whats-next-for-google-in-two-minutes-518288612');
7-
8-
$this->assertString($info->title, "What's Next for Google in Two Minutes");
9-
$this->assertString($info->description, "Wherein we smoosh Google's 2014 developer conference keynote from 2.5+ hours down to just under two minutes.");
10-
$this->assertString($info->type, 'video');
6+
$this->assertEmbed(
7+
'http://on.aol.com/video/whats-next-for-google-in-two-minutes-518288612',
8+
[
9+
'title' => "What's Next for Google in Two Minutes",
10+
'description' => "Wherein we smoosh Google's 2014 developer conference keynote from 2.5+ hours down to just under two minutes.",
11+
'type' => 'video',
12+
]
13+
);
1114

1215
/*
1316
Comented because in cli the html returned does not contain the oembed meta
1417
so the test fails. Need to investigate.
1518
16-
$this->assertString($info->code, "<iframe width='480' height='401' frameborder='0' webkitAllowFullScreen mozallowfullscreen allowFullScreen src='http://embed.5min.com/PlayerSeed/?playList=518288612&autoStart=true'></iframe>");
17-
$this->assertString($info->width, 480);
18-
$this->assertString($info->height, 401);
19-
$this->assertString($info->authorName, 'Time.com');
20-
$this->assertString($info->providerName, 'on.aol.com');
19+
'code' => "<iframe width='480' height='401' frameborder='0' webkitAllowFullScreen mozallowfullscreen allowFullScreen src='http://embed.5min.com/PlayerSeed/?playList=518288612&autoStart=true'></iframe>",
20+
'width' => 480,
21+
'height' => 401,
22+
'authorName' => 'Time.com',
23+
'providerName' => 'on.aol.com',
2124
*/
2225
}
2326
}

tests/AppTest.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@ class AppTest extends TestCaseBase
33
{
44
public function testOne()
55
{
6-
$info = $this->getInfo('https://alpha.app.net/chrifpa/post/33532003/photo/1');
7-
8-
$this->assertString($info->title, "Image_from_Riposte_2014-06-28.jpg");
9-
$this->assertString($info->description, 'is what I see in my mind when I hear “there’s now a $foo in javascript”. This [photos.app.net]');
10-
$this->assertString($info->width, 533);
11-
$this->assertString($info->height, 400);
12-
$this->assertString($info->type, 'photo');
13-
$this->assertString($info->authorName, '@chrifpa');
14-
$this->assertString($info->providerName, 'App.net');
6+
$this->assertEmbed(
7+
'https://alpha.app.net/chrifpa/post/33532003/photo/1',
8+
[
9+
'title' => "Image_from_Riposte_2014-06-28.jpg",
10+
'description' => 'is what I see in my mind when I hear “there’s now a $foo in javascript”. This [photos.app.net]',
11+
'width' => 533,
12+
'height' => 400,
13+
'type' => 'photo',
14+
'authorName' => '@chrifpa',
15+
'providerName' => 'App.net',
16+
]
17+
);
1518
}
1619
}

tests/ArchiveTest.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ class ArchiveTest extends TestCaseBase
33
{
44
public function testOne()
55
{
6-
$info = $this->getInfo('https://archive.org/details/dn2015-0220_vid');
7-
8-
$this->assertString($info->width, 640);
9-
$this->assertString($info->height, 480);
10-
$this->assertString($info->type, 'video');
11-
$this->assertString($info->providerName, 'Internet Archive');
6+
$this->assertEmbed(
7+
'https://archive.org/details/dn2015-0220_vid',
8+
[
9+
'width' => 640,
10+
'height' => 480,
11+
'type' => 'video',
12+
'providerName' => 'Internet Archive',
13+
]
14+
);
1215
}
1316
}

tests/BambuserTest.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@ class BambuserTest extends TestCaseBase
33
{
44
public function testOne()
55
{
6-
$info = $this->getInfo('http://bambuser.com/v/4740575');
7-
8-
$this->assertString($info->title, "#OccupyWestminster #SaveILF #London #olsx #ONN");
9-
$this->assertString($info->description, 'Broadcast by dancole on Bambuser.com');
10-
$this->assertString($info->type, 'video');
11-
$this->assertString($info->code, '<object id="bplayer" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="320" height="240"><embed allowfullscreen="true" allowscriptaccess="always" wmode="transparent" type="application/x-shockwave-flash" name="bplayer" src="http://static.bambuser.com/r/player.swf?context=oembed&amp;vid=4740575" width="320" height="240" /><param name="movie" value="http://static.bambuser.com/r/player.swf?context=oembed&amp;vid=4740575" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="wmode" value="transparent" /></object>');
12-
$this->assertString($info->width, 320);
13-
$this->assertString($info->height, 240);
14-
$this->assertString($info->authorName, 'dancole');
15-
$this->assertString($info->providerName, 'Bambuser.com');
6+
$this->assertEmbed(
7+
'http://bambuser.com/v/4740575',
8+
[
9+
'title' => "#OccupyWestminster #SaveILF #London #olsx #ONN",
10+
'description' => 'Broadcast by dancole on Bambuser.com',
11+
'type' => 'video',
12+
'code' => '<object id="bplayer" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="320" height="240"><embed allowfullscreen="true" allowscriptaccess="always" wmode="transparent" type="application/x-shockwave-flash" name="bplayer" src="http://static.bambuser.com/r/player.swf?context=oembed&amp;vid=4740575" width="320" height="240" /><param name="movie" value="http://static.bambuser.com/r/player.swf?context=oembed&amp;vid=4740575" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="wmode" value="transparent" /></object>',
13+
'width' => 320,
14+
'height' => 240,
15+
'authorName' => 'dancole',
16+
'providerName' => 'Bambuser.com',
17+
]
18+
);
1619
}
1720
}

0 commit comments

Comments
 (0)