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('STATUSNET', true);
10 define('LACONICA', true);
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 testFileType($filename, $expectedType)
34 if (!file_exists($filename)) {
35 throw new Exception("WTF? $filename test file missing");
38 $type = MediaFile::getUploadedFileType($filename, basename($filename));
39 $this->assertEquals($expectedType, $type);
43 * @dataProvider fileTypeCases
46 public function testUploadedFileType($filename, $expectedType)
48 if (!file_exists($filename)) {
49 throw new Exception("WTF? $filename test file missing");
52 fwrite($tmp, file_get_contents($filename));
54 $type = MediaFile::getUploadedFileType($tmp, basename($filename));
55 $this->assertEquals($expectedType, $type);
58 static public function fileTypeCases()
60 $base = dirname(__FILE__);
61 $dir = "$base/sample-uploads";
63 "image.png" => "image/png",
64 "image.gif" => "image/gif",
65 "image.jpg" => "image/jpeg",
66 "image.jpeg" => "image/jpeg",
68 "office.pdf" => "application/pdf",
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",
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",
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",
89 foreach ($files as $file => $type) {
90 $dataset[] = array("$dir/$file", $type);