[TASK] Adapt DriverRegistryTest to the changed behaviour
[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 \Tx_Phpunit_TestCase {
38
39 /**
40 * @var boolean Enable backup of global and system variables
41 */
42 protected $backupGlobals = TRUE;
43
44 /**
45 * Exclude TYPO3_DB from backup/ restore of $GLOBALS
46 * because resource types cannot be handled during serializing
47 *
48 * @var array
49 */
50 protected $backupGlobalsBlacklist = array('TYPO3_DB');
51
52 /**
53 * @var \TYPO3\CMS\Core\Resource\Driver\DriverRegistry
54 */
55 private $fixture;
56
57 public function setUp() {
58 $this->initializeFixture();
59 }
60
61 protected function initializeFixture() {
62 $this->fixture = new \TYPO3\CMS\Core\Resource\Driver\DriverRegistry();
63 }
64
65 /**
66 * @test
67 */
68 public function registeredDriverClassesCanBeRetrieved() {
69 $className = $this->getMockClass('TYPO3\\CMS\\Core\\Resource\\Driver\\AbstractDriver');
70 $this->fixture->registerDriverClass($className, 'foobar');
71 $returnedClassName = $this->fixture->getDriverClass('foobar');
72 $this->assertEquals($className, $returnedClassName);
73 }
74
75 /**
76 * @test
77 */
78 public function registerDriverClassThrowsExceptionIfClassDoesNotExist() {
79 $this->setExpectedException('InvalidArgumentException', '', 1314979197);
80 $this->fixture->registerDriverClass(uniqid());
81 }
82
83 /**
84 * @test
85 */
86 public function registerDriverClassThrowsExceptionIfShortnameIsAlreadyTakenByAnotherDriverClass() {
87 $this->setExpectedException('InvalidArgumentException', '', 1314979451);
88 $className = $this->getMockClass('TYPO3\\CMS\\Core\\Resource\\Driver\\AbstractDriver');
89 $className2 = '\stdClass';
90 $this->fixture->registerDriverClass($className, 'foobar');
91 $this->fixture->registerDriverClass($className2, 'foobar');
92 }
93
94 /**
95 * @test
96 */
97 public function getDriverClassThrowsExceptionIfClassIsNotRegistered() {
98 $this->setExpectedException('InvalidArgumentException', '', 1314085990);
99 $this->fixture->getDriverClass(uniqid());
100 }
101
102 /**
103 * @test
104 */
105 public function getDriverClassAcceptsClassNameIfClassIsRegistered() {
106 $className = $this->getMockClass('TYPO3\\CMS\\Core\\Resource\\Driver\\AbstractDriver');
107 $this->fixture->registerDriverClass($className, 'foobar');
108 $this->assertEquals($className, $this->fixture->getDriverClass($className));
109 }
110
111 /**
112 * @test
113 */
114 public function driverRegistryIsInitializedWithPreconfiguredDrivers() {
115 $className = $this->getMockClass('TYPO3\\CMS\\Core\\Resource\\Driver\\AbstractDriver');
116 $shortName = uniqid();
117 $GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['registeredDrivers'] = array(
118 $shortName => array(
119 'class' => $className
120 )
121 );
122 $this->initializeFixture();
123 $this->assertEquals($className, $this->fixture->getDriverClass($shortName));
124 }
125
126 }
127
128 ?>