Skip to content

Commit 974946b

Browse files
committed
More tests, changed readme with the new changes
1 parent dd5fc57 commit 974946b

File tree

6 files changed

+87
-92
lines changed

6 files changed

+87
-92
lines changed

README.md

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -71,39 +71,19 @@ $info = Embed\Embed::create('https://www.youtube.com/watch?v=PP1xn5wHtxE', $opti
7171
Customize the request
7272
---------------------
7373

74-
Embed provides a RequestResolvers\Curl class to resolve all requests using the curl library. You can create your own request resolver class creating a class implementing the RequestResolverInterface.
74+
Embed provides a RequestResolvers\Curl class to resolve all requests using the curl library. You can set custom options to the curl request or use your own request resolver class creating a class implementing the RequestResolverInterface. To do that, you have the "resolver" that is an array with two values: "class" (if you want provide your own class) and "options" to set options to the curl library. The options can be any of the available in the [curl_setopt PHP function](http://php.net/manual/en/function.curl-setopt.php)
7575

7676
```php
77-
//Set your own request resolver class:
78-
Embed\Request::setDefaultResolver('MyCustomResolverClass');
79-
```
80-
81-
You can configure also the following options of the default request resolver:
82-
83-
* userAgent: User agent used in all requests. By default is "Embed PHP Library"
84-
* maxRedirections: The maximum amount of HTTP redirections to follow. By default is 20
85-
* connectionTimeout: The number of seconds to wait while trying to connect. Use 0 to wait indefinitely. By default is 10
86-
* timeout: The maximum number of seconds to allow execute the request. By default is 10
87-
88-
To set a new configuration:
89-
90-
```php
91-
Embed\Request::setResolverConfig(array(
92-
'userAgent' => 'My spider',
93-
'connectionTimeout' => 0
77+
$info = Embed\Embed::create('https://www.youtube.com/watch?v=PP1xn5wHtxE', array(
78+
"resolver" => array(
79+
"options" => array(
80+
CURLOPT_USERAGENT => 'My spider',
81+
CURLOPT_MAXREDIRS => 3
82+
)
83+
)
9484
));
9585
```
9686

97-
Or you can set your custom resolver class and the configuration at the same time:
98-
99-
```php
100-
Embed\Request::setDefaultResolver('MyCustomResolverClass', array(
101-
'userAgent' => 'My spider',
102-
'connectionTimeout' => 0
103-
));
104-
```
105-
106-
10787
Online demo
10888
-----------
10989

tests/DailyMotionTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
include_once dirname(__DIR__).'/src/autoloader.php';
3+
4+
class DailyMotionTest extends PHPUnit_Framework_TestCase
5+
{
6+
public function testOne()
7+
{
8+
$info = Embed\Embed::create('http://www.dailymotion.com/video/xy0wd_chats-paresseux');
9+
10+
$this->assertEquals($info->title, 'Chats paresseux');
11+
$this->assertEquals($info->type, 'video');
12+
$this->assertEquals($info->url, 'http://www.dailymotion.com/video/xy0wd_chats-paresseux_animals');
13+
$this->assertEquals($info->image, 'http://s1.dmcdn.net/Ay0o/x240-kWu.jpg');
14+
$this->assertEquals($info->imageWidth, 320);
15+
$this->assertEquals($info->imageHeight, 240);
16+
$this->assertEquals($info->providerName, 'Dailymotion');
17+
$this->assertEquals($info->providerUrl, 'http://www.dailymotion.com');
18+
}
19+
}

tests/EmbedTest.php

Lines changed: 0 additions & 64 deletions
This file was deleted.

tests/PoliticoTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
include_once dirname(__DIR__).'/src/autoloader.php';
3+
4+
class PoliticoTest extends PHPUnit_Framework_TestCase
5+
{
6+
public function testOne()
7+
{
8+
$info = Embed\Embed::create('http://www.politico.com/story/2013/12/presidents-barack-obama-george-w-bush-second-term-101314.html');
9+
10+
$this->assertEquals($info->title, 'Echoes of George W. Bush blues in Barack Obama\'s 2nd term');
11+
$this->assertEquals($info->type, 'link');
12+
$this->assertEquals($info->image, 'http://images.politico.com/global/2013/12/18/131218_george_w_bush_barack_obama_ap_605.jpg');
13+
$this->assertEquals($info->imageWidth, 605);
14+
$this->assertEquals($info->imageHeight, 328);
15+
$this->assertEquals($info->providerName, 'POLITICO');
16+
$this->assertEquals($info->providerUrl, 'http://politico.com');
17+
$this->assertEquals($info->providerIcon, 'http://www.politico.com/favicon.ico');
18+
}
19+
}

tests/TwitterTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
include_once dirname(__DIR__).'/src/autoloader.php';
3+
4+
class TwitterTest extends PHPUnit_Framework_TestCase
5+
{
6+
public function testNormal()
7+
{
8+
$info = Embed\Embed::create('https://twitter.com/pepephone/status/436461658601713664');
9+
10+
$this->assertEquals($info->code, '<blockquote class="twitter-tweet"><p>RT <a href="https://twitter.com/PabloHerreros">@PabloHerreros</a> Pepephone rompe la baraja - <a href="http://t.co/mFn7mcB1vy">http://t.co/mFn7mcB1vy</a></p>&mdash; pepephone (@pepephone) <a href="https://twitter.com/pepephone/status/436461658601713664">February 20, 2014</a></blockquote>'."\n".'<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>');
11+
}
12+
13+
public function testOmitScript()
14+
{
15+
$info = Embed\Embed::create('https://twitter.com/pepephone/status/436461658601713664', array(
16+
'oembedParameters' => array('omit_script' => true)
17+
));
18+
19+
$this->assertEquals($info->code, '<blockquote class="twitter-tweet"><p>RT <a href="https://twitter.com/PabloHerreros">@PabloHerreros</a> Pepephone rompe la baraja - <a href="http://t.co/mFn7mcB1vy">http://t.co/mFn7mcB1vy</a></p>&mdash; pepephone (@pepephone) <a href="https://twitter.com/pepephone/status/436461658601713664">February 20, 2014</a></blockquote>');
20+
}
21+
}

tests/YoutubeTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
include_once dirname(__DIR__).'/src/autoloader.php';
3+
4+
class YoutubeTest extends PHPUnit_Framework_TestCase
5+
{
6+
public function testOne()
7+
{
8+
$info = Embed\Embed::create('http://www.youtube.com/watch?v=eiHXASgRTcA');
9+
10+
$this->assertEquals($info->title, 'Noisy kittens waiting for dinner!');
11+
$this->assertEquals($info->description, 'Disclaimer - 7 week old fostered kittens waiting on their dinner being prepared. They had been ill with cat flu and were just starting to get their appetite ...');
12+
$this->assertEquals($info->imageWidth, 480);
13+
$this->assertEquals($info->imageHeight, 360);
14+
$this->assertEquals($info->type, 'video');
15+
$this->assertEquals($info->authorName, 'smshdchrb');
16+
$this->assertEquals($info->authorUrl, 'http://www.youtube.com/user/smshdchrb');
17+
$this->assertEquals($info->providerName, 'YouTube');
18+
$this->assertEquals($info->providerUrl, 'http://www.youtube.com/');
19+
}
20+
}

0 commit comments

Comments
 (0)