1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the eZ Publish Legacy package. |
5
|
|
|
* |
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
7
|
|
|
* @license For full copyright and license information view LICENSE file distributd with this source code. |
8
|
|
|
*/ |
9
|
|
|
namespace eZ\Publish\Core\IO\Tests\IOMetadataHandler; |
10
|
|
|
|
11
|
|
|
use eZ\Publish\Core\IO\IOMetadataHandler\LegacyDFSCluster; |
12
|
|
|
use eZ\Publish\SPI\IO\BinaryFile as SPIBinaryFile; |
13
|
|
|
use eZ\Publish\SPI\IO\BinaryFileCreateStruct as SPIBinaryFileCreateStruct; |
14
|
|
|
use PHPUnit_Framework_TestCase; |
15
|
|
|
use DateTime; |
16
|
|
|
|
17
|
|
|
class LegacyDFSClusterTest extends PHPUnit_Framework_TestCase |
18
|
|
|
{ |
19
|
|
|
/** @var \eZ\Publish\Core\IO\IOMetadataHandler|\PHPUnit_Framework_MockObject_MockObject */ |
20
|
|
|
private $handler; |
21
|
|
|
|
22
|
|
|
/** @var \Doctrine\DBAL\Connection|\PHPUnit_Framework_MockObject_MockObject */ |
23
|
|
|
private $dbalMock; |
24
|
|
|
|
25
|
|
|
/** @var \eZ\Publish\Core\IO\UrlDecorator|\PHPUnit_Framework_MockObject_MockObject */ |
26
|
|
|
private $urlDecoratorMock; |
27
|
|
|
|
28
|
|
|
public function setUp() |
29
|
|
|
{ |
30
|
|
|
$this->dbalMock = $this->getMockBuilder('Doctrine\DBAL\Connection')->disableOriginalConstructor()->getMock(); |
31
|
|
|
$this->urlDecoratorMock = $this->getMock('eZ\Publish\Core\IO\UrlDecorator'); |
32
|
|
|
|
33
|
|
|
$this->handler = new LegacyDFSCluster( |
34
|
|
|
$this->dbalMock, |
35
|
|
|
$this->urlDecoratorMock, |
36
|
|
|
['prefix' => 'var/test'] |
37
|
|
|
); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testCreate() |
41
|
|
|
{ |
42
|
|
|
$this->dbalMock |
43
|
|
|
->expects($this->once()) |
44
|
|
|
->method('prepare') |
45
|
|
|
->with($this->anything()) |
46
|
|
|
->will($this->returnValue($this->createDbalStatementMock())); |
47
|
|
|
|
48
|
|
|
$spiCreateStruct = new SPIBinaryFileCreateStruct(); |
49
|
|
|
$spiCreateStruct->id = 'prefix/my/file.png'; |
50
|
|
|
$spiCreateStruct->mimeType = 'image/png'; |
51
|
|
|
$spiCreateStruct->size = 123; |
52
|
|
|
$spiCreateStruct->mtime = new DateTime('@1307155200'); |
53
|
|
|
|
54
|
|
|
$this->assertInstanceOf( |
55
|
|
|
'eZ\Publish\SPI\IO\BinaryFile', |
56
|
|
|
$this->handler->create($spiCreateStruct) |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
View Code Duplication |
public function testDelete() |
61
|
|
|
{ |
62
|
|
|
$statement = $this->createDbalStatementMock(); |
63
|
|
|
$statement |
64
|
|
|
->expects($this->once()) |
65
|
|
|
->method('rowCount') |
66
|
|
|
->will($this->returnValue(1)); |
67
|
|
|
|
68
|
|
|
$this->dbalMock |
69
|
|
|
->expects($this->once()) |
70
|
|
|
->method('prepare') |
71
|
|
|
->with($this->anything()) |
72
|
|
|
->will($this->returnValue($statement)); |
73
|
|
|
|
74
|
|
|
$this->handler->delete('prefix/my/file.png'); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @expectedException \eZ\Publish\Core\IO\Exception\BinaryFileNotFoundException |
79
|
|
|
*/ |
80
|
|
View Code Duplication |
public function testDeleteNotFound() |
81
|
|
|
{ |
82
|
|
|
$statement = $this->createDbalStatementMock(); |
83
|
|
|
$statement |
84
|
|
|
->expects($this->once()) |
85
|
|
|
->method('rowCount') |
86
|
|
|
->will($this->returnValue(0)); |
87
|
|
|
|
88
|
|
|
$this->dbalMock |
89
|
|
|
->expects($this->once()) |
90
|
|
|
->method('prepare') |
91
|
|
|
->with($this->anything()) |
92
|
|
|
->will($this->returnValue($statement)); |
93
|
|
|
|
94
|
|
|
$this->handler->delete('prefix/my/file.png'); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function testLoad() |
98
|
|
|
{ |
99
|
|
|
$statement = $this->createDbalStatementMock(); |
100
|
|
|
$statement |
101
|
|
|
->expects($this->once()) |
102
|
|
|
->method('rowCount') |
103
|
|
|
->will($this->returnValue(1)); |
104
|
|
|
|
105
|
|
|
$statement |
106
|
|
|
->expects($this->once()) |
107
|
|
|
->method('fetch') |
108
|
|
|
->will($this->returnValue(array('size' => 123, 'datatype' => 'image/png', 'mtime' => 1307155200))); |
109
|
|
|
|
110
|
|
|
$this->dbalMock |
111
|
|
|
->expects($this->once()) |
112
|
|
|
->method('prepare') |
113
|
|
|
->with($this->anything()) |
114
|
|
|
->will($this->returnValue($statement)); |
115
|
|
|
|
116
|
|
|
$expectedSpiBinaryFile = new SPIBinaryFile(); |
117
|
|
|
$expectedSpiBinaryFile->id = 'prefix/my/file.png'; |
118
|
|
|
$expectedSpiBinaryFile->size = 123; |
119
|
|
|
$expectedSpiBinaryFile->mtime = new DateTime('@1307155200'); |
120
|
|
|
$expectedSpiBinaryFile->mimeType = 'image/png'; |
|
|
|
|
121
|
|
|
|
122
|
|
|
self::assertEquals( |
123
|
|
|
$expectedSpiBinaryFile, |
124
|
|
|
$this->handler->load('prefix/my/file.png') |
125
|
|
|
); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @expectedException \eZ\Publish\Core\IO\Exception\BinaryFileNotFoundException |
130
|
|
|
*/ |
131
|
|
View Code Duplication |
public function testLoadNotFound() |
132
|
|
|
{ |
133
|
|
|
$statement = $this->createDbalStatementMock(); |
134
|
|
|
$statement |
135
|
|
|
->expects($this->once()) |
136
|
|
|
->method('rowCount') |
137
|
|
|
->will($this->returnValue(0)); |
138
|
|
|
|
139
|
|
|
$this->dbalMock |
140
|
|
|
->expects($this->once()) |
141
|
|
|
->method('prepare') |
142
|
|
|
->with($this->anything()) |
143
|
|
|
->will($this->returnValue($statement)); |
144
|
|
|
|
145
|
|
|
$this->handler->load('prefix/my/file.png'); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
View Code Duplication |
public function testExists() |
149
|
|
|
{ |
150
|
|
|
$statement = $this->createDbalStatementMock(); |
151
|
|
|
$statement |
152
|
|
|
->expects($this->once()) |
153
|
|
|
->method('rowCount') |
154
|
|
|
->will($this->returnValue(1)); |
155
|
|
|
|
156
|
|
|
$this->dbalMock |
157
|
|
|
->expects($this->once()) |
158
|
|
|
->method('prepare') |
159
|
|
|
->with($this->anything()) |
160
|
|
|
->will($this->returnValue($statement)); |
161
|
|
|
|
162
|
|
|
self::assertTrue($this->handler->exists('prefix/my/file.png')); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
View Code Duplication |
public function testExistsNot() |
166
|
|
|
{ |
167
|
|
|
$statement = $this->createDbalStatementMock(); |
168
|
|
|
$statement |
169
|
|
|
->expects($this->once()) |
170
|
|
|
->method('rowCount') |
171
|
|
|
->will($this->returnValue(0)); |
172
|
|
|
|
173
|
|
|
$this->dbalMock |
174
|
|
|
->expects($this->once()) |
175
|
|
|
->method('prepare') |
176
|
|
|
->with($this->anything()) |
177
|
|
|
->will($this->returnValue($statement)); |
178
|
|
|
|
179
|
|
|
self::assertFalse($this->handler->exists('prefix/my/file.png')); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
View Code Duplication |
public function testDeletedirectory() |
183
|
|
|
{ |
184
|
|
|
$statement = $this->createDbalStatementMock(); |
185
|
|
|
$statement |
186
|
|
|
->expects($this->once()) |
187
|
|
|
->method('bindValue') |
188
|
|
|
->with(1, 'folder/subfolder/%'); |
189
|
|
|
|
190
|
|
|
$this->dbalMock |
191
|
|
|
->expects($this->once()) |
192
|
|
|
->method('prepare') |
193
|
|
|
->with($this->anything()) |
194
|
|
|
->will($this->returnValue($statement)); |
195
|
|
|
|
196
|
|
|
$this->handler->deleteDirectory('folder/subfolder/'); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject |
201
|
|
|
*/ |
202
|
|
|
protected function createDbalStatementMock() |
203
|
|
|
{ |
204
|
|
|
return $this->getMock('Doctrine\DBAL\Driver\Statement'); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
View Code Duplication |
public function testCount() |
208
|
|
|
{ |
209
|
|
|
$statement = $this->createDbalStatementMock(); |
210
|
|
|
|
211
|
|
|
$statement |
212
|
|
|
->expects($this->once()) |
213
|
|
|
->method('fetch') |
214
|
|
|
->will($this->returnValue(['count' => 42])); |
215
|
|
|
|
216
|
|
|
$this->dbalMock |
217
|
|
|
->expects($this->once()) |
218
|
|
|
->method('prepare') |
219
|
|
|
->with($this->anything()) |
220
|
|
|
->will($this->returnValue($statement)); |
221
|
|
|
|
222
|
|
|
self::assertEquals(42, $this->handler->count()); |
223
|
|
|
} |
224
|
|
|
} |
225
|
|
|
|
This property has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.