[TASK] Extension Manager: Remove superfluous tests
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Tests / Unit / Utility / InstallUtilityTest.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Tests\Unit\Utility;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2012 Susanne Moog, <susanne.moog@typo3.org>
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 * Testcase for the Tx_Extensionmanager_Utility_List class in the TYPO3 Core.
28 *
29 * @package Extension Manager
30 * @subpackage Tests
31 */
32 class InstallUtilityTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
33
34 public $extListGlobal;
35
36 public $loadedExtGlobal;
37
38 public $extension;
39
40 public $fakedExtensions;
41
42 /**
43 * @var \TYPO3\CMS\Extensionmanager\Utility\InstallUtility
44 */
45 public $installMock;
46
47 protected $listUtilityMock;
48
49 /**
50 * @return void
51 */
52 public function setUp() {
53 $this->extension = 'dummy';
54 $this->installMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility', array(
55 'loadExtension',
56 'unloadExtension',
57 'processDatabaseUpdates',
58 'reloadCaches',
59 'saveDefaultConfiguration',
60 'enrichExtensionWithDetails'
61 ));
62 }
63
64 /**
65 * @return void
66 */
67 public function tearDown() {
68 foreach ($this->fakedExtensions as $extension => $dummy) {
69 \TYPO3\CMS\Core\Utility\GeneralUtility::rmdir((PATH_site . 'typo3temp/') . $extension, TRUE);
70 }
71 }
72
73 /**
74 * Creates a fake extension inside typo3temp/. No configuration is created,
75 * just the folder
76 *
77 * @return string The extension key
78 */
79 protected function createFakeExtension() {
80 $extKey = strtolower(uniqid('testing'));
81 $absExtPath = ((PATH_site . 'typo3temp/') . $extKey) . '/';
82 $relPath = ('typo3temp/' . $extKey) . '/';
83 \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir($absExtPath);
84 $this->fakedExtensions[$extKey] = array(
85 'siteRelPath' => $relPath
86 );
87 return $extKey;
88 }
89
90 /**
91 * @test
92 * @return void
93 */
94 public function installCallsProcessDatabaseUpdates() {
95 $this->installMock->expects($this->once())->method('enrichExtensionWithDetails')->with($this->extension)->will($this->returnValue(array('key' => $this->extension)));
96 $this->installMock->expects($this->once())->method('processDatabaseUpdates')->with(array('key' => $this->extension));
97 $this->installMock->install($this->extension);
98 }
99
100 /**
101 * @test
102 * @return void
103 */
104 public function installCallsLoadExtenion() {
105 $this->installMock->expects($this->once())->method('enrichExtensionWithDetails')->with($this->extension)->will($this->returnValue(array('key' => $this->extension)));
106 $this->installMock->expects($this->once())->method('loadExtension');
107 $this->installMock->install($this->extension);
108 }
109
110 /**
111 * @test
112 * @return void
113 */
114 public function installCallsFlushCachesIfClearCacheOnLoadIsSet() {
115 $this->installMock->expects($this->once())->method('enrichExtensionWithDetails')->with($this->extension)->will($this->returnValue(array('key' => $this->extension, 'clearcacheonload' => TRUE)));
116 $backupCacheManager = $GLOBALS['typo3CacheManager'];
117 $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager');
118 $GLOBALS['typo3CacheManager']->expects($this->once())->method('flushCaches');
119 $this->installMock->install($this->extension);
120 $GLOBALS['typo3CacheManager'] = $backupCacheManager;
121 }
122
123 /**
124 * @test
125 * @return void
126 */
127 public function installCallsReloadCaches() {
128 $this->installMock->expects($this->once())->method('enrichExtensionWithDetails')->with($this->extension)->will($this->returnValue(array('key' => $this->extension)));
129 $this->installMock->expects($this->once())->method('reloadCaches');
130 $this->installMock->install('dummy');
131 }
132
133 /**
134 * @test
135 * @return void
136 */
137 public function installCallsSaveDefaultConfigurationWithExtensionKey() {
138 $this->installMock->expects($this->once())->method('enrichExtensionWithDetails')->with($this->extension)->will($this->returnValue(array('key' => $this->extension)));
139 $this->installMock->expects($this->once())->method('saveDefaultConfiguration')->with('dummy');
140 $this->installMock->install('dummy');
141 }
142
143 /**
144 * @test
145 * @return void
146 */
147 public function uninstallCallsUnloadExtension() {
148 $this->installMock->expects($this->once())->method('unloadExtension');
149 $this->installMock->uninstall('dummy');
150 }
151
152 /**
153 * @test
154 * @return void
155 */
156 public function processDatabaseUpdatesCallsUpdateDbWithExtTablesSql() {
157 $extKey = $this->createFakeExtension();
158 $extPath = ((PATH_site . 'typo3temp/') . $extKey) . '/';
159 $extTablesFile = $extPath . 'ext_tables.sql';
160 $fileContent = 'DUMMY TEXT TO COMPARE';
161 file_put_contents($extTablesFile, $fileContent);
162 $installMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility', array('updateDbWithExtTablesSql'));
163 $installMock->expects($this->once())->method('updateDbWithExtTablesSql')->with($this->stringStartsWith($fileContent));
164 $installMock->processDatabaseUpdates($this->fakedExtensions[$extKey]);
165 }
166
167 /**
168 * @test
169 * @return void
170 */
171 public function processDatabaseUpdatesCallsUpdateDbWithExtTablesSqlIncludingCachingFrameworkTables() {
172 $extKey = $this->createFakeExtension();
173 $extPath = ((PATH_site . 'typo3temp/') . $extKey) . '/';
174 $extTablesFile = $extPath . 'ext_tables.sql';
175 $fileContent = 'DUMMY TEXT TO COMPARE';
176 file_put_contents($extTablesFile, $fileContent);
177 $installMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility', array('updateDbWithExtTablesSql'));
178 $installMock->expects($this->once())->method('updateDbWithExtTablesSql')->with($this->stringContains('CREATE TABLE cf_cache_hash'));
179 $installMock->processDatabaseUpdates($this->fakedExtensions[$extKey]);
180 }
181
182 /**
183 * @test
184 * @return void
185 */
186 public function processDatabaseUpdatesCallsImportStaticSql() {
187 $extKey = $this->createFakeExtension();
188 $extPath = ((PATH_site . 'typo3temp/') . $extKey) . '/';
189 $extTablesFile = $extPath . 'ext_tables_static+adt.sql';
190 $fileContent = 'DUMMY TEXT TO COMPARE';
191 file_put_contents($extTablesFile, $fileContent);
192 $installMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility', array('importStaticSql'));
193 $installMock->expects($this->once())->method('importStaticSql')->with($fileContent);
194 $installMock->processDatabaseUpdates($this->fakedExtensions[$extKey]);
195 }
196
197 }
198
199
200 ?>