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('STATUSNET', true);
11 require_once INSTALLDIR . '/lib/common.php';
13 class oEmbedTest extends PHPUnit_Framework_TestCase
16 public function setup()
18 $this->old_oohembed = common_config('oohembed', 'endpoint');
21 public function tearDown()
23 $GLOBALS['config']['oohembed']['endpoint'] = $this->old_oohembed;
27 * Test with oohembed DISABLED.
29 * @dataProvider discoverableSources
31 public function testoEmbed($url, $expectedType)
33 $GLOBALS['config']['oohembed']['endpoint'] = false;
34 $this->_doTest($url, $expectedType);
38 * Test with oohembed ENABLED.
40 * @dataProvider fallbackSources
42 public function testoohEmbed($url, $expectedType)
44 $GLOBALS['config']['oohembed']['endpoint'] = $this->_endpoint();
45 $this->_doTest($url, $expectedType);
49 * Get default oohembed endpoint.
56 $_server = 'localhost'; $_path = '';
57 require INSTALLDIR . '/lib/default.php';
58 return $default['oohembed']['endpoint'];
62 * Actually run an individual test.
65 * @param string $expectedType
67 function _doTest($url, $expectedType)
70 $data = oEmbedHelper::getObject($url);
71 $this->assertEquals($expectedType, $data->type);
72 if ($data->type == 'photo') {
73 $this->assertTrue(!empty($data->url), 'Photo must have a URL.');
74 $this->assertTrue(!empty($data->width), 'Photo must have a width.');
75 $this->assertTrue(!empty($data->height), 'Photo must have a height.');
76 } else if ($data->type == 'video') {
77 $this->assertTrue(!empty($data->html), 'Video must have embedding HTML.');
78 $this->assertTrue(!empty($data->thumbnail_url), 'Video should have a thumbnail.');
80 if (!empty($data->thumbnail_url)) {
81 $this->assertTrue(!empty($data->thumbnail_width), 'Thumbnail must list a width.');
82 $this->assertTrue(!empty($data->thumbnail_height), 'Thumbnail must list a height.');
84 } catch (Exception $e) {
85 if ($expectedType == 'none') {
86 $this->assertEquals($expectedType, 'none', 'Should not have data for this URL.');
94 * Sample oEmbed targets for sites we know ourselves...
97 static public function knownSources()
100 array('http://www.flickr.com/photos/brionv/5172500179/', 'photo'),
101 array('http://yfrog.com/fy42747177j', 'photo'),
102 array('http://twitpic.com/36adw6', 'photo'),
108 * Sample oEmbed targets that can be found via discovery.
109 * Includes also knownSources() output.
113 static public function discoverableSources()
116 array('http://identi.ca/attachment/34437400', 'photo'),
118 array('http://www.youtube.com/watch?v=eUgLR232Cnw', 'video'),
119 array('http://vimeo.com/9283184', 'video'),
121 // Will fail discovery:
122 array('http://leuksman.com/log/2010/10/29/statusnet-0-9-6-release/', 'none'),
124 return array_merge(self::knownSources(), $sources);
128 * Sample oEmbed targets that can be found via oohembed.com.
129 * Includes also discoverableSources() output.
133 static public function fallbackSources()
136 array('http://en.wikipedia.org/wiki/File:Wiki.png', 'link'), // @fixme in future there may be a native provider -- will change to 'photo'
138 return array_merge(self::discoverableSources(), $sources);