2 namespace TYPO3\CMS\Core\Tests\Unit\
Resource\Driver
;
4 /***************************************************************
7 * (c) 2011 Andreas Wolf <andreas.wolf@ikt-werk.de>
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.
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.
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.
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
31 * Testcase for the FAL driver registry.
33 * @author Andreas Wolf <andreas.wolf@ikt-werk.de>
37 class DriverRegistryTest
extends \TYPO3\CMS\Core\Tests\UnitTestCase
{
40 * @var boolean Enable backup of global and system variables
42 protected $backupGlobals = TRUE;
45 * @var \TYPO3\CMS\Core\Resource\Driver\DriverRegistry
49 public function setUp() {
50 $this->initializeFixture();
53 protected function initializeFixture() {
54 $this->fixture
= new \TYPO3\CMS\Core\
Resource\Driver\
DriverRegistry();
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);
70 public function registerDriverClassThrowsExceptionIfClassDoesNotExist() {
71 $this->setExpectedException('InvalidArgumentException', '', 1314979197);
72 $this->fixture
->registerDriverClass(uniqid());
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');
89 public function getDriverClassThrowsExceptionIfClassIsNotRegistered() {
90 $this->setExpectedException('InvalidArgumentException', '', 1314085990);
91 $this->fixture
->getDriverClass(uniqid());
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));
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(
111 'class' => $className
114 $this->initializeFixture();
115 $this->assertEquals($className, $this->fixture
->getDriverClass($shortName));
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(
126 'class' => $className
129 $this->initializeFixture();
130 $this->assertTrue($this->fixture
->driverExists($shortName));
131 $this->assertFalse($this->fixture
->driverExists(uniqid()));
137 public function driverExistsReturnsFalseIfDriverDoesNotExist() {
138 $GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['registeredDrivers'] = array(
140 $this->initializeFixture();
141 $this->assertFalse($this->fixture
->driverExists(uniqid()));