[TASK] Re-work/simplify copyright header in PHP files - Part 4
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Resource / Driver / DriverRegistryTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Resource\Driver;
3
4 /**
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * Testcase for the FAL driver registry.
19 *
20 * @author Andreas Wolf <andreas.wolf@ikt-werk.de>
21 */
22 class DriverRegistryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
23
24 /**
25 * @var \TYPO3\CMS\Core\Resource\Driver\DriverRegistry
26 */
27 protected $fixture;
28
29 public function setUp() {
30 $this->initializeFixture();
31 }
32
33 protected function initializeFixture() {
34 $this->fixture = new \TYPO3\CMS\Core\Resource\Driver\DriverRegistry();
35 }
36
37 /**
38 * @test
39 */
40 public function registeredDriverClassesCanBeRetrieved() {
41 $className = get_class($this->getMockForAbstractClass('TYPO3\\CMS\\Core\\Resource\\Driver\\AbstractDriver'));
42 $this->fixture->registerDriverClass($className, 'foobar');
43 $returnedClassName = $this->fixture->getDriverClass('foobar');
44 $this->assertEquals($className, $returnedClassName);
45 }
46
47 /**
48 * @test
49 */
50 public function registerDriverClassThrowsExceptionIfClassDoesNotExist() {
51 $this->setExpectedException('InvalidArgumentException', '', 1314979197);
52 $this->fixture->registerDriverClass(uniqid());
53 }
54
55 /**
56 * @test
57 */
58 public function registerDriverClassThrowsExceptionIfShortnameIsAlreadyTakenByAnotherDriverClass() {
59 $this->setExpectedException('InvalidArgumentException', '', 1314979451);
60 $className = get_class($this->getMockForAbstractClass('TYPO3\\CMS\\Core\\Resource\\Driver\\AbstractDriver'));
61 $className2 = get_class($this->getMockForAbstractClass('TYPO3\\CMS\\Core\\Resource\\Driver\\DriverInterface'));
62 $this->fixture->registerDriverClass($className, 'foobar');
63 $this->fixture->registerDriverClass($className2, 'foobar');
64 }
65
66 /**
67 * @test
68 */
69 public function getDriverClassThrowsExceptionIfClassIsNotRegistered() {
70 $this->setExpectedException('InvalidArgumentException', '', 1314085990);
71 $this->fixture->getDriverClass(uniqid());
72 }
73
74 /**
75 * @test
76 */
77 public function getDriverClassAcceptsClassNameIfClassIsRegistered() {
78 $className = get_class($this->getMockForAbstractClass('TYPO3\\CMS\\Core\\Resource\\Driver\\AbstractDriver'));
79 $this->fixture->registerDriverClass($className, 'foobar');
80 $this->assertEquals($className, $this->fixture->getDriverClass($className));
81 }
82
83 /**
84 * @test
85 */
86 public function driverRegistryIsInitializedWithPreconfiguredDrivers() {
87 $className = get_class($this->getMockForAbstractClass('TYPO3\\CMS\\Core\\Resource\\Driver\\AbstractDriver'));
88 $shortName = uniqid();
89 $GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['registeredDrivers'] = array(
90 $shortName => array(
91 'class' => $className
92 )
93 );
94 $this->initializeFixture();
95 $this->assertEquals($className, $this->fixture->getDriverClass($shortName));
96 }
97
98 /**
99 * @test
100 */
101 public function driverExistsReturnsTrueForAllExistingDrivers() {
102 $className = get_class($this->getMockForAbstractClass('TYPO3\\CMS\\Core\\Resource\\Driver\\AbstractDriver'));
103 $shortName = uniqid();
104 $GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['registeredDrivers'] = array(
105 $shortName => array(
106 'class' => $className
107 )
108 );
109 $this->initializeFixture();
110 $this->assertTrue($this->fixture->driverExists($shortName));
111 $this->assertFalse($this->fixture->driverExists(uniqid()));
112 }
113
114 /**
115 * @test
116 */
117 public function driverExistsReturnsFalseIfDriverDoesNotExist() {
118 $GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['registeredDrivers'] = array(
119 );
120 $this->initializeFixture();
121 $this->assertFalse($this->fixture->driverExists(uniqid()));
122 }
123
124 }