38 $this->storageMock = $this->getMock(
'TYPO3\CMS\Core\Resource\ResourceStorage', array(), array(),
'', FALSE);
39 $this->storageMock->expects($this->any())->method(
'getUid')->will($this->returnValue(5));
41 $mockedMetaDataRepository = $this->getMock(
'TYPO3\\CMS\\Core\\Resource\\Index\\MetaDataRepository');
42 $mockedMetaDataRepository->expects($this->any())->method(
'findByFile')->will($this->returnValue(array(
'file' => 1)));
55 $fixture = new \TYPO3\CMS\Core\Resource\File(array(
'testfile'), $this->storageMock);
64 $this->markTestSkipped(
'TYPO3\\CMS\\Core\\Resource\\File::getAvailableProperties() does not exist');
70 $fixture = new \TYPO3\CMS\Core\Resource\File($properties, $this->storageMock);
71 $availablePropertiesBackup = \TYPO3\CMS\Core\Resource\File::getAvailableProperties();
72 \TYPO3\CMS\Core\Resource\File::setAvailableProperties(array_keys($properties));
73 foreach ($properties as $key => $value) {
74 $this->assertTrue($fixture->hasProperty($key));
75 $this->assertEquals($value, $fixture->getProperty($key));
77 $this->assertFalse($fixture->hasProperty($this->getUniqueId()));
78 \TYPO3\CMS\Core\Resource\File::setAvailableProperties($availablePropertiesBackup);
79 $this->setExpectedException(
'InvalidArgumentException',
'', 1314226805);
89 'storage' => $this->storageMock,
92 $fixture = new \TYPO3\CMS\Core\Resource\File($properties, $this->storageMock);
93 foreach ($properties as $key => $value) {
94 $this->assertEquals($value, call_user_func(array($fixture,
'get' . $key)));
104 $fixture = new \TYPO3\CMS\Core\Resource\File(array(
'uid' => 1), $this->storageMock);
105 $this->assertTrue($fixture->isIndexed());
113 $fixture = new \TYPO3\CMS\Core\Resource\File(array(
'uid' => 1,
'identifier' =>
'/test'), $this->storageMock);
114 $fixture->updateProperties(array(
'identifier' => $identifier));
115 $this->assertEquals($identifier, $fixture->getIdentifier());
122 $fixture = new \TYPO3\CMS\Core\Resource\File(array(
'uid' => 1,
'foo' =>
'asdf',
'identifier' =>
'/test'), $this->storageMock);
123 $fixture->updateProperties(array(
'foo' =>
'foobar'));
124 $this->assertEquals(
'/test', $fixture->getIdentifier());
125 $this->assertEquals(
'/test', $fixture->getProperty(
'identifier'));
132 $fixture = new \TYPO3\CMS\Core\Resource\File(array(
'uid' => 1,
'identifier' =>
'/test'), $this->storageMock);
133 $fixture->updateProperties(array(
'uid' => 3));
134 $this->assertEquals(1, $fixture->getUid());
141 $fixture = new \TYPO3\CMS\Core\Resource\File(array(
'uid' => 1,
'foo' =>
'asdf',
'baz' =>
'fdsw',
'identifier' =>
'/test'), $this->storageMock);
142 $fixture->updateProperties(array(
'foo' =>
'foobar',
'baz' =>
'foobaz'));
143 $this->assertEquals(array(
'foo',
'baz'), $fixture->getUpdatedProperties());
150 $fixture = new \TYPO3\CMS\Core\Resource\File(array(
'uid' => 1,
'foo' =>
'asdf',
'identifier' =>
'/test'), $this->storageMock);
151 $fixture->updateProperties(array(
'foo' =>
'asdf'));
152 $this->assertEmpty($fixture->getUpdatedProperties());
159 $fixture = new \TYPO3\CMS\Core\Resource\File(array(
'uid' => 1,
'foo' =>
'asdf',
'baz' =>
'fdsw',
'identifier' =>
'/test'), $this->storageMock);
160 $fixture->updateProperties(array(
'foo' =>
'foobar',
'baz' =>
'foobaz'));
161 $fixture->updateProperties(array(
'foo' =>
'fdsw',
'baz' =>
'asdf'));
162 $this->assertEquals(array(
'foo',
'baz'), $fixture->getUpdatedProperties());
169 $fileProperties = array(
171 'storage' =>
'first',
173 $subject = $this->getMock(
174 'TYPO3\\CMS\\Core\\Resource\\File',
175 array(
'loadStorage'),
176 array($fileProperties, $this->storageMock)
178 $mockedNewStorage = $this->getMock(
'TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(),
'', FALSE);
179 $mockedResourceFactory = $this->getMock(
'TYPO3\\CMS\\Core\\Resource\\ResourceFactory');
180 $mockedResourceFactory
181 ->expects($this->once())
182 ->method(
'getStorageObject')
183 ->will($this->returnValue($mockedNewStorage));
186 $subject->updateProperties(array(
'storage' =>
'different'));
187 $this->assertSame($mockedNewStorage, $subject->getStorage());
196 $targetStorage = $this->getMock(
'TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(),
'', FALSE);
197 $targetFolder = $this->getMock(
'TYPO3\\CMS\\Core\\Resource\\Folder', array(), array(),
'', FALSE);
198 $targetFolder->expects($this->any())->method(
'getStorage')->will($this->returnValue($targetStorage));
199 $fixture = new \TYPO3\CMS\Core\Resource\File(array(), $this->storageMock);
200 $targetStorage->expects($this->once())->method(
'copyFile')->with($this->equalTo($fixture), $this->equalTo($targetFolder));
201 $fixture->copyTo($targetFolder);
208 $targetStorage = $this->getMock(
'TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(),
'', FALSE);
209 $targetFolder = $this->getMock(
'TYPO3\\CMS\\Core\\Resource\\Folder', array(), array(),
'', FALSE);
210 $targetFolder->expects($this->any())->method(
'getStorage')->will($this->returnValue($targetStorage));
211 $fixture = new \TYPO3\CMS\Core\Resource\File(array(), $this->storageMock);
212 $targetStorage->expects($this->once())->method(
'moveFile')->with($this->equalTo($fixture), $this->equalTo($targetFolder));
213 $fixture->moveTo($targetFolder);
220 $this->markTestSkipped();
222 $fileMode =
'invalidMode';
223 $mockDriver = $this->getMockForAbstractClass(
't3lib_file_driver_Abstract');
224 $mockDriver->expects($this->atLeastOnce())->method(
'getFileHandle')->with($this->equalTo($fixture), $this->equalTo($fileMode));
225 $fixture->setStorageDriver($mockDriver);
226 $fixture->open($fileMode);
233 $this->markTestSkipped();
236 $mockFileHandle = $this->getMock(
'TYPO3\\CMS\\Core\\Resource\\FileHandle', array(), array(),
'', FALSE);
237 $mockFileHandle->expects($this->any())->method(
'isOpen')->will($this->returnValue(TRUE));
238 $mockDriver = $this->getMockForAbstractClass(
't3lib_file_driver_Abstract');
239 $mockDriver->expects($this->any())->method(
'getFileHandle')->will($this->returnValue($mockFileHandle));
240 $fixture->setStorageDriver($mockDriver);
241 $this->assertFalse($fixture->isOpen());
242 $fixture->open($fileMode);
243 $this->assertTrue($fixture->isOpen());
250 $this->markTestSkipped();
253 $mockFileHandle = $this->getMock(
'TYPO3\\CMS\\Core\\Resource\\FileHandle', array(), array(),
'', FALSE);
254 $mockFileHandle->expects($this->once())->method(
'close');
255 $mockDriver = $this->getMockForAbstractClass(
't3lib_file_driver_Abstract');
256 $mockDriver->expects($this->any())->method(
'getFileHandle')->will($this->returnValue($mockFileHandle));
257 $fixture->setStorageDriver($mockDriver);
258 $fixture->open($fileMode);
260 $this->assertFalse($fixture->isOpen());
267 $this->markTestSkipped();
270 $fileContents =
'Some random file contents.';
272 $mockFileHandle = $this->getMock(
'TYPO3\\CMS\\Core\\Resource\\FileHandle', array(), array(),
'', FALSE);
273 $mockFileHandle->expects($this->any())->method(
'isOpen')->will($this->returnValue(TRUE));
274 $mockDriver = $this->getMockForAbstractClass(
't3lib_file_driver_Abstract');
275 $mockDriver->expects($this->any())->method(
'getFileHandle')->will($this->returnValue($mockFileHandle));
276 $mockDriver->expects($this->once())->method(
'readFromFile')->with($this->anything(), $this->equalTo($bytesToRead))->will($this->returnValue(substr($fileContents, 0, $bytesToRead)));
277 $fixture->setStorageDriver($mockDriver);
278 $fixture->open($fileMode);
279 $this->assertEquals(substr($fileContents, 0, $bytesToRead), $fixture->read($bytesToRead));
286 $this->markTestSkipped();
287 $this->setExpectedException(
'\\RuntimeException',
'', 1299863431);
289 $mockFileHandle = $this->getMock(
'TYPO3\\CMS\\Core\\Resource\\FileHandle', array(), array(),
'', FALSE);
290 $mockDriver = $this->getMockForAbstractClass(
't3lib_file_driver_Abstract');
291 $mockDriver->expects($this->any())->method(
'getFileHandle')->will($this->returnValue($mockFileHandle));
292 $fixture->setStorageDriver($mockDriver);
300 $this->markTestSkipped();
303 $fileContents =
'Some random file contents.';
304 $mockFileHandle = $this->getMock(
'TYPO3\\CMS\\Core\\Resource\\FileHandle', array(), array(),
'', FALSE);
305 $mockFileHandle->expects($this->any())->method(
'isOpen')->will($this->returnValue(TRUE));
306 $mockDriver = $this->getMockForAbstractClass(
't3lib_file_driver_Abstract');
307 $mockDriver->expects($this->any())->method(
'getFileHandle')->will($this->returnValue($mockFileHandle));
308 $mockDriver->expects($this->once())->method(
'writeToFile')->with($this->anything(), $this->equalTo($fileContents))->will($this->returnValue(TRUE));
309 $fixture->setStorageDriver($mockDriver);
310 $fixture->open($fileMode);
311 $this->assertTrue($fixture->write($fileContents));
318 $this->markTestSkipped();
319 $this->setExpectedException(
'\\RuntimeException',
'', 1299863432);
321 $mockFileHandle = $this->getMock(
'TYPO3\\CMS\\Core\\Resource\\FileHandle', array(), array(),
'', FALSE);
322 $mockDriver = $this->getMockForAbstractClass(
't3lib_file_driver_Abstract');
323 $mockDriver->expects($this->any())->method(
'getFileHandle')->will($this->returnValue($mockFileHandle));
324 $fixture->setStorageDriver($mockDriver);
325 $fixture->write(
'asdf');
330 array(
'somefile.jpg',
'somefile',
'jpg'),
331 array(
'SomeFile.PNG',
'SomeFile',
'png'),
332 array(
'somefile',
'somefile',
''),
333 array(
'somefile.tar.gz',
'somefile.tar',
'gz'),
334 array(
'somefile.tar.bz2',
'somefile.tar',
'bz2'),
343 $fixture = new \TYPO3\CMS\Core\Resource\File(array(
344 'name' => $originalFilename,
345 'identifier' =>
'/' . $originalFilename
348 $this->assertSame($expectedBasename, $fixture->getNameWithoutExtension());
356 $fixture = new \TYPO3\CMS\Core\Resource\File(array(
357 'name' => $originalFilename,
358 'identifier' =>
'/' . $originalFilename
359 ), $this->storageMock);
360 $this->assertSame($expectedExtension, $fixture->getExtension());
367 $fixture = new \TYPO3\CMS\Core\Resource\File(array(
'testproperty' =>
'testvalue'), $this->storageMock);
368 $this->assertTrue($fixture->hasProperty(
'testproperty'));
375 $fixture = $this->
getAccessibleMock(
'TYPO3\\CMS\\Core\\Resource\\File', array(
'dummy'), array(array(), $this->storageMock));
376 $fixture->_set(
'metaDataLoaded', TRUE);
377 $fixture->_set(
'metaDataProperties', array(
'testproperty' =>
'testvalue'));
378 $this->assertTrue($fixture->hasProperty(
'testproperty'));
getNameWithoutExtensionReturnsCorrectName($originalFilename, $expectedBasename)
static getSingletonInstances()
static setSingletonInstance($className, \TYPO3\CMS\Core\SingletonInterface $instance)
updatePropertiesRecordsNamesOfChangedProperties()
writePassesContentsToDriver()
updatePropertiesMarksPropertyAsChangedOnlyOnce()
updatePropertiesDoesNotRecordPropertyNameIfSameValueIsProvided()
getExtensionReturnsCorrectExtension($originalFilename, $expectedBasename, $expectedExtension)
commonPropertiesAreAvailableWithOwnGetters()
copyToCallsCopyOperationOnTargetFolderStorage()
writeFailsIfFileIsClosed()
hasPropertyReturnsTrueIfMetadataPropertyExists()
static resetSingletonInstances(array $newSingletonInstances)
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)
moveToCallsMoveOperationOnTargetFolderStorage()
openCorrectlyOpensFileInDriver()
propertiesPassedToConstructorAreAvailableViaGenericGetter()
fileIndexStatusIsTrueIfUidIsSet()
updatePropertiesUpdatesFileProperties()
isOpenReturnsCorrectValuesForClosedAndOpenFile()
updatePropertiesLeavesPropertiesUntouchedIfNotSetInNewProperties()
updatePropertiesReloadsStorageObjectIfStorageChanges()
hasPropertyReturnsTrueFilePropertyExists()
readFailsIfFileIsClosed()
filenameExtensionDataProvider()
readReturnsRequestedContentsFromDriver()
updatePropertiesDiscardsUidIfAlreadySet()