‪TYPO3CMS  9.5
DriverRegistryTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
5 
6 /*
7  * This file is part of the TYPO3 CMS project.
8  *
9  * It is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License, either version 2
11  * of the License, or any later version.
12  *
13  * For the full copyright and license information, please read the
14  * LICENSE.txt file that was distributed with this source code.
15  *
16  * The TYPO3 project - inspiring people to share!
17  */
18 
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23 
27 class ‪DriverRegistryTest extends UnitTestCase
28 {
32  protected ‪$subject;
33 
34  protected function ‪setUp()
35  {
36  $this->‪initializeSubject();
37  }
38 
39  protected function ‪initializeSubject(): void
40  {
41  $this->subject = new ‪DriverRegistry();
42  }
43 
47  public function ‪registeredDriverClassesCanBeRetrieved(): void
48  {
49  $className = get_class($this->getMockForAbstractClass(AbstractDriver::class));
50  $this->subject->registerDriverClass($className, 'foobar');
51  $returnedClassName = $this->subject->getDriverClass('foobar');
52  $this->assertEquals($className, $returnedClassName);
53  }
54 
59  {
60  $this->expectException(\InvalidArgumentException::class);
61  $this->expectExceptionCode(1314979197);
62  $this->subject->registerDriverClass($this->getUniqueId());
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($this->getUniqueId());
86  }
87 
92  {
93  $className = get_class($this->getMockForAbstractClass(AbstractDriver::class));
94  $this->subject->registerDriverClass($className, 'foobar');
95  $this->assertEquals($className, $this->subject->getDriverClass($className));
96  }
97 
102  {
103  $className = get_class($this->getMockForAbstractClass(AbstractDriver::class));
104  $shortName = $this->getUniqueId();
105  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['registeredDrivers'] = [
106  $shortName => [
107  'class' => $className
108  ]
109  ];
110  $this->‪initializeSubject();
111  $this->assertEquals($className, $this->subject->getDriverClass($shortName));
112  }
113 
118  {
119  $className = get_class($this->getMockForAbstractClass(AbstractDriver::class));
120  $shortName = $this->getUniqueId();
121  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['registeredDrivers'] = [
122  $shortName => [
123  'class' => $className
124  ]
125  ];
126  $this->‪initializeSubject();
127  $this->assertTrue($this->subject->driverExists($shortName));
128  $this->assertFalse($this->subject->driverExists($this->getUniqueId()));
129  }
130 
135  {
136  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['registeredDrivers'] = [];
137  $this->‪initializeSubject();
138  $this->assertFalse($this->subject->driverExists($this->getUniqueId()));
139  }
140 }
‪TYPO3\CMS\Core\Tests\Unit\Resource\Driver\DriverRegistryTest\driverExistsReturnsTrueForAllExistingDrivers
‪driverExistsReturnsTrueForAllExistingDrivers()
Definition: DriverRegistryTest.php:116
‪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:38
‪TYPO3\CMS\Core\Tests\Unit\Resource\Driver\DriverRegistryTest\driverRegistryIsInitializedWithPreconfiguredDrivers
‪driverRegistryIsInitializedWithPreconfiguredDrivers()
Definition: DriverRegistryTest.php:100
‪TYPO3\CMS\Core\Tests\Unit\Resource\Driver\DriverRegistryTest\registeredDriverClassesCanBeRetrieved
‪registeredDriverClassesCanBeRetrieved()
Definition: DriverRegistryTest.php:46
‪TYPO3\CMS\Core\Tests\Unit\Resource\Driver\DriverRegistryTest\registerDriverClassThrowsExceptionIfShortnameIsAlreadyTakenByAnotherDriverClass
‪registerDriverClassThrowsExceptionIfShortnameIsAlreadyTakenByAnotherDriverClass()
Definition: DriverRegistryTest.php:67
‪TYPO3\CMS\Core\Tests\Unit\Resource\Driver\DriverRegistryTest\getDriverClassThrowsExceptionIfClassIsNotRegistered
‪getDriverClassThrowsExceptionIfClassIsNotRegistered()
Definition: DriverRegistryTest.php:80
‪TYPO3\CMS\Core\Tests\Unit\Resource\Driver\DriverRegistryTest\setUp
‪setUp()
Definition: DriverRegistryTest.php:33
‪TYPO3\CMS\Core\Resource\Driver\DriverInterface
Definition: DriverInterface.php:22
‪TYPO3\CMS\Core\Tests\Unit\Resource\Driver
Definition: AbstractDriverTest.php:2
‪TYPO3\CMS\Core\Tests\Unit\Resource\Driver\DriverRegistryTest
Definition: DriverRegistryTest.php:28
‪TYPO3\CMS\Core\Resource\Driver\DriverRegistry
Definition: DriverRegistry.php:21
‪TYPO3\CMS\Core\Tests\Unit\Resource\Driver\DriverRegistryTest\registerDriverClassThrowsExceptionIfClassDoesNotExist
‪registerDriverClassThrowsExceptionIfClassDoesNotExist()
Definition: DriverRegistryTest.php:57
‪$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:90
‪TYPO3\CMS\Core\Tests\Unit\Resource\Driver\DriverRegistryTest\driverExistsReturnsFalseIfDriverDoesNotExist
‪driverExistsReturnsFalseIfDriverDoesNotExist()
Definition: DriverRegistryTest.php:133
‪TYPO3\CMS\Core\Resource\Driver\AbstractDriver
Definition: AbstractDriver.php:23