‪TYPO3CMS  ‪main
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 
20 use PHPUnit\Framework\Attributes\Test;
25 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
26 
30 final class ‪AbstractFileTest extends UnitTestCase
31 {
32  #[Test]
34  {
35  $parentIdentifier = '/parent/';
36  $currentIdentifier = '/parent/current/';
37 
38  $mockedStorageForParent = $this->createMock(ResourceStorage::class);
39 
40  $parentFolderFixture = $this->createMock(FolderInterface::class);
41  $parentFolderFixture->method('getStorage')->willReturn($mockedStorageForParent);
42 
43  $mockedStorage = $this->getMockBuilder(ResourceStorage::class)
44  ->onlyMethods(['getFolderIdentifierFromFileIdentifier', 'getFolder'])
45  ->disableOriginalConstructor()
46  ->getMock();
47  $mockedStorage->expects(self::once())->method('getFolderIdentifierFromFileIdentifier')->with($currentIdentifier)->willReturn($parentIdentifier);
48  $mockedStorage->expects(self::once())->method('getFolder')->with($parentIdentifier)->willReturn($parentFolderFixture);
49 
50  $currentFolderFixture = new ‪TestingFile();
51  $currentFolderFixture->setIdentifier($currentIdentifier)->setStorage($mockedStorage);
52 
53  self::assertSame($parentFolderFixture, $currentFolderFixture->getParentFolder());
54  }
55 
62  #[Test]
64  {
65  $mockedStorage = $this->getMockBuilder(ResourceStorage::class)->disableOriginalConstructor()->getMock();
66  $mockedStorage->expects(self::never())->method('getFileInfoByIdentifier')->with('/foo', 'mimetype');
67  $subject = new ‪File(['identifier' => '/foo', 'mime_type' => 'my/mime-type'], $mockedStorage);
68 
69  self::assertEquals('my/mime-type', $subject->getMimeType());
70  }
71 }
‪TYPO3\CMS\Core\Tests\Unit\Resource
Definition: AbstractFileTest.php:18
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:26
‪TYPO3\CMS\Core\Tests\Unit\Resource\AbstractFileTest
Definition: AbstractFileTest.php:31
‪TYPO3\CMS\Core\Resource\ResourceStorage
Definition: ResourceStorage.php:129
‪TYPO3\CMS\Core\Resource\FolderInterface
Definition: FolderInterface.php:24
‪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:63
‪TYPO3\CMS\Core\Tests\Unit\Resource\Fixtures\TestingFile
Definition: TestingFile.php:26