‪TYPO3CMS  11.5
DriverRegistryTest.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 class ‪DriverRegistryTest extends UnitTestCase
30 {
32 
33  protected function ‪setUp(): void
34  {
35  parent::setUp();
36  $this->‪initializeSubject();
37  }
38 
39  protected function ‪initializeSubject(): void
40  {
41  $this->subject = new ‪DriverRegistry();
42  }
43 
48  {
49  $className = get_class($this->getMockForAbstractClass(AbstractDriver::class));
50  $this->subject->registerDriverClass($className, 'foobar');
51  $returnedClassName = $this->subject->getDriverClass('foobar');
52  self::assertEquals($className, $returnedClassName);
53  }
54 
59  {
60  $this->expectException(\InvalidArgumentException::class);
61  $this->expectExceptionCode(1314979197);
62  $this->subject->registerDriverClass(‪StringUtility::getUniqueId('class_'));
63  }
64 
69  {
70  $this->expectException(\InvalidArgumentException::class);
71  $this->expectExceptionCode(1314979451);
72  $className = get_class($this->getMockForAbstractClass(AbstractDriver::class));
73  $className2 = get_class($this->getMockForAbstractClass(DriverInterface::class));
74  $this->subject->registerDriverClass($className, 'foobar');
75  $this->subject->registerDriverClass($className2, 'foobar');
76  }
77 
82  {
83  $this->expectException(\InvalidArgumentException::class);
84  $this->expectExceptionCode(1314085990);
85  $this->subject->getDriverClass(‪StringUtility::getUniqueId('class_'));
86  }
87 
92  {
93  $className = get_class($this->getMockForAbstractClass(AbstractDriver::class));
94  $this->subject->registerDriverClass($className, 'foobar');
95  self::assertEquals($className, $this->subject->getDriverClass($className));
96  }
97 
102  {
103  $className = get_class($this->getMockForAbstractClass(AbstractDriver::class));
104  $shortName = ‪StringUtility::getUniqueId('class_');
105  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['registeredDrivers'] = [
106  $shortName => [
107  'class' => $className,
108  ],
109  ];
110  $this->‪initializeSubject();
111  self::assertEquals($className, $this->subject->getDriverClass($shortName));
112  }
113 
118  {
119  $className = get_class($this->getMockForAbstractClass(AbstractDriver::class));
120  $shortName = ‪StringUtility::getUniqueId('class_');
121  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['registeredDrivers'] = [
122  $shortName => [
123  'class' => $className,
124  ],
125  ];
126  $this->‪initializeSubject();
127  self::assertTrue($this->subject->driverExists($shortName));
128  self::assertFalse($this->subject->driverExists(‪StringUtility::getUniqueId('class')));
129  }
130 
135  {
136  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['registeredDrivers'] = [];
137  $this->‪initializeSubject();
138  self::assertFalse($this->subject->driverExists(‪StringUtility::getUniqueId('class_')));
139  }
140 }
‪TYPO3\CMS\Core\Tests\Unit\Resource\Driver\DriverRegistryTest\driverExistsReturnsTrueForAllExistingDrivers
‪driverExistsReturnsTrueForAllExistingDrivers()
Definition: DriverRegistryTest.php:117
‪TYPO3\CMS\Core\Tests\Unit\Resource\Driver\DriverRegistryTest\$subject
‪DriverRegistry $subject
Definition: DriverRegistryTest.php:31
‪TYPO3\CMS\Core\Tests\Unit\Resource\Driver\DriverRegistryTest\initializeSubject
‪initializeSubject()
Definition: DriverRegistryTest.php:39
‪TYPO3\CMS\Core\Tests\Unit\Resource\Driver\DriverRegistryTest\driverRegistryIsInitializedWithPreconfiguredDrivers
‪driverRegistryIsInitializedWithPreconfiguredDrivers()
Definition: DriverRegistryTest.php:101
‪TYPO3\CMS\Core\Tests\Unit\Resource\Driver\DriverRegistryTest\registeredDriverClassesCanBeRetrieved
‪registeredDriverClassesCanBeRetrieved()
Definition: DriverRegistryTest.php:47
‪TYPO3\CMS\Core\Tests\Unit\Resource\Driver\DriverRegistryTest\registerDriverClassThrowsExceptionIfShortnameIsAlreadyTakenByAnotherDriverClass
‪registerDriverClassThrowsExceptionIfShortnameIsAlreadyTakenByAnotherDriverClass()
Definition: DriverRegistryTest.php:68
‪TYPO3\CMS\Core\Tests\Unit\Resource\Driver\DriverRegistryTest\getDriverClassThrowsExceptionIfClassIsNotRegistered
‪getDriverClassThrowsExceptionIfClassIsNotRegistered()
Definition: DriverRegistryTest.php:81
‪TYPO3\CMS\Core\Tests\Unit\Resource\Driver\DriverRegistryTest\setUp
‪setUp()
Definition: DriverRegistryTest.php:33
‪TYPO3\CMS\Core\Resource\Driver\DriverInterface
Definition: DriverInterface.php:23
‪TYPO3\CMS\Core\Tests\Unit\Resource\Driver
Definition: AbstractDriverTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\Resource\Driver\DriverRegistryTest
Definition: DriverRegistryTest.php:30
‪TYPO3\CMS\Core\Resource\Driver\DriverRegistry
Definition: DriverRegistry.php:24
‪TYPO3\CMS\Core\Utility\StringUtility\getUniqueId
‪static string getUniqueId($prefix='')
Definition: StringUtility.php:128
‪TYPO3\CMS\Core\Tests\Unit\Resource\Driver\DriverRegistryTest\registerDriverClassThrowsExceptionIfClassDoesNotExist
‪registerDriverClassThrowsExceptionIfClassDoesNotExist()
Definition: DriverRegistryTest.php:58
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Tests\Unit\Resource\Driver\DriverRegistryTest\getDriverClassAcceptsClassNameIfClassIsRegistered
‪getDriverClassAcceptsClassNameIfClassIsRegistered()
Definition: DriverRegistryTest.php:91
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:22
‪TYPO3\CMS\Core\Tests\Unit\Resource\Driver\DriverRegistryTest\driverExistsReturnsFalseIfDriverDoesNotExist
‪driverExistsReturnsFalseIfDriverDoesNotExist()
Definition: DriverRegistryTest.php:134
‪TYPO3\CMS\Core\Resource\Driver\AbstractDriver
Definition: AbstractDriver.php:25