]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - tests/MediaFileTest.php
CSS to align the notice footer (thanks fnadde42)
[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('GNUSOCIAL', true);
10 define('STATUSNET', true);  // compatibility
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 testMimeType($filename, $expectedType)
33     {
34         if (!file_exists($filename)) {
35             throw new Exception("WTF? $filename test file missing");
36         }
37
38         $type = MediaFile::getUploadedMimeType($filename, basename($filename));
39         $this->assertEquals($expectedType, $type);
40     }
41
42     /**
43      * @dataProvider fileTypeCases
44      *
45      */
46     public function testUploadedMimeType($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         $tmp_metadata = stream_get_meta_data($tmp);
55         $type = MediaFile::getUploadedMimeType($tmp_metadata['uri'], basename($filename));
56         $this->assertEquals($expectedType, $type);
57     }
58
59     static public function fileTypeCases()
60     {
61         $base = dirname(__FILE__);
62         $dir = "$base/sample-uploads";
63         $files = array(
64             "image.png" => "image/png",
65             "image.gif" => "image/gif",
66             "image.jpg" => "image/jpeg",
67             "image.jpeg" => "image/jpeg",
68         
69             "office.pdf" => "application/pdf",
70             
71             "wordproc.odt" => "application/vnd.oasis.opendocument.text",
72             "wordproc.ott" => "application/vnd.oasis.opendocument.text-template",
73             "wordproc.doc" => "application/msword",
74             "wordproc.docx" => "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
75             "wordproc.rtf" => "text/rtf",
76             
77             "spreadsheet.ods" => "application/vnd.oasis.opendocument.spreadsheet",
78             "spreadsheet.ots" => "application/vnd.oasis.opendocument.spreadsheet-template",
79             "spreadsheet.xls" => "application/vnd.ms-excel",
80             "spreadsheet.xlt" => "application/vnd.ms-excel",
81             "spreadsheet.xlsx" => "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
82             
83             "presentation.odp" => "application/vnd.oasis.opendocument.presentation",
84             "presentation.otp" => "application/vnd.oasis.opendocument.presentation-template",
85             "presentation.ppt" => "application/vnd.ms-powerpoint",
86             "presentation.pptx" => "application/vnd.openxmlformats-officedocument.presentationml.presentation",
87         );
88
89         $dataset = array();
90         foreach ($files as $file => $type) {
91             $dataset[] = array("$dir/$file", $type);
92         }
93         return $dataset;
94     }
95
96 }
97