3 if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
4 print "This script must be run from the command line\n";
8 define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
9 define('GNUSOCIAL', true);
10 define('STATUSNET', true); // compatibility
12 require_once INSTALLDIR . '/lib/common.php';
14 class oEmbedTest extends PHPUnit_Framework_TestCase
17 public function setup()
19 $this->old_ohembed = common_config('ohembed', 'endpoint');
22 public function tearDown()
24 $GLOBALS['config']['oembed']['endpoint'] = $this->old_ohembed;
28 * Test with ohembed DISABLED.
30 * @dataProvider discoverableSources
32 public function testoEmbed($url, $expectedType)
34 $GLOBALS['config']['oembed']['endpoint'] = false;
35 $this->_doTest($url, $expectedType);
39 * Test with oohembed ENABLED.
41 * @dataProvider fallbackSources
43 public function testnoEmbed($url, $expectedType)
45 $GLOBALS['config']['oembed']['endpoint'] = $this->_endpoint();
46 $this->_doTest($url, $expectedType);
50 * Get default oembed endpoint.
57 $_server = 'localhost'; $_path = '';
58 require INSTALLDIR . '/lib/default.php';
59 return $default['oembed']['endpoint'];
63 * Actually run an individual test.
66 * @param string $expectedType
68 function _doTest($url, $expectedType)
71 $data = oEmbedHelper::getObject($url);
72 $this->assertEquals($expectedType, $data->type);
73 if ($data->type == 'photo') {
74 $this->assertTrue(!empty($data->url), 'Photo must have a URL.');
75 $this->assertTrue(!empty($data->width), 'Photo must have a width.');
76 $this->assertTrue(!empty($data->height), 'Photo must have a height.');
77 } else if ($data->type == 'video') {
78 $this->assertTrue(!empty($data->html), 'Video must have embedding HTML.');
79 $this->assertTrue(!empty($data->thumbnail_url), 'Video should have a thumbnail.');
81 if (!empty($data->thumbnail_url)) {
82 $this->assertTrue(!empty($data->thumbnail_width), 'Thumbnail must list a width.');
83 $this->assertTrue(!empty($data->thumbnail_height), 'Thumbnail must list a height.');
85 } catch (Exception $e) {
86 if ($expectedType == 'none') {
87 $this->assertEquals($expectedType, 'none', 'Should not have data for this URL.');
95 * Sample oEmbed targets for sites we know ourselves...
98 static public function knownSources()
101 array('https://www.flickr.com/photos/brionv/5172500179/', 'photo'),
107 * Sample oEmbed targets that can be found via discovery.
108 * Includes also knownSources() output.
112 static public function discoverableSources()
116 array('http://www.youtube.com/watch?v=eUgLR232Cnw', 'video'),
117 array('http://vimeo.com/9283184', 'video'),
119 // Will fail discovery:
120 array('http://leuksman.com/log/2010/10/29/statusnet-0-9-6-release/', 'none'),
122 return array_merge(self::knownSources(), $sources);
126 * Sample oEmbed targets that can be found via noembed.com.
127 * Includes also discoverableSources() output.
131 static public function fallbackSources()
135 array('https://github.com/git/git/commit/85e9c7e1d42849c5c3084a9da748608468310c0e', 'Github Commit'), // @fixme in future there may be a native provider -- will change to 'photo'
140 return array_merge(self::discoverableSources(), $sources);