summaryrefslogtreecommitdiff
path: root/tests/MediaFileTest.php
blob: 6fe9956210b3615c86138a42e46dcaec4ccad406 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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"),
        );
    }

}