c7e4240a94e06070f3dace0eadb03cacb8e529bc
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Resource / FactoryTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Resource;
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 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 require_once 'vfsStream/vfsStream.php';
28
29 /**
30 * Testcase for the factory of FAL
31 *
32 * @author Andreas Wolf <andreas.wolf@ikt-werk.de>
33 */
34 class FactoryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
35
36 /**
37 * @var array A backup of registered singleton instances
38 */
39 protected $singletonInstances = array();
40
41 /**
42 * @var \TYPO3\CMS\Core\Resource\ResourceFactory
43 */
44 private $fixture;
45
46 /**
47 * @var boolean
48 */
49 private $objectCreated = FALSE;
50
51 public function setUp() {
52 $this->singletonInstances = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
53 $this->fixture = new \TYPO3\CMS\Core\Resource\ResourceFactory();
54 }
55
56 protected function tearDown() {
57 \TYPO3\CMS\Core\Utility\GeneralUtility::resetSingletonInstances($this->singletonInstances);
58 }
59
60 /**********************************
61 * Storage Collections
62 **********************************/
63 /**
64 * @test
65 */
66 public function createStorageCollectionObjectCreatesCollectionWithCorrectArguments() {
67 $mockedMount = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
68 $path = uniqid();
69 $name = uniqid();
70 $storageCollection = $this->fixture->createFolderObject($mockedMount, $path, $name, 0);
71 $this->assertSame($mockedMount, $storageCollection->getStorage());
72 $this->assertEquals($path . '/', $storageCollection->getIdentifier());
73 $this->assertEquals($name, $storageCollection->getName());
74 }
75
76 /**********************************
77 * Drivers
78 **********************************/
79 /**
80 * @test
81 */
82 public function getDriverObjectAcceptsDriverClassName() {
83 $mockedDriver = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Driver\\AbstractDriver', array(), array(), '', FALSE);
84 $driverFixtureClass = get_class($mockedDriver);
85 \TYPO3\CMS\Core\Utility\GeneralUtility::addInstance($driverFixtureClass, $mockedDriver);
86 $mockedMount = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
87 $mockedRegistry = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Driver\\DriverRegistry');
88 $mockedRegistry->expects($this->once())->method('getDriverClass')->with($this->equalTo($driverFixtureClass))->will($this->returnValue($driverFixtureClass));
89 \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Resource\\Driver\\DriverRegistry', $mockedRegistry);
90 $obj = $this->fixture->getDriverObject($driverFixtureClass, array());
91 $this->assertInstanceOf('TYPO3\\CMS\\Core\\Resource\\Driver\\AbstractDriver', $obj);
92 }
93
94 }
95
96 ?>