‪TYPO3CMS  ‪main
ElementBrowserRegistryTest.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;
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
25 final class ‪ElementBrowserRegistryTest extends UnitTestCase
26 {
27  #[Test]
28  public function ‪registrationRequiresInterface(): void
29  {
30  $elementBrowser = [
31  new class () {},
32  $this->‪getElementBrowser('valid-identifier'),
33  ];
34 
35  $elementBrowserRegistry = new ‪ElementBrowserRegistry($elementBrowser);
36 
37  self::assertNotNull($elementBrowserRegistry->getElementBrowser('valid-identifier'));
38  self::assertCount(1, $elementBrowserRegistry->getElementBrowsers());
39  self::assertTrue($elementBrowserRegistry->hasElementBrowser('valid-identifier'));
40  }
41 
42  #[Test]
44  {
45  $elementBrowser = [
46  $this->‪getElementBrowser(),
47  ];
48 
49  $this->expectException(\InvalidArgumentException::class);
50  $this->expectExceptionCode(1647241084);
51 
52  new ‪ElementBrowserRegistry($elementBrowser);
53  }
54 
55  #[Test]
57  {
58  $elementBrowser = [
59  $this->‪getElementBrowser('duplicate'),
60  $this->‪getElementBrowser('duplicate'),
61  ];
62 
63  $this->expectException(\InvalidArgumentException::class);
64  $this->expectExceptionCode(1647241085);
65 
66  new ‪ElementBrowserRegistry($elementBrowser);
67  }
68 
69  #[Test]
71  {
72  $this->expectException(\UnexpectedValueException::class);
73  $this->expectExceptionCode(1647241086);
74 
75  (new ‪ElementBrowserRegistry([]))->‪getElementBrowser('non-existent-identifer');
76  }
77 
79  {
80  return new class (‪$identifier) implements ‪ElementBrowserInterface {
81  private string ‪$identifier;
82  public function __construct(string ‪$identifier)
83  {
84  $this->identifier = ‪$identifier;
85  }
86  public function getIdentifier(): string
87  {
88  return ‪$this->identifier;
89  }
90  public function render()
91  {
92  return '';
93  }
94  public function processSessionData($data)
95  {
96  return [];
97  }
98  };
99  }
100 }
‪TYPO3\CMS\Backend\ElementBrowser\ElementBrowserInterface
Definition: ElementBrowserInterface.php:28
‪TYPO3\CMS\Backend\Tests\Unit\ElementBrowser\ElementBrowserRegistryTest\registrationRequiresInterface
‪registrationRequiresInterface()
Definition: ElementBrowserRegistryTest.php:28
‪TYPO3\CMS\Backend\Tests\Unit\ElementBrowser
Definition: ElementBrowserRegistryTest.php:18
‪TYPO3\CMS\Backend\Tests\Unit\ElementBrowser\ElementBrowserRegistryTest\registrationThrowsExceptionOnDuplicateIdentifier
‪registrationThrowsExceptionOnDuplicateIdentifier()
Definition: ElementBrowserRegistryTest.php:56
‪TYPO3\CMS\Backend\Tests\Unit\ElementBrowser\ElementBrowserRegistryTest\getElementBrowser
‪getElementBrowser(string $identifier='')
Definition: ElementBrowserRegistryTest.php:78
‪TYPO3\CMS\Backend\Tests\Unit\ElementBrowser\ElementBrowserRegistryTest
Definition: ElementBrowserRegistryTest.php:26
‪TYPO3\CMS\Backend\ElementBrowser\ElementBrowserRegistry
Definition: ElementBrowserRegistry.php:27
‪TYPO3\CMS\Backend\Tests\Unit\ElementBrowser\ElementBrowserRegistryTest\registrationThrowsExceptionOnRequestingInvalidIdentifier
‪registrationThrowsExceptionOnRequestingInvalidIdentifier()
Definition: ElementBrowserRegistryTest.php:70
‪TYPO3\CMS\Backend\Tests\Unit\ElementBrowser\ElementBrowserRegistryTest\registrationThrowsExceptionOnEmptyIdentifier
‪registrationThrowsExceptionOnEmptyIdentifier()
Definition: ElementBrowserRegistryTest.php:43
‪TYPO3\CMS\Webhooks\Message\$identifier
‪identifier readonly string $identifier
Definition: FileAddedMessage.php:37