‪TYPO3CMS  9.5
AbstractFileTest.php
Go to the documentation of this file.
1 <?php
2 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 
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
26 class ‪AbstractFileTest extends UnitTestCase
27 {
32  {
33  $parentIdentifier = '/parent/';
34  $currentIdentifier = '/parent/current/';
35 
37  $mockedStorageForParent = $this->createMock(ResourceStorage::class);
38 
40  $parentFolderFixture = $this->getMockForAbstractClass(AbstractFile::class);
41  $parentFolderFixture->setIdentifier($parentIdentifier)->setStorage($mockedStorageForParent);
42 
44  $mockedStorage = $this->getMockBuilder(ResourceStorage::class)
45  ->setMethods(['getFolderIdentifierFromFileIdentifier', 'getFolder'])
46  ->disableOriginalConstructor()
47  ->getMock();
48  $mockedStorage->expects($this->once())->method('getFolderIdentifierFromFileIdentifier')->with($currentIdentifier)->will($this->returnValue($parentIdentifier));
49  $mockedStorage->expects($this->once())->method('getFolder')->with($parentIdentifier)->will($this->returnValue($parentFolderFixture));
50 
52  $currentFolderFixture = $this->getMockForAbstractClass(AbstractFile::class);
53  $currentFolderFixture->setIdentifier($currentIdentifier)->setStorage($mockedStorage);
54 
55  $this->assertSame($parentFolderFixture, $currentFolderFixture->getParentFolder());
56  }
57 
67  {
69  $mockedStorage = $this->getMockBuilder(ResourceStorage::class)->disableOriginalConstructor()->getMock();
70  $mockedStorage->expects($this->never())->method('getFileInfoByIdentifier')->with('/foo', 'mimetype');
71  $subject = new ‪File(['identifier' => '/foo', 'mime_type' => 'my/mime-type'], $mockedStorage);
72 
73  $this->assertEquals('my/mime-type', $subject->getMimeType());
74  }
75 }
‪TYPO3\CMS\Core\Tests\Unit\Resource
Definition: AbstractFileTest.php:3
‪TYPO3\CMS\Core\Resource\AbstractFile
Definition: AbstractFile.php:24
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:23
‪TYPO3\CMS\Core\Tests\Unit\Resource\AbstractFileTest
Definition: AbstractFileTest.php:27
‪TYPO3\CMS\Core\Resource\ResourceStorage
Definition: ResourceStorage.php:74
‪TYPO3\CMS\Core\Tests\Unit\Resource\AbstractFileTest\getParentFolderGetsParentFolderFromStorage
‪getParentFolderGetsParentFolderFromStorage()
Definition: AbstractFileTest.php:31
‪TYPO3\CMS\Core\Tests\Unit\Resource\AbstractFileTest\storageIsNotAskedForMimeTypeForPersistedRecord
‪storageIsNotAskedForMimeTypeForPersistedRecord()
Definition: AbstractFileTest.php:66