‪TYPO3CMS  10.4
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 {
34  protected ‪$subject;
35 
36  protected function ‪setUp(): void
37  {
38  parent::setUp();
39  $this->‪initializeSubject();
40  }
41 
42  protected function ‪initializeSubject(): void
43  {
44  $this->subject = new ‪DriverRegistry();
45  }
46 
50  public function ‪registeredDriverClassesCanBeRetrieved(): void
51  {
52  $className = get_class($this->getMockForAbstractClass(AbstractDriver::class));
53  $this->subject->registerDriverClass($className, 'foobar');
54  $returnedClassName = $this->subject->getDriverClass('foobar');
55  self::assertEquals($className, $returnedClassName);
56  }
57 
62  {
63  $this->expectException(\InvalidArgumentException::class);
64  $this->expectExceptionCode(1314979197);
65  $this->subject->registerDriverClass(‪StringUtility::getUniqueId('class_'));
66  }
67 
72  {
73  $this->expectException(\InvalidArgumentException::class);
74  $this->expectExceptionCode(1314979451);
75  $className = get_class($this->getMockForAbstractClass(AbstractDriver::class));
76  $className2 = get_class($this->getMockForAbstractClass(DriverInterface::class));
77  $this->subject->registerDriverClass($className, 'foobar');
78  $this->subject->registerDriverClass($className2, 'foobar');
79  }
80 
85  {
86  $this->expectException(\InvalidArgumentException::class);
87  $this->expectExceptionCode(1314085990);
88  $this->subject->getDriverClass(‪StringUtility::getUniqueId('class_'));
89  }
90 
95  {
96  $className = get_class($this->getMockForAbstractClass(AbstractDriver::class));
97  $this->subject->registerDriverClass($className, 'foobar');
98  self::assertEquals($className, $this->subject->getDriverClass($className));
99  }
100 
105  {
106  $className = get_class($this->getMockForAbstractClass(AbstractDriver::class));
107  $shortName = ‪StringUtility::getUniqueId('class_');
108  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['registeredDrivers'] = [
109  $shortName => [
110  'class' => $className
111  ]
112  ];
113  $this->‪initializeSubject();
114  self::assertEquals($className, $this->subject->getDriverClass($shortName));
115  }
116 
121  {
122  $className = get_class($this->getMockForAbstractClass(AbstractDriver::class));
123  $shortName = ‪StringUtility::getUniqueId('class_');
124  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['registeredDrivers'] = [
125  $shortName => [
126  'class' => $className
127  ]
128  ];
129  $this->‪initializeSubject();
130  self::assertTrue($this->subject->driverExists($shortName));
131  self::assertFalse($this->subject->driverExists(‪StringUtility::getUniqueId('class')));
132  }
133 
138  {
139  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['registeredDrivers'] = [];
140  $this->‪initializeSubject();
141  self::assertFalse($this->subject->driverExists(‪StringUtility::getUniqueId('class_')));
142  }
143 }
‪TYPO3\CMS\Core\Tests\Unit\Resource\Driver\DriverRegistryTest\driverExistsReturnsTrueForAllExistingDrivers
‪driverExistsReturnsTrueForAllExistingDrivers()
Definition: DriverRegistryTest.php:119
‪TYPO3\CMS\Core\Tests\Unit\Resource\Driver\DriverRegistryTest\$subject
‪DriverRegistry $subject
Definition: DriverRegistryTest.php:33
‪TYPO3\CMS\Core\Tests\Unit\Resource\Driver\DriverRegistryTest\initializeSubject
‪initializeSubject()
Definition: DriverRegistryTest.php:41
‪TYPO3\CMS\Core\Tests\Unit\Resource\Driver\DriverRegistryTest\driverRegistryIsInitializedWithPreconfiguredDrivers
‪driverRegistryIsInitializedWithPreconfiguredDrivers()
Definition: DriverRegistryTest.php:103
‪TYPO3\CMS\Core\Tests\Unit\Resource\Driver\DriverRegistryTest\registeredDriverClassesCanBeRetrieved
‪registeredDriverClassesCanBeRetrieved()
Definition: DriverRegistryTest.php:49
‪TYPO3\CMS\Core\Tests\Unit\Resource\Driver\DriverRegistryTest\registerDriverClassThrowsExceptionIfShortnameIsAlreadyTakenByAnotherDriverClass
‪registerDriverClassThrowsExceptionIfShortnameIsAlreadyTakenByAnotherDriverClass()
Definition: DriverRegistryTest.php:70
‪TYPO3\CMS\Core\Tests\Unit\Resource\Driver\DriverRegistryTest\getDriverClassThrowsExceptionIfClassIsNotRegistered
‪getDriverClassThrowsExceptionIfClassIsNotRegistered()
Definition: DriverRegistryTest.php:83
‪TYPO3\CMS\Core\Tests\Unit\Resource\Driver\DriverRegistryTest\setUp
‪setUp()
Definition: DriverRegistryTest.php:35
‪TYPO3\CMS\Core\Resource\Driver\DriverInterface
Definition: DriverInterface.php:23
‪TYPO3\CMS\Core\Tests\Unit\Resource\Driver
Definition: AbstractDriverTest.php:16
‪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:92
‪TYPO3\CMS\Core\Tests\Unit\Resource\Driver\DriverRegistryTest\registerDriverClassThrowsExceptionIfClassDoesNotExist
‪registerDriverClassThrowsExceptionIfClassDoesNotExist()
Definition: DriverRegistryTest.php:60
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Tests\Unit\Resource\Driver\DriverRegistryTest\getDriverClassAcceptsClassNameIfClassIsRegistered
‪getDriverClassAcceptsClassNameIfClassIsRegistered()
Definition: DriverRegistryTest.php:93
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:22
‪TYPO3\CMS\Core\Tests\Unit\Resource\Driver\DriverRegistryTest\driverExistsReturnsFalseIfDriverDoesNotExist
‪driverExistsReturnsFalseIfDriverDoesNotExist()
Definition: DriverRegistryTest.php:136
‪TYPO3\CMS\Core\Resource\Driver\AbstractDriver
Definition: AbstractDriver.php:25