Skip to content

Commit

Permalink
[TASK] Make InstallUtilityTest notice free
Browse files Browse the repository at this point in the history
Releases: master
Resolves: #84384
Change-Id: Ia43a39337ccbeed748b1da857bc3e051fc7e7af5
Reviewed-on: https://review.typo3.org/56261
Reviewed-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
Tested-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
  • Loading branch information
janhelke authored and lolli42 committed Mar 16, 2018
1 parent c6a4e85 commit 2070243
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 33 deletions.
Expand Up @@ -177,7 +177,7 @@ public function processExtensionSetup($extensionKey)
{
$extension = $this->enrichExtensionWithDetails($extensionKey, false);
$this->ensureConfiguredDirectoriesExist($extension);
$this->importInitialFiles($extension['siteRelPath'], $extensionKey);
$this->importInitialFiles($extension['siteRelPath'] ?? '', $extensionKey);
$this->processDatabaseUpdates($extension);
$this->processRuntimeDatabaseUpdates($extensionKey);
}
Expand Down
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace TYPO3\CMS\Extensionmanager\Tests\Unit\Utility;

/*
Expand All @@ -14,16 +15,18 @@
* The TYPO3 project - inspiring people to share!
*/

use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Registry;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extensionmanager\Utility\DependencyUtility;
use TYPO3\CMS\Extensionmanager\Utility\InstallUtility;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;

/**
* Test case
*/
class InstallUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
class InstallUtilityTest extends UnitTestCase
{
/**
* Subject is not notice free, disable E_NOTICES
*/
protected static $suppressNotices = true;

/**
* @var string
*/
Expand All @@ -40,7 +43,7 @@ class InstallUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
protected $fakedExtensions = [];

/**
* @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Extensionmanager\Utility\InstallUtility|\TYPO3\TestingFramework\Core\AccessibleObjectInterface
* @var \PHPUnit_Framework_MockObject_MockObject|InstallUtility|\TYPO3\TestingFramework\Core\AccessibleObjectInterface
*/
protected $installMock;

Expand All @@ -53,7 +56,7 @@ protected function setUp()
'key' => $this->extensionKey
];
$this->installMock = $this->getAccessibleMock(
\TYPO3\CMS\Extensionmanager\Utility\InstallUtility::class,
InstallUtility::class,
[
'isLoaded',
'loadExtension',
Expand All @@ -73,7 +76,7 @@ protected function setUp()
'',
false
);
$dependencyUtility = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Utility\DependencyUtility::class)->getMock();
$dependencyUtility = $this->getMockBuilder(DependencyUtility::class)->getMock();
$this->installMock->_set('dependencyUtility', $dependencyUtility);
$this->installMock->expects($this->any())
->method('getExtensionArray')
Expand All @@ -88,7 +91,7 @@ protected function setUp()
/**
* @return array
*/
public function getExtensionData()
public function getExtensionData(): array
{
return $this->extensionData;
}
Expand All @@ -109,12 +112,12 @@ protected function tearDown()
*
* @return string The extension key
*/
protected function createFakeExtension()
protected function createFakeExtension(): string
{
$extKey = strtolower($this->getUniqueId('testing'));
$absExtPath = PATH_site . 'typo3temp/var/tests/' . $extKey;
$relPath = 'typo3temp/var/tests/' . $extKey . '/';
\TYPO3\CMS\Core\Utility\GeneralUtility::mkdir($absExtPath);
GeneralUtility::mkdir($absExtPath);
$this->fakedExtensions[$extKey] = [
'siteRelPath' => $relPath
];
Expand All @@ -130,7 +133,7 @@ public function installCallsProcessRuntimeDatabaseUpdates()
->method('processRuntimeDatabaseUpdates')
->with($this->extensionKey);

$cacheManagerMock = $this->getMockBuilder(\TYPO3\CMS\Core\Cache\CacheManager::class)->getMock();
$cacheManagerMock = $this->getMockBuilder(CacheManager::class)->getMock();
$cacheManagerMock->expects($this->once())->method('flushCachesInGroup');
$this->installMock->_set('cacheManager', $cacheManagerMock);
$this->installMock->install($this->extensionKey);
Expand All @@ -141,7 +144,7 @@ public function installCallsProcessRuntimeDatabaseUpdates()
*/
public function installCallsLoadExtension()
{
$cacheManagerMock = $this->getMockBuilder(\TYPO3\CMS\Core\Cache\CacheManager::class)->getMock();
$cacheManagerMock = $this->getMockBuilder(CacheManager::class)->getMock();
$cacheManagerMock->expects($this->once())->method('flushCachesInGroup');
$this->installMock->_set('cacheManager', $cacheManagerMock);
$this->installMock->expects($this->once())->method('loadExtension');
Expand All @@ -154,7 +157,7 @@ public function installCallsLoadExtension()
public function installCallsFlushCachesIfClearCacheOnLoadIsSet()
{
$this->extensionData['clearcacheonload'] = true;
$cacheManagerMock = $this->getMockBuilder(\TYPO3\CMS\Core\Cache\CacheManager::class)->getMock();
$cacheManagerMock = $this->getMockBuilder(CacheManager::class)->getMock();
$cacheManagerMock->expects($this->once())->method('flushCaches');
$this->installMock->_set('cacheManager', $cacheManagerMock);
$this->installMock->install($this->extensionKey);
Expand All @@ -166,7 +169,7 @@ public function installCallsFlushCachesIfClearCacheOnLoadIsSet()
public function installCallsFlushCachesIfClearCacheOnLoadCamelCasedIsSet()
{
$this->extensionData['clearCacheOnLoad'] = true;
$cacheManagerMock = $this->getMockBuilder(\TYPO3\CMS\Core\Cache\CacheManager::class)->getMock();
$cacheManagerMock = $this->getMockBuilder(CacheManager::class)->getMock();
$cacheManagerMock->expects($this->once())->method('flushCaches');
$this->installMock->_set('cacheManager', $cacheManagerMock);
$this->installMock->install($this->extensionKey);
Expand All @@ -177,7 +180,7 @@ public function installCallsFlushCachesIfClearCacheOnLoadCamelCasedIsSet()
*/
public function installationOfAnExtensionWillCallEnsureThatDirectoriesExist()
{
$cacheManagerMock = $this->getMockBuilder(\TYPO3\CMS\Core\Cache\CacheManager::class)->getMock();
$cacheManagerMock = $this->getMockBuilder(CacheManager::class)->getMock();
$cacheManagerMock->expects($this->once())->method('flushCachesInGroup');
$this->installMock->_set('cacheManager', $cacheManagerMock);
$this->installMock->expects($this->once())->method('ensureConfiguredDirectoriesExist');
Expand All @@ -189,7 +192,7 @@ public function installationOfAnExtensionWillCallEnsureThatDirectoriesExist()
*/
public function installCallsReloadCaches()
{
$cacheManagerMock = $this->getMockBuilder(\TYPO3\CMS\Core\Cache\CacheManager::class)->getMock();
$cacheManagerMock = $this->getMockBuilder(CacheManager::class)->getMock();
$cacheManagerMock->expects($this->once())->method('flushCachesInGroup');
$this->installMock->_set('cacheManager', $cacheManagerMock);
$this->installMock->expects($this->once())->method('reloadCaches');
Expand All @@ -201,7 +204,7 @@ public function installCallsReloadCaches()
*/
public function installCallsSaveDefaultConfigurationWithExtensionKey()
{
$cacheManagerMock = $this->getMockBuilder(\TYPO3\CMS\Core\Cache\CacheManager::class)->getMock();
$cacheManagerMock = $this->getMockBuilder(CacheManager::class)->getMock();
$cacheManagerMock->expects($this->once())->method('flushCachesInGroup');
$this->installMock->_set('cacheManager', $cacheManagerMock);
$this->installMock->expects($this->once())->method('saveDefaultConfiguration')->with('dummy');
Expand All @@ -228,13 +231,13 @@ public function processDatabaseUpdatesCallsUpdateDbWithExtTablesSql()
$fileContent = 'DUMMY TEXT TO COMPARE';
file_put_contents($extTablesFile, $fileContent);
$installMock = $this->getAccessibleMock(
\TYPO3\CMS\Extensionmanager\Utility\InstallUtility::class,
InstallUtility::class,
['updateDbWithExtTablesSql', 'importStaticSqlFile', 'importT3DFile'],
[],
'',
false
);
$dependencyUtility = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Utility\DependencyUtility::class)->getMock();
$dependencyUtility = $this->getMockBuilder(DependencyUtility::class)->getMock();
$installMock->_set('dependencyUtility', $dependencyUtility);

$installMock->expects($this->once())->method('updateDbWithExtTablesSql')->with($this->stringStartsWith($fileContent));
Expand All @@ -249,13 +252,13 @@ public function processDatabaseUpdatesCallsImportStaticSqlFile()
$extKey = $this->createFakeExtension();
$extensionSiteRelPath = 'typo3temp/var/tests/' . $extKey . '/';
$installMock = $this->getAccessibleMock(
\TYPO3\CMS\Extensionmanager\Utility\InstallUtility::class,
InstallUtility::class,
['importStaticSqlFile', 'updateDbWithExtTablesSql', 'importT3DFile'],
[],
'',
false
);
$dependencyUtility = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Utility\DependencyUtility::class)->getMock();
$dependencyUtility = $this->getMockBuilder(DependencyUtility::class)->getMock();
$installMock->_set('dependencyUtility', $dependencyUtility);
$installMock->expects($this->once())->method('importStaticSqlFile')->with($extensionSiteRelPath);
$installMock->processDatabaseUpdates($this->fakedExtensions[$extKey]);
Expand All @@ -264,7 +267,7 @@ public function processDatabaseUpdatesCallsImportStaticSqlFile()
/**
* @return array
*/
public function processDatabaseUpdatesCallsImportFileDataProvider()
public function processDatabaseUpdatesCallsImportFileDataProvider(): array
{
return [
'T3D file' => [
Expand All @@ -285,16 +288,16 @@ public function processDatabaseUpdatesCallsImportFile($fileName)
{
$extKey = $this->createFakeExtension();
$absPath = PATH_site . $this->fakedExtensions[$extKey]['siteRelPath'];
\TYPO3\CMS\Core\Utility\GeneralUtility::mkdir($absPath . '/Initialisation');
GeneralUtility::mkdir($absPath . '/Initialisation');
file_put_contents($absPath . '/Initialisation/' . $fileName, 'DUMMY');
$installMock = $this->getAccessibleMock(
\TYPO3\CMS\Extensionmanager\Utility\InstallUtility::class,
InstallUtility::class,
['updateDbWithExtTablesSql', 'importStaticSqlFile', 'importT3DFile'],
[],
'',
false
);
$dependencyUtility = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Utility\DependencyUtility::class)->getMock();
$dependencyUtility = $this->getMockBuilder(DependencyUtility::class)->getMock();
$installMock->_set('dependencyUtility', $dependencyUtility);
$installMock->expects($this->once())->method('importT3DFile')->with($this->fakedExtensions[$extKey]['siteRelPath']);
$installMock->processDatabaseUpdates($this->fakedExtensions[$extKey]);
Expand All @@ -303,7 +306,7 @@ public function processDatabaseUpdatesCallsImportFile($fileName)
/**
* @return array
*/
public function importT3DFileDoesNotImportFileIfAlreadyImportedDataProvider()
public function importT3DFileDoesNotImportFileIfAlreadyImportedDataProvider(): array
{
return [
'Import T3D file when T3D was imported before extension to XML' => [
Expand Down Expand Up @@ -340,9 +343,9 @@ public function importT3DFileDoesNotImportFileIfAlreadyImported($fileName, $regi
{
$extKey = $this->createFakeExtension();
$absPath = PATH_site . $this->fakedExtensions[$extKey]['siteRelPath'];
\TYPO3\CMS\Core\Utility\GeneralUtility::mkdir($absPath . 'Initialisation');
GeneralUtility::mkdir($absPath . 'Initialisation');
file_put_contents($absPath . 'Initialisation/' . $fileName, 'DUMMY');
$registryMock = $this->getMockBuilder(\TYPO3\CMS\Core\Registry::class)
$registryMock = $this->getMockBuilder(Registry::class)
->setMethods(['get', 'set'])
->getMock();
$registryMock
Expand All @@ -355,13 +358,13 @@ public function importT3DFileDoesNotImportFileIfAlreadyImported($fileName, $regi
]
));
$installMock = $this->getAccessibleMock(
\TYPO3\CMS\Extensionmanager\Utility\InstallUtility::class,
InstallUtility::class,
['getRegistry', 'getImportExportUtility'],
[],
'',
false
);
$dependencyUtility = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Utility\DependencyUtility::class)->getMock();
$dependencyUtility = $this->getMockBuilder(DependencyUtility::class)->getMock();
$installMock->_set('dependencyUtility', $dependencyUtility);
$installMock->_set('registry', $registryMock);
$installMock->expects($this->never())->method('getImportExportUtility');
Expand Down

0 comments on commit 2070243

Please sign in to comment.