‪TYPO3CMS  10.4
AbstractFileTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
28 class ‪AbstractFileTest extends UnitTestCase
29 {
34  {
35  $parentIdentifier = '/parent/';
36  $currentIdentifier = '/parent/current/';
37 
39  $mockedStorageForParent = $this->createMock(ResourceStorage::class);
40 
42  $parentFolderFixture = $this->getMockForAbstractClass(AbstractFile::class);
43  $parentFolderFixture->setIdentifier($parentIdentifier)->setStorage($mockedStorageForParent);
44 
46  $mockedStorage = $this->getMockBuilder(ResourceStorage::class)
47  ->setMethods(['getFolderIdentifierFromFileIdentifier', 'getFolder'])
48  ->disableOriginalConstructor()
49  ->getMock();
50  $mockedStorage->expects(self::once())->method('getFolderIdentifierFromFileIdentifier')->with($currentIdentifier)->willReturn($parentIdentifier);
51  $mockedStorage->expects(self::once())->method('getFolder')->with($parentIdentifier)->willReturn($parentFolderFixture);
52 
54  $currentFolderFixture = $this->getMockForAbstractClass(AbstractFile::class);
55  $currentFolderFixture->setIdentifier($currentIdentifier)->setStorage($mockedStorage);
56 
57  self::assertSame($parentFolderFixture, $currentFolderFixture->getParentFolder());
58  }
59 
69  {
71  $mockedStorage = $this->getMockBuilder(ResourceStorage::class)->disableOriginalConstructor()->getMock();
72  $mockedStorage->expects(self::never())->method('getFileInfoByIdentifier')->with('/foo', 'mimetype');
73  $subject = new ‪File(['identifier' => '/foo', 'mime_type' => 'my/mime-type'], $mockedStorage);
74 
75  self::assertEquals('my/mime-type', $subject->getMimeType());
76  }
77 }
‪TYPO3\CMS\Core\Tests\Unit\Resource
Definition: AbstractFileTest.php:18
‪TYPO3\CMS\Core\Resource\AbstractFile
Definition: AbstractFile.php:26
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:24
‪TYPO3\CMS\Core\Tests\Unit\Resource\AbstractFileTest
Definition: AbstractFileTest.php:29
‪TYPO3\CMS\Core\Resource\ResourceStorage
Definition: ResourceStorage.php:122
‪TYPO3\CMS\Core\Tests\Unit\Resource\AbstractFileTest\getParentFolderGetsParentFolderFromStorage
‪getParentFolderGetsParentFolderFromStorage()
Definition: AbstractFileTest.php:33
‪TYPO3\CMS\Core\Tests\Unit\Resource\AbstractFileTest\storageIsNotAskedForMimeTypeForPersistedRecord
‪storageIsNotAskedForMimeTypeForPersistedRecord()
Definition: AbstractFileTest.php:68