2 declare(strict_types = 1);
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
39 protected function setUp(): void
41 $this->storageMock = $this->createMock(ResourceStorage::class);
42 $this->storageMock->expects($this->any())->method(
'getUid')->will($this->returnValue(5));
44 $mockedMetaDataRepository = $this->createMock(MetaDataRepository::class);
45 $mockedMetaDataRepository->expects($this->any())->method(
'findByFile')->will($this->returnValue([
'file' => 1]));
46 GeneralUtility::setSingletonInstance(MetaDataRepository::class, $mockedMetaDataRepository);
54 $fixture =
new File([
'testfile'], $this->storageMock);
64 'name' => $this->getUniqueId(),
68 $fixture =
new File($properties, $this->storageMock);
69 foreach ($properties as $key => $value) {
70 $this->assertEquals($value, call_user_func([$fixture,
'get' . $key]));
81 $fixture =
new File([
'uid' => 1], $this->storageMock);
82 $this->assertTrue($fixture->isIndexed());
90 $identifier =
'/' . $this->getUniqueId();
91 $fixture =
new File([
'uid' => 1,
'identifier' =>
'/test'], $this->storageMock);
92 $fixture->updateProperties([
'identifier' => $identifier]);
93 $this->assertEquals($identifier, $fixture->getIdentifier());
101 $fixture =
new File([
'uid' => 1,
'foo' =>
'asdf',
'identifier' =>
'/test'], $this->storageMock);
102 $fixture->updateProperties([
'foo' =>
'foobar']);
103 $this->assertEquals(
'/test', $fixture->getIdentifier());
104 $this->assertEquals(
'/test', $fixture->getProperty(
'identifier'));
112 $fixture =
new File([
'uid' => 1,
'identifier' =>
'/test'], $this->storageMock);
113 $fixture->updateProperties([
'uid' => 3]);
114 $this->assertEquals(1, $fixture->getUid());
122 $fixture =
new File([
'uid' => 1,
'foo' =>
'asdf',
'baz' =>
'fdsw',
'identifier' =>
'/test'], $this->storageMock);
123 $fixture->updateProperties([
'foo' =>
'foobar',
'baz' =>
'foobaz']);
124 $this->assertEquals([
'foo',
'baz'], $fixture->getUpdatedProperties());
132 $fixture =
new File([
'uid' => 1,
'foo' =>
'asdf',
'identifier' =>
'/test'], $this->storageMock);
133 $fixture->updateProperties([
'foo' =>
'asdf']);
134 $this->assertEmpty($fixture->getUpdatedProperties());
142 $fixture =
new File([
'uid' => 1,
'foo' =>
'asdf',
'baz' =>
'fdsw',
'identifier' =>
'/test'], $this->storageMock);
143 $fixture->updateProperties([
'foo' =>
'foobar',
'baz' =>
'foobaz']);
144 $fixture->updateProperties([
'foo' =>
'fdsw',
'baz' =>
'asdf']);
145 $this->assertEquals([
'foo',
'baz'], $fixture->getUpdatedProperties());
155 'storage' =>
'first',
157 $subject = $this->getMockBuilder(File::class)
158 ->setMethods([
'loadStorage'])
159 ->setConstructorArgs([$fileProperties, $this->storageMock])
161 $mockedNewStorage = $this->createMock(\
TYPO3\CMS\Core\Resource\ResourceStorage::class);
162 $mockedResourceFactory = $this->createMock(\
TYPO3\CMS\Core\Resource\ResourceFactory::class);
163 $mockedResourceFactory
164 ->expects($this->once())
165 ->method(
'getStorageObject')
166 ->will($this->returnValue($mockedNewStorage));
167 GeneralUtility::setSingletonInstance(\
TYPO3\CMS\Core\Resource\ResourceFactory::class, $mockedResourceFactory);
169 $subject->updateProperties([
'storage' =>
'different']);
170 $this->assertSame($mockedNewStorage, $subject->getStorage());
178 $targetStorage = $this->createMock(\
TYPO3\CMS\Core\Resource\ResourceStorage::class);
179 $targetFolder = $this->createMock(\
TYPO3\CMS\Core\Resource\Folder::class);
180 $targetFolder->expects($this->any())->method(
'getStorage')->will($this->returnValue($targetStorage));
181 $fixture =
new File([], $this->storageMock);
182 $targetStorage->expects($this->once())->method(
'copyFile')->with($this->equalTo($fixture), $this->equalTo($targetFolder));
183 $fixture->copyTo($targetFolder);
191 $targetStorage = $this->createMock(\
TYPO3\CMS\Core\Resource\ResourceStorage::class);
192 $targetFolder = $this->createMock(\
TYPO3\CMS\Core\Resource\Folder::class);
193 $targetFolder->expects($this->any())->method(
'getStorage')->will($this->returnValue($targetStorage));
194 $fixture =
new File([], $this->storageMock);
195 $targetStorage->expects($this->once())->method(
'moveFile')->with($this->equalTo($fixture), $this->equalTo($targetFolder));
196 $fixture->moveTo($targetFolder);
202 [
'somefile.jpg',
'somefile',
'jpg'],
203 [
'SomeFile.PNG',
'SomeFile',
'png'],
204 [
'somefile',
'somefile',
''],
205 [
'somefile.tar.gz',
'somefile.tar',
'gz'],
206 [
'somefile.tar.bz2',
'somefile.tar',
'bz2'],
218 'name' => $originalFilename,
219 'identifier' =>
'/' . $originalFilename
223 $this->assertSame($expectedBasename, $fixture->getNameWithoutExtension());
232 $fixture =
new File([
233 'name' => $originalFilename,
234 'identifier' =>
'/' . $originalFilename
235 ], $this->storageMock);
236 $this->assertSame($expectedExtension, $fixture->getExtension());
244 $fixture =
new File([
'testproperty' =>
'testvalue'], $this->storageMock);
245 $this->assertTrue($fixture->hasProperty(
'testproperty'));
253 $fixture = $this->getAccessibleMock(File::class, [
'dummy'], [[], $this->storageMock]);
254 $fixture->_set(
'metaDataLoaded',
true);
255 $fixture->_set(
'metaDataProperties', [
'testproperty' =>
'testvalue']);
256 $this->assertTrue($fixture->hasProperty(
'testproperty'));