‪TYPO3CMS  9.5
InstallUtilityTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23 
27 class ‪InstallUtilityTest extends UnitTestCase
28 {
32  protected ‪$fakedExtensions = [];
33 
36  protected function ‪tearDown()
37  {
38  foreach ($this->fakedExtensions as $fakeExtkey => $fakeExtension) {
39  $this->testFilesToDelete[] = ‪Environment::getVarPath() . '/tests/' . $fakeExtkey;
40  }
41  parent::tearDown();
42  }
43 
50  protected function ‪createFakeExtension(): string
51  {
52  $extKey = strtolower($this->getUniqueId('testing'));
53  $absExtPath = ‪Environment::getVarPath() . '/tests/' . $extKey;
54  $relPath = 'typo3temp/var/tests/' . $extKey . '/';
55  GeneralUtility::mkdir($absExtPath);
56  $this->fakedExtensions[$extKey] = [
57  'siteRelPath' => $relPath,
58  ];
59 
60  return $extKey;
61  }
62 
67  {
68  $extKey = $this->‪createFakeExtension();
69  $extPath = ‪Environment::getVarPath() . '/tests/' . $extKey . '/';
70  $extTablesFile = $extPath . 'ext_tables.sql';
71  $fileContent = 'DUMMY TEXT TO COMPARE';
72  file_put_contents($extTablesFile, $fileContent);
73  $installMock = $this->getAccessibleMock(
74  InstallUtility::class,
75  ['updateDbWithExtTablesSql', 'importStaticSqlFile', 'importT3DFile'],
76  [],
77  '',
78  false
79  );
80  $dependencyUtility = $this->getMockBuilder(DependencyUtility::class)->getMock();
81  $installMock->_set('dependencyUtility', $dependencyUtility);
82 
83  $installMock->expects($this->once())->method('updateDbWithExtTablesSql')->with($this->stringStartsWith($fileContent));
84  $installMock->processDatabaseUpdates($this->fakedExtensions[$extKey]);
85  }
86 
91  {
92  $extKey = $this->‪createFakeExtension();
93  $extensionSiteRelPath = 'typo3temp/var/tests/' . $extKey . '/';
94  $installMock = $this->getAccessibleMock(
95  InstallUtility::class,
96  ['importStaticSqlFile', 'updateDbWithExtTablesSql', 'importT3DFile'],
97  [],
98  '',
99  false
100  );
101  $dependencyUtility = $this->getMockBuilder(DependencyUtility::class)->getMock();
102  $installMock->_set('dependencyUtility', $dependencyUtility);
103  $installMock->expects($this->once())->method('importStaticSqlFile')->with($extensionSiteRelPath);
104  $installMock->processDatabaseUpdates($this->fakedExtensions[$extKey]);
105  }
106 
111  {
112  return [
113  'T3D file' => [
114  'data.t3d',
115  ],
116  'XML file' => [
117  'data.xml',
118  ],
119  ];
120  }
121 
127  public function ‪processDatabaseUpdatesCallsImportFile($fileName)
128  {
129  $extKey = $this->‪createFakeExtension();
130  $absPath = ‪Environment::getPublicPath() . '/' . $this->fakedExtensions[$extKey]['siteRelPath'];
131  GeneralUtility::mkdir($absPath . '/Initialisation');
132  file_put_contents($absPath . '/Initialisation/' . $fileName, 'DUMMY');
133  $installMock = $this->getAccessibleMock(
134  InstallUtility::class,
135  ['updateDbWithExtTablesSql', 'importStaticSqlFile', 'importT3DFile'],
136  [],
137  '',
138  false
139  );
140  $dependencyUtility = $this->getMockBuilder(DependencyUtility::class)->getMock();
141  $installMock->_set('dependencyUtility', $dependencyUtility);
142  $installMock->expects($this->once())->method('importT3DFile')->with($this->fakedExtensions[$extKey]['siteRelPath']);
143  $installMock->processDatabaseUpdates($this->fakedExtensions[$extKey]);
144  }
145 }
‪TYPO3\CMS\Extensionmanager\Tests\UnitDeprecated\Utility
Definition: InstallUtilityTest.php:3
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static string getPublicPath()
Definition: Environment.php:153
‪TYPO3\CMS\Extensionmanager\Tests\UnitDeprecated\Utility\InstallUtilityTest\createFakeExtension
‪string createFakeExtension()
Definition: InstallUtilityTest.php:49
‪TYPO3\CMS\Extensionmanager\Tests\UnitDeprecated\Utility\InstallUtilityTest\processDatabaseUpdatesCallsImportFileDataProvider
‪array processDatabaseUpdatesCallsImportFileDataProvider()
Definition: InstallUtilityTest.php:109
‪TYPO3\CMS\Extensionmanager\Tests\UnitDeprecated\Utility\InstallUtilityTest\processDatabaseUpdatesCallsUpdateDbWithExtTablesSql
‪processDatabaseUpdatesCallsUpdateDbWithExtTablesSql()
Definition: InstallUtilityTest.php:65
‪TYPO3\CMS\Extensionmanager\Utility\InstallUtility
Definition: InstallUtility.php:32
‪TYPO3\CMS\Extensionmanager\Tests\UnitDeprecated\Utility\InstallUtilityTest\$fakedExtensions
‪array $fakedExtensions
Definition: InstallUtilityTest.php:31
‪TYPO3\CMS\Extensionmanager\Tests\UnitDeprecated\Utility\InstallUtilityTest\processDatabaseUpdatesCallsImportStaticSqlFile
‪processDatabaseUpdatesCallsImportStaticSqlFile()
Definition: InstallUtilityTest.php:89
‪TYPO3\CMS\Extensionmanager\Utility\DependencyUtility
Definition: DependencyUtility.php:28
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:39
‪TYPO3\CMS\Extensionmanager\Tests\UnitDeprecated\Utility\InstallUtilityTest\processDatabaseUpdatesCallsImportFile
‪processDatabaseUpdatesCallsImportFile($fileName)
Definition: InstallUtilityTest.php:126
‪TYPO3\CMS\Extensionmanager\Tests\UnitDeprecated\Utility\InstallUtilityTest
Definition: InstallUtilityTest.php:28
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Extensionmanager\Tests\UnitDeprecated\Utility\InstallUtilityTest\tearDown
‪tearDown()
Definition: InstallUtilityTest.php:35
‪TYPO3\CMS\Core\Core\Environment\getVarPath
‪static string getVarPath()
Definition: Environment.php:165