summaryrefslogtreecommitdiff
path: root/tests/MediaFileTest.php
diff options
context:
space:
mode:
authorBrion Vibber <brion@pobox.com>2010-05-10 15:32:02 -0700
committerBrion Vibber <brion@pobox.com>2010-06-28 08:59:46 -0700
commit41d81b996fdd8276cc04e750297a12f852a97bf4 (patch)
tree602dee18c6177ab86baeb157ec4a90e78eb46d02 /tests/MediaFileTest.php
parentef7e85c0ab79dcac5239aaee2e3f329588db6397 (diff)
Test cases for MediaFile::getUploadedFileType() with OpenOffice, MS Office, and PDF sample files (as saved from OpenOffice 3.2)
Only 3 of 16 cases pass on my dev box with default config. Ouch!
Diffstat (limited to 'tests/MediaFileTest.php')
-rw-r--r--tests/MediaFileTest.php77
1 files changed, 77 insertions, 0 deletions
diff --git a/tests/MediaFileTest.php b/tests/MediaFileTest.php
new file mode 100644
index 000000000..6fe995621
--- /dev/null
+++ b/tests/MediaFileTest.php
@@ -0,0 +1,77 @@
+<?php
+
+if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
+ print "This script must be run from the command line\n";
+ exit();
+}
+
+define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
+define('STATUSNET', true);
+define('LACONICA', true);
+
+require_once INSTALLDIR . '/lib/common.php';
+
+class MediaFileTest extends PHPUnit_Framework_TestCase
+{
+
+ public function setup()
+ {
+ $this->old_attachments_supported = common_config('attachments', 'supported');
+ $GLOBALS['config']['attachments']['supported'] = true;
+ }
+
+ public function tearDown()
+ {
+ $GLOBALS['config']['attachments']['supported'] = $this->old_attachments_supported;
+ }
+
+ /**
+ * @dataProvider fileTypeCases
+ *
+ */
+ public function testFileType($filename, $expectedType)
+ {
+ if (!file_exists($filename)) {
+ throw new Exception("WTF? $filename test file missing");
+ }
+ $this->assertEquals($expectedType, MediaFile::getUploadedFileType($filename));
+ }
+
+ static public function fileTypeCases()
+ {
+ $base = dirname(__FILE__);
+ $dir = "$base/sample-uploads";
+ return array(
+ array("$dir/office.pdf", "application/pdf"),
+
+ array("$dir/wordproc.odt", "application/vnd.oasis.opendocument.text"),
+ array("$dir/wordproc.ott", "application/vnd.oasis.opendocument.text-template"),
+ array("$dir/wordproc.doc", "application/msword"),
+ array("$dir/wordproc.docx",
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document"),
+ array("$dir/wordproc.rtf", "text/rtf"),
+
+ array("$dir/spreadsheet.ods",
+ "application/vnd.oasis.opendocument.spreadsheet"),
+ array("$dir/spreadsheet.ots",
+ "application/vnd.oasis.opendocument.spreadsheet-template"),
+ array("$dir/spreadsheet.xls", "application/vnd.ms-excel"),
+ array("$dir/spreadsheet.xlt", "application/vnd.ms-excel"),
+ array("$dir/spreadsheet.xlsx",
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"),
+
+ array("$dir/presentation.odp",
+ "application/vnd.oasis-opendocument.presentation"),
+ array("$dir/presentation.otp",
+ "application/vnd.oasis-opendocument.presentation-template"),
+ array("$dir/presentation.ppt",
+ "application/vnd.ms-powerpoint"),
+ array("$dir/presentation.pot",
+ "application/vnd.ms-powerpoint"),
+ array("$dir/presentation.pptx",
+ "application/vnd.openxmlformats-officedocument.presentationml.presentation"),
+ );
+ }
+
+}
+