‪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 
20 use PHPUnit\Framework\Attributes\Test;
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 
39  #[Test]
40  public function ‪latestDefaultModeIsReturned(): void
41  {
42  $module = ‪JavaScriptModuleInstruction::create('@test/foo', 'bar')->invoke();
43  $firstDefaultMode = (new ‪Mode($module))->setAsDefault();
44  $expected = (new ‪Mode($module))->setAsDefault();
45  $this->subject->register($firstDefaultMode)->register($expected);
46  $actual = $this->subject->getDefaultMode();
47 
48  self::assertSame($expected, $actual);
49  }
50 
51  #[Test]
52  public function ‪formatCodeReturnsCorrectMode(): void
53  {
54  $module = ‪JavaScriptModuleInstruction::create('@test/mode', 'formatCode')->invoke();
55  $expected = (new ‪Mode($module))->setFormatCode('code');
56  $this->subject->register($expected);
57  $actual = $this->subject->getByFormatCode('code');
58 
59  self::assertSame($expected, $actual);
60  }
61 
62  #[Test]
63  public function ‪modeIsFetchedByFileExtension(): void
64  {
65  $module = ‪JavaScriptModuleInstruction::create('@test/mode', 'extension')->invoke();
66  $expected = (new ‪Mode($module))->bindToFileExtensions(['ext', 'fext']);
67  $this->subject->register($expected);
68  $actual = $this->subject->getByFileExtension('fext');
69 
70  self::assertSame($expected, $actual);
71  }
72 }
‪TYPO3\CMS\Core\Page\JavaScriptModuleInstruction
Definition: JavaScriptModuleInstruction.php:23
‪TYPO3\CMS\Backend\Tests\Unit\CodeEditor\Registry\ModeRegistryTest\formatCodeReturnsCorrectMode
‪formatCodeReturnsCorrectMode()
Definition: ModeRegistryTest.php:52
‪TYPO3\CMS\Backend\Tests\Unit\CodeEditor\Registry\ModeRegistryTest\modeIsFetchedByFileExtension
‪modeIsFetchedByFileExtension()
Definition: ModeRegistryTest.php:63
‪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:40
‪TYPO3\CMS\Backend\CodeEditor\Registry\ModeRegistry
Definition: ModeRegistry.php:29
‪TYPO3\CMS\Core\Page\JavaScriptModuleInstruction\create
‪static create(string $name, ?string $exportName=null)
Definition: JavaScriptModuleInstruction.php:47