2 declare(strict_types = 1);
18 use Prophecy\Argument;
28 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
69 'header' =>
'dummy content header',
81 'sys_language_uid' =>
'0',
90 protected function setUp()
92 $this->iconRegistryMock = $this->prophesize(IconRegistry::class);
93 $signalSlotDispatcherMock = $this->prophesize(SignalSlotDispatcher::class);
94 $signalSlotDispatcherMock->dispatch(Argument::any(), Argument::any(), Argument::type(
'array'))->willReturnArgument(2);
95 GeneralUtility::setSingletonInstance(SignalSlotDispatcher::class, $signalSlotDispatcherMock->reveal());
97 $this->subject =
new IconFactory($this->iconRegistryMock->reveal());
99 $this->iconRegistryMock->isRegistered(
'tcarecords--default')->willReturn(
false);
100 $this->iconRegistryMock->isRegistered(Argument::any())->willReturn(
true);
101 $this->iconRegistryMock->isDeprecated(Argument::any())->willReturn(
false);
102 $this->iconRegistryMock->getDefaultIconIdentifier()->willReturn(
'default-not-found');
103 $this->iconRegistryMock->getIconIdentifierForMimeType(
'application/pdf')->willReturn(
'mimetypes-pdf');
104 $this->iconRegistryMock->getIconIdentifierForMimeType(
'image/*')->willReturn(
'mimetypes-media-image');
105 $this->iconRegistryMock->getIconIdentifierForMimeType(Argument::any())->willReturn(
null);
106 $this->iconRegistryMock->getIconIdentifierForFileExtension(Argument::any())->willReturn(
'mimetypes-other-other');
107 $this->iconRegistryMock->getIconIdentifierForFileExtension(
'foo')->willReturn(
'mimetypes-other-other');
108 $this->iconRegistryMock->getIconIdentifierForFileExtension(
'pdf')->willReturn(
'mimetypes-pdf');
109 $this->iconRegistryMock->getIconIdentifierForFileExtension(
'png')->willReturn(
'mimetypes-media-image');
110 $this->iconRegistryMock->getIconConfigurationByIdentifier(Argument::any())->willReturn([
111 'provider' => FontawesomeIconProvider::class,
114 'additionalClasses' =>
'fa-fw'
138 $this->assertContains(
139 '<span class="icon-markup">',
140 $this->subject->getIcon($this->registeredIconIdentifier)->render()
149 $this->assertContains(
150 '<span class="t3js-icon icon icon-size-default icon-state-default icon-actions-close" data-identifier="actions-close">',
151 $this->subject->getIcon($this->registeredIconIdentifier)->render()
161 $this->assertContains(
162 '<span class="t3js-icon icon icon-size-' . $size[
'expected'] .
' icon-state-default icon-actions-close" data-identifier="actions-close">',
163 $this->subject->getIcon($this->registeredIconIdentifier, $size[
'input'])->render()
173 $this->assertContains(
174 '<span class="icon-overlay icon-overlay-readonly">',
175 $this->subject->getIcon($this->registeredIconIdentifier, $size[
'input'],
'overlay-readonly')->render()
184 $this->iconRegistryMock->isRegistered(Argument::any())->willReturn(
false);
185 $this->iconRegistryMock->getDefaultIconIdentifier(Argument::any())->willReturn(
'default-not-found');
186 $this->iconRegistryMock->getIconConfigurationByIdentifier(
'default-not-found')->willReturn([
187 'provider' => FontawesomeIconProvider::class,
189 'name' =>
'times-circle',
190 'additionalClasses' =>
'fa-fw'
193 $this->assertContains(
194 '<span class="t3js-icon icon icon-size-default icon-state-default icon-default-not-found" data-identifier="default-not-found">',
195 $this->subject->getIcon($this->notRegisteredIconIdentifier)->render()
205 $this->iconRegistryMock->isRegistered(Argument::any())->willReturn(
false);
206 $this->iconRegistryMock->getDefaultIconIdentifier(Argument::any())->willReturn(
'default-not-found');
207 $this->iconRegistryMock->getIconConfigurationByIdentifier(
'default-not-found')->willReturn([
208 'provider' => FontawesomeIconProvider::class,
210 'name' =>
'times-circle',
211 'additionalClasses' =>
'fa-fw'
214 $this->assertContains(
215 '<span class="t3js-icon icon icon-size-' . $size[
'expected'] .
' icon-state-default icon-default-not-found" data-identifier="default-not-found">',
216 $this->subject->getIcon($this->notRegisteredIconIdentifier, $size[
'input'])->render()
225 $this->iconRegistryMock->getIconConfigurationByIdentifier($this->registeredSpinningIconIdentifier)->willReturn([
226 'provider' => FontawesomeIconProvider::class,
228 'name' =>
'times-circle',
229 'additionalClasses' =>
'fa-fw',
233 $this->assertContains(
234 '<span class="t3js-icon icon icon-size-default icon-state-default icon-' . $this->registeredSpinningIconIdentifier .
' icon-spin" data-identifier="spinning-icon">',
235 $this->subject->getIcon($this->registeredSpinningIconIdentifier)->render()
246 $this->assertContains(
247 '<span class="icon-overlay icon-overlay-readonly">',
248 $this->subject->getIcon($this->notRegisteredIconIdentifier, $size[
'input'],
'overlay-readonly')->render()
257 $this->expectException(\InvalidArgumentException::class);
258 $this->subject->getIcon($this->registeredIconIdentifier,
'foo')->render();
272 $this->assertContains(
273 '<span class="t3js-icon icon icon-size-default icon-state-default icon-mimetypes-other-other" data-identifier="mimetypes-other-other">',
274 $this->subject->getIconForFileExtension(
'')->render()
285 $this->assertContains(
286 '<span class="t3js-icon icon icon-size-default icon-state-default icon-mimetypes-other-other" data-identifier="mimetypes-other-other">',
287 $this->subject->getIconForFileExtension(
'foo')->render()
298 $this->assertContains(
299 '<span class="t3js-icon icon icon-size-default icon-state-default icon-mimetypes-pdf" data-identifier="mimetypes-pdf">',
300 $this->subject->getIconForFileExtension(
'pdf')->render()
311 $this->assertContains(
312 '<span class="t3js-icon icon icon-size-default icon-state-default icon-mimetypes-media-image" data-identifier="mimetypes-media-image">',
313 $this->subject->getIconForFileExtension(
'png')->render()
322 $resourceProphecy = $this->prophesize(File::class);
323 $resourceProphecy->isMissing()->willReturn(
false);
324 $resourceProphecy->getExtension()->willReturn(
'pdf');
325 $resourceProphecy->getMimeType()->willReturn(
'');
327 $this->assertContains(
328 '<span class="t3js-icon icon icon-size-default icon-state-default icon-mimetypes-pdf" data-identifier="mimetypes-pdf">',
329 $this->subject->getIconForResource($resourceProphecy->reveal())->render()
344 $result = $this->subject->getIconForResource($fileObject)->render();
345 $this->assertContains(
'<span class="t3js-icon icon icon-size-default icon-state-default icon-mimetypes-other-other" data-identifier="mimetypes-other-other">', $result);
356 $result = $this->subject->getIconForResource($fileObject)->render();
357 $this->assertContains(
'<span class="t3js-icon icon icon-size-default icon-state-default icon-mimetypes-other-other" data-identifier="mimetypes-other-other">', $result);
368 $result = $this->subject->getIconForResource($fileObject)->render();
369 $this->assertContains(
'<span class="t3js-icon icon icon-size-default icon-state-default icon-mimetypes-pdf" data-identifier="mimetypes-pdf">', $result);
380 $result = $this->subject->getIconForResource($fileObject)->render();
381 $this->assertContains(
'<span class="t3js-icon icon icon-size-default icon-state-default icon-mimetypes-pdf" data-identifier="mimetypes-pdf">', $result);
392 $result = $this->subject->getIconForResource($fileObject)->render();
393 $this->assertContains(
'<span class="t3js-icon icon icon-size-default icon-state-default icon-mimetypes-media-image" data-identifier="mimetypes-media-image">', $result);
404 $result = $this->subject->getIconForResource($fileObject)->render();
405 $this->assertContains(
'<span class="t3js-icon icon icon-size-default icon-state-default icon-mimetypes-media-image" data-identifier="mimetypes-media-image">', $result);
416 $result = $this->subject->getIconForResource($folderObject)->render();
417 $this->assertContains(
'<span class="t3js-icon icon icon-size-default icon-state-default icon-apps-filetree-folder-default" data-identifier="apps-filetree-folder-default">', $result);
428 $result = $this->subject->getIconForResource($folderObject,
Icon::SIZE_DEFAULT,
null, [
'folder-open' =>
true])->render();
429 $this->assertContains(
'<span class="t3js-icon icon icon-size-default icon-state-default icon-apps-filetree-folder-opened" data-identifier="apps-filetree-folder-opened">', $result);
440 $result = $this->subject->getIconForResource($folderObject)->render();
441 $this->assertContains(
'<span class="t3js-icon icon icon-size-default icon-state-default icon-apps-filetree-root" data-identifier="apps-filetree-root">', $result);
452 $result = $this->subject->getIconForResource($folderObject,
Icon::SIZE_DEFAULT,
null, [
'mount-root' =>
true])->render();
453 $this->assertContains(
'<span class="t3js-icon icon icon-size-default icon-state-default icon-apps-filetree-mount" data-identifier="apps-filetree-mount">', $result);
468 $this->assertContains(
469 '<span class="t3js-icon icon icon-size-default icon-state-default icon-default-not-found" data-identifier="default-not-found">',
470 $this->subject->getIconForRecord(
'', [])->render()
484 'typeicon_column' =>
'CType',
485 'typeicon_classes' => [
486 'default' =>
'mimetypes-x-content-text',
491 $result = $this->subject->getIconForRecord(
'tt_content', [])->render();
492 $this->assertContains(
'<span class="t3js-icon icon icon-size-default icon-state-default icon-mimetypes-x-content-text" data-identifier="mimetypes-x-content-text">', $result);
505 'typeicon_column' =>
'CType',
506 'typeicon_classes' => [
508 'text' =>
'mimetypes-x-content-text',
513 $result = $this->subject->getIconForRecord(
'tt_content', $this->mockRecord)->render();
514 $this->assertContains(
'<span class="t3js-icon icon icon-size-default icon-state-default icon-mimetypes-x-content-text" data-identifier="mimetypes-x-content-text">', $result);
527 'typeicon_column' =>
'CType',
528 'typeicon_classes' => [
530 'list' =>
'mimetypes-x-content-plugin',
537 $result = $this->subject->getIconForRecord(
'tt_content',
$mockRecord)->render();
538 $this->assertContains(
'<span class="t3js-icon icon icon-size-default icon-state-default icon-mimetypes-x-content-plugin" data-identifier="mimetypes-x-content-plugin">', $result);
552 'disabled' =>
'hidden',
554 'typeicon_column' =>
'CType',
555 'typeicon_classes' => [
557 'text' =>
'mimetypes-x-content-text',
564 $result = $this->subject->getIconForRecord(
'tt_content',
$mockRecord)->render();
565 $this->assertContains(
'<span class="t3js-icon icon icon-size-default icon-state-default icon-mimetypes-x-content-text" data-identifier="mimetypes-x-content-text">', $result);
566 $this->assertContains(
'<span class="icon-overlay icon-overlay-hidden">', $result);
578 $mockedStorage = $this->createMock(ResourceStorage::class);
579 $mockedFile = $this->getMockBuilder(File::class)
580 ->setConstructorArgs([[
'identifier' =>
'',
'name' =>
''], $mockedStorage])
582 $mockedFile->expects($this->atMost(1))->method(
'getExtension')->will($this->returnValue($extension));
583 $mockedFile->expects($this->atLeastOnce())->method(
'getMimeType')->will($this->returnValue($mimeType));
595 $mockedStorage = $this->createMock(ResourceStorage::class);
596 $mockedStorage->expects($this->any())->method(
'getRootLevelFolder')->will($this->returnValue(
597 new Folder($mockedStorage,
'/',
'/')
599 $mockedStorage->expects($this->any())->method(
'checkFolderActionPermission')->will($this->returnValue(
true));
600 $mockedStorage->expects($this->any())->method(
'isBrowsable')->will($this->returnValue(
true));
601 return new Folder($mockedStorage, $identifier, $identifier);