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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
<?php
/**
* Copyright (c) 2014 Vincent Petry <pvince81@owncloud.com>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
/**
* Tests for the converting of legacy storages to home storages.
*
* @see \OC\Repair\RepairMimeTypes
*/
class TestRepairMimeTypes extends PHPUnit_Framework_TestCase {
/** @var \OC\RepairStep */
private $repair;
private $storage;
public function setUp() {
$this->storage = new \OC\Files\Storage\Temporary(array());
$this->repair = new \OC\Repair\RepairMimeTypes();
}
public function tearDown() {
$this->storage->getCache()->clear();
$sql = 'DELETE FROM `*PREFIX*storages` WHERE id = ?';
\OC_DB::executeAudited($sql, array($this->storage->getId()));
$this->clearMimeTypes();
DummyFileCache::clearCachedMimeTypes();
}
private function clearMimeTypes() {
$sql = 'DELETE FROM `*PREFIX*mimetypes`';
\OC_DB::executeAudited($sql);
}
private function addEntries($entries) {
// create files for the different extensions, this
// will also automatically create the corresponding mime types
foreach ($entries as $entry) {
$this->storage->getCache()->put(
$entry[0],
array(
'size' => 0,
'mtime' => 0,
'mimetype' => $entry[1]
)
);
}
}
private function checkEntries($entries) {
foreach ($entries as $entry) {
$data = $this->storage->getCache()->get($entry[0]);
$this->assertEquals($entry[1], $data['mimetype']);
}
}
/**
* Test renaming and splitting old office mime types
*/
public function testRenameOfficeMimeTypes() {
$this->addEntries(
array(
array('test.doc', 'application/msword'),
array('test.docx', 'application/msword'),
array('test.xls', 'application/msexcel'),
array('test.xlsx', 'application/msexcel'),
array('test.ppt', 'application/mspowerpoint'),
array('test.pptx', 'application/mspowerpoint'),
)
);
$this->repair->run();
// force mimetype reload
$this->storage->getCache()->loadMimeTypes();
$this->checkEntries(
array(
array('test.doc', 'application/msword'),
array('test.docx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'),
array('test.xls', 'application/msexcel'),
array('test.xlsx', 'application/vnd.ms-excel'),
array('test.ppt', 'application/mspowerpoint'),
array('test.pptx', 'application/vnd.ms-powerpoint'),
)
);
}
}
/**
* Dummy class to access protected members
*/
class DummyFileCache extends \OC\Files\Cache\Cache {
public static function clearCachedMimeTypes() {
self::$mimetypeIds = array();
self::$mimetypes = array();
}
}
|