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 } catch (Exception $e) {
73 if ($expectedType == 'none') {
74 $this->assertEquals($expectedType, 'none', 'Should not have data for this URL.');
82 * Sample oEmbed targets for sites we know ourselves...
85 static public function knownSources()
88 array('http://www.flickr.com/photos/brionv/5172500179/', 'photo'),
89 array('http://yfrog.com/fy42747177j', 'photo'),
90 array('http://twitpic.com/36adw6', 'photo'),
96 * Sample oEmbed targets that can be found via discovery.
97 * Includes also knownSources() output.
101 static public function discoverableSources()
104 array('http://identi.ca/attachment/34437400', 'photo'),
106 array('http://www.youtube.com/watch?v=eUgLR232Cnw', 'video'),
107 array('http://vimeo.com/9283184', 'video'),
109 // Will fail discovery:
110 array('http://leuksman.com/log/2010/10/29/statusnet-0-9-6-release/', 'none'),
112 return array_merge(self::knownSources(), $sources);
116 * Sample oEmbed targets that can be found via oohembed.com.
117 * Includes also discoverableSources() output.
121 static public function fallbackSources()
124 array('http://en.wikipedia.org/wiki/File:Wiki.png', 'link'), // @fixme in future there may be a native provider -- will change to 'photo'
126 return array_merge(self::discoverableSources(), $sources);