[BUGFIX] LocalDriver can be instantiated without basePath
[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 * Copyright notice
6 *
7 * (c) 2011 Andreas Wolf <andreas.wolf@ikt-werk.de>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 /**
31 * Testcase for the FAL driver registry.
32 *
33 * @author Andreas Wolf <andreas.wolf@ikt-werk.de>
34 * @package TYPO3
35 * @subpackage t3lib
36 */
37 class DriverRegistryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
38
39 /**
40 * @var boolean Enable backup of global and system variables
41 */
42 protected $backupGlobals = TRUE;
43
44 /**
45 * @var \TYPO3\CMS\Core\Resource\Driver\DriverRegistry
46 */
47 private $fixture;
48
49 public function setUp() {
50 $this->initializeFixture();
51 }
52
53 protected function initializeFixture() {
54 $this->fixture = new \TYPO3\CMS\Core\Resource\Driver\DriverRegistry();
55 }
56
57 /**
58 * @test
59 */
60 public function registeredDriverClassesCanBeRetrieved() {
61 $className = $this->getMockClass('TYPO3\\CMS\\Core\\Resource\\Driver\\AbstractDriver');
62 $this->fixture->registerDriverClass($className, 'foobar');
63 $returnedClassName = $this->fixture->getDriverClass('foobar');
64 $this->assertEquals($className, $returnedClassName);
65 }
66
67 /**
68 * @test
69 */
70 public function registerDriverClassThrowsExceptionIfClassDoesNotExist() {
71 $this->setExpectedException('InvalidArgumentException', '', 1314979197);
72 $this->fixture->registerDriverClass(uniqid());
73 }
74
75 /**
76 * @test
77 */
78 public function registerDriverClassThrowsExceptionIfShortnameIsAlreadyTakenByAnotherDriverClass() {
79 $this->setExpectedException('InvalidArgumentException', '', 1314979451);
80 $className = $this->getMockClass('TYPO3\\CMS\\Core\\Resource\\Driver\\AbstractDriver');
81 $className2 = '\stdClass';
82 $this->fixture->registerDriverClass($className, 'foobar');
83 $this->fixture->registerDriverClass($className2, 'foobar');
84 }
85
86 /**
87 * @test
88 */
89 public function getDriverClassThrowsExceptionIfClassIsNotRegistered() {
90 $this->setExpectedException('InvalidArgumentException', '', 1314085990);
91 $this->fixture->getDriverClass(uniqid());
92 }
93
94 /**
95 * @test
96 */
97 public function getDriverClassAcceptsClassNameIfClassIsRegistered() {
98 $className = $this->getMockClass('TYPO3\\CMS\\Core\\Resource\\Driver\\AbstractDriver');
99 $this->fixture->registerDriverClass($className, 'foobar');
100 $this->assertEquals($className, $this->fixture->getDriverClass($className));
101 }
102
103 /**
104 * @test
105 */
106 public function driverRegistryIsInitializedWithPreconfiguredDrivers() {
107 $className = $this->getMockClass('TYPO3\\CMS\\Core\\Resource\\Driver\\AbstractDriver');
108 $shortName = uniqid();
109 $GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['registeredDrivers'] = array(
110 $shortName => array(
111 'class' => $className
112 )
113 );
114 $this->initializeFixture();
115 $this->assertEquals($className, $this->fixture->getDriverClass($shortName));
116 }
117
118 /**
119 * @test
120 */
121 public function driverExistsReturnsTrueForAllExistingDrivers() {
122 $className = $this->getMockClass('TYPO3\\CMS\\Core\\Resource\\Driver\\AbstractDriver');
123 $shortName = uniqid();
124 $GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['registeredDrivers'] = array(
125 $shortName => array(
126 'class' => $className
127 )
128 );
129 $this->initializeFixture();
130 $this->assertTrue($this->fixture->driverExists($shortName));
131 $this->assertFalse($this->fixture->driverExists(uniqid()));
132 }
133
134 /**
135 * @test
136 */
137 public function driverExistsReturnsFalseIfDriverDoesNotExist() {
138 $GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['registeredDrivers'] = array(
139 );
140 $this->initializeFixture();
141 $this->assertFalse($this->fixture->driverExists(uniqid()));
142 }
143
144 }
145
146 ?>