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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2018, Michael Weimann <mail@michael-weimann.eu>
*
* @author Michael Weimann <mail@michael-weimann.eu>
*
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
namespace Test\File\SimpleFS;
use OCP\Files\NotPermittedException;
use OCP\Files\SimpleFS\InMemoryFile;
use Test\TestCase;
/**
* This class provide test casesf or the InMemoryFile.
*
* @package Test\File\SimpleFS
*/
class InMemoryFileTest extends TestCase {
/**
* Holds a pdf file with know attributes for tests.
*
* @var InMemoryFile
*/
private $testPdf;
/**
* Sets the test file from "./resources/test.pdf".
*
* @before
* @return void
*/
public function setupTestPdf() {
$fileContents = file_get_contents(
__DIR__ . '/../../../data/test.pdf'
);
$this->testPdf = new InMemoryFile('test.pdf', $fileContents);
}
/**
* Asserts that putContent replaces the file contents.
*
* @return void
*/
public function testPutContent() {
$this->testPdf->putContent('test');
self::assertEquals('test', $this->testPdf->getContent());
}
/**
* Asserts that delete() doesn't rise an exception.
*
* @return void
*/
public function testDelete() {
$this->testPdf->delete();
// assert true, otherwise phpunit complains about not doing any assert
self::assertTrue(true);
}
/**
* Asserts that getName returns the name passed on file creation.
*
* @return void
*/
public function testGetName() {
self::assertEquals('test.pdf', $this->testPdf->getName());
}
/**
* Asserts that the file size is the size of the test file.
*
* @return void
*/
public function testGetSize() {
self::assertEquals(7083, $this->testPdf->getSize());
}
/**
* Asserts the file contents are the same than the original file contents.
*
* @return void
*/
public function testGetContent() {
self::assertEquals(
file_get_contents(__DIR__ . '/../../../data/test.pdf'),
$this->testPdf->getContent()
);
}
/**
* Asserts the test file modification time is an integer.
*
* @return void
*/
public function testGetMTime() {
self::assertTrue(is_int($this->testPdf->getMTime()));
}
/**
* Asserts the test file mime type is "application/json".
*
* @return void
*/
public function testGetMimeType() {
self::assertEquals('application/pdf', $this->testPdf->getMimeType());
}
/**
* Asserts that read() raises an NotPermittedException.
*
* @return void
*/
public function testRead() {
self::expectException(NotPermittedException::class);
$this->testPdf->read();
}
/**
* Asserts that write() raises an NotPermittedException.
*
* @return void
*/
public function testWrite() {
self::expectException(NotPermittedException::class);
$this->testPdf->write();
}
}
|