]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - tests/oEmbedTest.php
Add some basic oEmbed lookup test cases; fixed a bug in discovery fallback.
[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 fileTypeCases
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     static public function fileTypeCases()
45     {
46         $files = array(
47             'http://www.flickr.com/photos/brionv/5172500179/' => 'photo',
48             'http://twitpic.com/36adw6' => 'photo',
49             'http://yfrog.com/fy42747177j' => 'photo',
50             'http://identi.ca/attachment/34437400' => 'photo',
51
52             'http://www.youtube.com/watch?v=eUgLR232Cnw' => 'video',
53             'http://vimeo.com/9283184' => 'video',
54
55             'http://en.wikipedia.org/wiki/File:Wiki.png' => 'link', // @fixme in future there may be a native provider -- will change to 'photo'
56             'http://leuksman.com/log/2010/10/29/statusnet-0-9-6-release/' => 'none',
57         );
58
59         $dataset = array();
60         foreach ($files as $url => $type) {
61             $dataset[] = array($url, $type);
62         }
63         return $dataset;
64     }
65
66 }
67