]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - tests/MediaFileTest.php
Give NoticeListItem its own class
[quix0rs-gnu-social.git] / tests / MediaFileTest.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 define('LACONICA', true);
11
12 require_once INSTALLDIR . '/lib/common.php';
13
14 class MediaFileTest extends PHPUnit_Framework_TestCase
15 {
16
17     public function setup()
18     {
19         $this->old_attachments_supported = common_config('attachments', 'supported');
20         $GLOBALS['config']['attachments']['supported'] = true;
21     }
22
23     public function tearDown()
24     {
25         $GLOBALS['config']['attachments']['supported'] = $this->old_attachments_supported;
26     }
27
28     /**
29      * @dataProvider fileTypeCases
30      *
31      */
32     public function testFileType($filename, $expectedType)
33     {
34         if (!file_exists($filename)) {
35             throw new Exception("WTF? $filename test file missing");
36         }
37
38         $type = MediaFile::getUploadedFileType($filename, basename($filename));
39         $this->assertEquals($expectedType, $type);
40     }
41
42     /**
43      * @dataProvider fileTypeCases
44      *
45      */
46     public function testUploadedFileType($filename, $expectedType)
47     {
48         if (!file_exists($filename)) {
49             throw new Exception("WTF? $filename test file missing");
50         }
51         $tmp = tmpfile();
52         fwrite($tmp, file_get_contents($filename));
53
54         $type = MediaFile::getUploadedFileType($tmp, basename($filename));
55         $this->assertEquals($expectedType, $type);
56     }
57
58     static public function fileTypeCases()
59     {
60         $base = dirname(__FILE__);
61         $dir = "$base/sample-uploads";
62         $files = array(
63             "image.png" => "image/png",
64             "image.gif" => "image/gif",
65             "image.jpg" => "image/jpeg",
66             "image.jpeg" => "image/jpeg",
67         
68             "office.pdf" => "application/pdf",
69             
70             "wordproc.odt" => "application/vnd.oasis.opendocument.text",
71             "wordproc.ott" => "application/vnd.oasis.opendocument.text-template",
72             "wordproc.doc" => "application/msword",
73             "wordproc.docx" => "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
74             "wordproc.rtf" => "text/rtf",
75             
76             "spreadsheet.ods" => "application/vnd.oasis.opendocument.spreadsheet",
77             "spreadsheet.ots" => "application/vnd.oasis.opendocument.spreadsheet-template",
78             "spreadsheet.xls" => "application/vnd.ms-excel",
79             "spreadsheet.xlt" => "application/vnd.ms-excel",
80             "spreadsheet.xlsx" => "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
81             
82             "presentation.odp" => "application/vnd.oasis.opendocument.presentation",
83             "presentation.otp" => "application/vnd.oasis.opendocument.presentation-template",
84             "presentation.ppt" => "application/vnd.ms-powerpoint",
85             "presentation.pptx" => "application/vnd.openxmlformats-officedocument.presentationml.presentation",
86         );
87
88         $dataset = array();
89         foreach ($files as $file => $type) {
90             $dataset[] = array("$dir/$file", $type);
91         }
92         return $dataset;
93     }
94
95 }
96