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('GNUSOCIAL', true);
10 define('STATUSNET', true); // compatibility
12 require_once INSTALLDIR . '/lib/common.php';
14 class MediaFileTest extends PHPUnit_Framework_TestCase
17 public function setup()
19 $this->old_attachments_supported = common_config('attachments', 'supported');
20 $GLOBALS['config']['attachments']['supported'] = true;
23 public function tearDown()
25 $GLOBALS['config']['attachments']['supported'] = $this->old_attachments_supported;
29 * @dataProvider fileTypeCases
32 public function testMimeType($filename, $expectedType)
34 if (!file_exists($filename)) {
35 throw new Exception("WTF? $filename test file missing");
38 $type = MediaFile::getUploadedMimeType($filename, basename($filename));
39 $this->assertEquals($expectedType, $type);
43 * @dataProvider fileTypeCases
46 public function testUploadedMimeType($filename, $expectedType)
48 if (!file_exists($filename)) {
49 throw new Exception("WTF? $filename test file missing");
52 fwrite($tmp, file_get_contents($filename));
54 $tmp_metadata = stream_get_meta_data($tmp);
55 $type = MediaFile::getUploadedMimeType($tmp_metadata['uri'], basename($filename));
56 $this->assertEquals($expectedType, $type);
59 static public function fileTypeCases()
61 $base = dirname(__FILE__);
62 $dir = "$base/sample-uploads";
64 "image.png" => "image/png",
65 "image.gif" => "image/gif",
66 "image.jpg" => "image/jpeg",
67 "image.jpeg" => "image/jpeg",
69 "office.pdf" => "application/pdf",
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",
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",
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",
90 foreach ($files as $file => $type) {
91 $dataset[] = array("$dir/$file", $type);