‪TYPO3CMS  ‪main
ModeRegistryTest.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 
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
29 final class ‪ModeRegistryTest extends UnitTestCase
30 {
32 
33  protected function ‪setUp(): void
34  {
35  parent::setUp();
36  $this->subject = new ‪ModeRegistry();
37  }
38 
42  public function ‪latestDefaultModeIsReturned(): void
43  {
44  $module = ‪JavaScriptModuleInstruction::create('@test/foo', 'bar')->invoke();
45  $firstDefaultMode = GeneralUtility::makeInstance(Mode::class, $module)->setAsDefault();
46  $expected = GeneralUtility::makeInstance(Mode::class, $module)->setAsDefault();
47  $this->subject->register($firstDefaultMode)->register($expected);
48  $actual = $this->subject->getDefaultMode();
49 
50  self::assertSame($expected, $actual);
51  }
52 
56  public function ‪formatCodeReturnsCorrectMode(): void
57  {
58  $module = ‪JavaScriptModuleInstruction::create('@test/mode', 'formatCode')->invoke();
59  $expected = GeneralUtility::makeInstance(Mode::class, $module)->setFormatCode('code');
60  $this->subject->register($expected);
61  $actual = $this->subject->getByFormatCode('code');
62 
63  self::assertSame($expected, $actual);
64  }
65 
69  public function ‪modeIsFetchedByFileExtension(): void
70  {
71  $module = ‪JavaScriptModuleInstruction::create('@test/mode', 'extension')->invoke();
72  $expected = GeneralUtility::makeInstance(Mode::class, $module)->bindToFileExtensions(['ext', 'fext']);
73  $this->subject->register($expected);
74  $actual = $this->subject->getByFileExtension('fext');
75 
76  self::assertSame($expected, $actual);
77  }
78 }
‪TYPO3\CMS\Core\Page\JavaScriptModuleInstruction\create
‪static create(string $name, string $exportName=null)
Definition: JavaScriptModuleInstruction.php:47
‪TYPO3\CMS\Core\Page\JavaScriptModuleInstruction
Definition: JavaScriptModuleInstruction.php:23
‪TYPO3\CMS\Backend\Tests\Unit\CodeEditor\Registry\ModeRegistryTest\formatCodeReturnsCorrectMode
‪formatCodeReturnsCorrectMode()
Definition: ModeRegistryTest.php:56
‪TYPO3\CMS\Backend\Tests\Unit\CodeEditor\Registry\ModeRegistryTest\modeIsFetchedByFileExtension
‪modeIsFetchedByFileExtension()
Definition: ModeRegistryTest.php:69
‪TYPO3\CMS\Filelist\Type\Mode
‪Mode
Definition: Mode.php:24
‪TYPO3\CMS\Backend\Tests\Unit\CodeEditor\Registry
Definition: AddonRegistryTest.php:18
‪TYPO3\CMS\Backend\Tests\Unit\CodeEditor\Registry\ModeRegistryTest
Definition: ModeRegistryTest.php:30
‪TYPO3\CMS\Backend\Tests\Unit\CodeEditor\Registry\ModeRegistryTest\$subject
‪ModeRegistry $subject
Definition: ModeRegistryTest.php:31
‪TYPO3\CMS\Backend\Tests\Unit\CodeEditor\Registry\ModeRegistryTest\setUp
‪setUp()
Definition: ModeRegistryTest.php:33
‪TYPO3\CMS\Backend\Tests\Unit\CodeEditor\Registry\ModeRegistryTest\latestDefaultModeIsReturned
‪latestDefaultModeIsReturned()
Definition: ModeRegistryTest.php:42
‪TYPO3\CMS\Backend\CodeEditor\Registry\ModeRegistry
Definition: ModeRegistry.php:29
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52