]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - tests/oEmbedTest.php
0a8841606e8533653cabf400f024d1b8dc57e0d2
[quix0rs-gnu-social.git] / tests / oEmbedTest.php
1 <?php
2
3 if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
4     print "This script must be run from the command line\n";
5     exit();
6 }
7
8 define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
9 define('STATUSNET', true);
10
11 require_once INSTALLDIR . '/lib/common.php';
12
13 class oEmbedTest extends PHPUnit_Framework_TestCase
14 {
15
16     public function setup()
17     {
18         //$this->old_oohembed = common_config('oohembed', 'endpoint');
19     }
20
21     public function tearDown()
22     {
23         //$GLOBALS['config']['attachments']['supported'] = $this->old_attachments_supported;
24     }
25
26     /**
27      * @dataProvider fallbackSources
28      *
29      */
30     public function testoEmbed($url, $expectedType)
31     {
32         try {
33             $data = oEmbedHelper::getObject($url);
34             $this->assertEquals($expectedType, $data->type);
35         } catch (Exception $e) {
36             if ($expectedType == 'none') {
37                 $this->assertEquals($expectedType, 'none', 'Should not have data for this URL.');
38             } else {
39                 throw $e;
40             }
41         }
42     }
43
44     /**
45      * Sample oEmbed targets for sites we know ourselves...
46      * @return array
47      */
48     static public function knownSources()
49     {
50         $sources = array(
51             array('http://www.flickr.com/photos/brionv/5172500179/', 'photo'),
52             array('http://yfrog.com/fy42747177j', 'photo'),
53             array('http://twitpic.com/36adw6', 'photo'),
54         );
55         return $sources;
56     }
57
58     /**
59      * Sample oEmbed targets that can be found via discovery.
60      * Includes also knownSources() output.
61      *
62      * @return array
63      */
64     static public function discoverableSources()
65     {
66         $sources = array(
67             array('http://identi.ca/attachment/34437400', 'photo'),
68
69             array('http://www.youtube.com/watch?v=eUgLR232Cnw', 'video'),
70             array('http://vimeo.com/9283184', 'video'),
71
72             // Will fail discovery:
73             array('http://leuksman.com/log/2010/10/29/statusnet-0-9-6-release/', 'none'),
74         );
75         return array_merge(self::knownSources(), $sources);
76     }
77
78     /**
79      * Sample oEmbed targets that can be found via oohembed.com.
80      * Includes also discoverableSources() output.
81      *
82      * @return array
83      */
84     static public function fallbackSources()
85     {
86         $sources = array(
87             array('http://en.wikipedia.org/wiki/File:Wiki.png', 'link'), // @fixme in future there may be a native provider -- will change to 'photo'
88         );
89         return array_merge(self::discoverableSources(), $sources);
90     }
91 }