Commit 945c43f2 authored by Jan Helke's avatar Jan Helke Committed by Wouter Wolters
Browse files

[TASK] Make sysext/core/Tests/Unit/Resource/ notice free

Releases: master
Resolves: #85270
Change-Id: I31794c8e5ac90cce3c93bca8a8c0b502ada42c24
Reviewed-on: https://review.typo3.org/57228


Tested-by: default avatarTYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Wouter Wolters's avatarWouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters's avatarWouter Wolters <typo3@wouterwolters.nl>
parent d525bcb0
......@@ -422,7 +422,7 @@ abstract class AbstractFile implements FileInterface
*/
public function getCombinedIdentifier()
{
if (is_array($this->properties) && MathUtility::canBeInterpretedAsInteger($this->properties['storage'])) {
if (!empty($this->properties['storage']) && MathUtility::canBeInterpretedAsInteger($this->properties['storage'])) {
$combinedIdentifier = $this->properties['storage'] . ':' . $this->getIdentifier();
} else {
$combinedIdentifier = $this->getStorage()->getUid() . ':' . $this->getIdentifier();
......
......@@ -36,8 +36,8 @@ class DriverRegistry implements \TYPO3\CMS\Core\SingletonInterface
{
$driverConfigurations = $GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['registeredDrivers'];
foreach ($driverConfigurations as $shortName => $driverConfig) {
$shortName = $shortName ?: $driverConfig['shortName'];
$this->registerDriverClass($driverConfig['class'], $shortName, $driverConfig['label'] ?? null, $driverConfig['flexFormDS'] ?? null);
$shortName = $shortName ?: $driverConfig['shortName'] ?? '';
$this->registerDriverClass($driverConfig['class'] ?? '', $shortName, $driverConfig['label'] ?? '', $driverConfig['flexFormDS'] ?? '');
}
}
......
......@@ -139,6 +139,7 @@ class LocalDriver extends AbstractHierarchicalFilesystemDriver
* @throws Exception\InvalidConfigurationException
* @param array $configuration
* @return string
* @throws Exception\InvalidPathException
*/
protected function calculateBasePath(array $configuration)
{
......
......@@ -210,7 +210,7 @@ class File extends AbstractFile
$this->name = $properties['name'];
}
if ($this->properties['uid'] != 0 && isset($properties['uid'])) {
if (isset($properties['uid']) && $this->properties['uid'] != 0) {
unset($properties['uid']);
}
foreach ($properties as $key => $value) {
......
......@@ -171,14 +171,14 @@ class ResourceStorage implements ResourceStorageInterface
public function __construct(Driver\DriverInterface $driver, array $storageRecord)
{
$this->storageRecord = $storageRecord;
$this->configuration = $this->getResourceFactoryInstance()->convertFlexFormDataToConfigurationArray($storageRecord['configuration']);
$this->configuration = $this->getResourceFactoryInstance()->convertFlexFormDataToConfigurationArray($storageRecord['configuration'] ?? '');
$this->capabilities =
($this->storageRecord['is_browsable'] ? self::CAPABILITY_BROWSABLE : 0) |
($this->storageRecord['is_public'] ? self::CAPABILITY_PUBLIC : 0) |
($this->storageRecord['is_writable'] ? self::CAPABILITY_WRITABLE : 0);
($this->storageRecord['is_browsable'] ?? null ? self::CAPABILITY_BROWSABLE : 0) |
($this->storageRecord['is_public'] ?? null ? self::CAPABILITY_PUBLIC : 0) |
($this->storageRecord['is_writable'] ?? null ? self::CAPABILITY_WRITABLE : 0);
$this->driver = $driver;
$this->driver->setStorageUid($storageRecord['uid']);
$this->driver->setStorageUid($storageRecord['uid'] ?? null);
$this->driver->mergeConfigurationCapabilities($this->capabilities);
try {
$this->driver->processConfiguration();
......@@ -272,7 +272,7 @@ class ResourceStorage implements ResourceStorageInterface
*/
public function getUid()
{
return (int)$this->storageRecord['uid'];
return (int)($this->storageRecord['uid'] ?? 0);
}
/**
......
......@@ -1488,18 +1488,18 @@ class GeneralUtility
$tagName = $k;
// Construct the tag name.
// Use tag based on grand-parent + parent tag name
if (isset($options['grandParentTagMap'][$stackData['grandParentTagName'] . '/' . $stackData['parentTagName']])) {
if (isset($stackData['grandParentTagName'], $stackData['parentTagName'], $options['grandParentTagMap'][$stackData['grandParentTagName'] . '/' . $stackData['parentTagName']])) {
$attr .= ' index="' . htmlspecialchars($tagName) . '"';
$tagName = (string)$options['grandParentTagMap'][$stackData['grandParentTagName'] . '/' . $stackData['parentTagName']];
} elseif (isset($options['parentTagMap'][$stackData['parentTagName'] . ':_IS_NUM']) && MathUtility::canBeInterpretedAsInteger($tagName)) {
} elseif (isset($stackData['parentTagName'], $options['parentTagMap'][$stackData['parentTagName'] . ':_IS_NUM']) && MathUtility::canBeInterpretedAsInteger($tagName)) {
// Use tag based on parent tag name + if current tag is numeric
$attr .= ' index="' . htmlspecialchars($tagName) . '"';
$tagName = (string)$options['parentTagMap'][$stackData['parentTagName'] . ':_IS_NUM'];
} elseif (isset($options['parentTagMap'][$stackData['parentTagName'] . ':' . $tagName])) {
} elseif (isset($stackData['parentTagName'], $options['parentTagMap'][$stackData['parentTagName'] . ':' . $tagName])) {
// Use tag based on parent tag name + current tag
$attr .= ' index="' . htmlspecialchars($tagName) . '"';
$tagName = (string)$options['parentTagMap'][$stackData['parentTagName'] . ':' . $tagName];
} elseif (isset($options['parentTagMap'][$stackData['parentTagName']])) {
} elseif (isset($stackData['parentTagName'], $options['parentTagMap'][$stackData['parentTagName']])) {
// Use tag based on parent tag name:
$attr .= ' index="' . htmlspecialchars($tagName) . '"';
$tagName = (string)$options['parentTagMap'][$stackData['parentTagName']];
......@@ -1513,7 +1513,7 @@ class GeneralUtility
$attr .= ' index="' . $tagName . '"';
$tagName = $options['useIndexTagForNum'] ?: 'numIndex';
}
} elseif ($options['useIndexTagForAssoc']) {
} elseif (!empty($options['useIndexTagForAssoc'])) {
// Use tag for all associative keys:
$attr .= ' index="' . htmlspecialchars($tagName) . '"';
$tagName = $options['useIndexTagForAssoc'];
......@@ -1523,7 +1523,7 @@ class GeneralUtility
// If the value is an array then we will call this function recursively:
if (is_array($v)) {
// Sub elements:
if ($options['alt_options'][$stackData['path'] . '/' . $tagName]) {
if (isset($options['alt_options']) && $options['alt_options'][($stackData['path'] ?? '') . '/' . $tagName]) {
$subOptions = $options['alt_options'][$stackData['path'] . '/' . $tagName];
$clearStackPath = $subOptions['clearStackPath'];
} else {
......@@ -1535,12 +1535,12 @@ class GeneralUtility
} else {
$content = $nl . self::array2xml($v, $NSprefix, $level + 1, '', $spaceInd, $subOptions, [
'parentTagName' => $tagName,
'grandParentTagName' => $stackData['parentTagName'],
'path' => $clearStackPath ? '' : $stackData['path'] . '/' . $tagName
'grandParentTagName' => $stackData['parentTagName'] ?? '',
'path' => $clearStackPath ? '' : ($stackData['path'] ?? '') . '/' . $tagName
]) . ($spaceInd >= 0 ? str_pad('', ($level + 1) * $indentN, $indentChar) : '');
}
// Do not set "type = array". Makes prettier XML but means that empty arrays are not restored with xml2array
if ((int)$options['disableTypeAttrib'] != 2) {
if (!isset($options['disableTypeAttrib']) || (int)$options['disableTypeAttrib'] != 2) {
$attr .= ' type="array"';
}
} else {
......
<?php
declare(strict_types = 1);
namespace TYPO3\CMS\Core\Tests\Unit\Resource\Driver;
/*
......@@ -125,7 +126,11 @@ class LocalDriverTest extends BaseTestCase
}
/** @var LocalDriver $driver */
$mockedDriverMethods[] = 'isPathValid';
$driver = $this->getAccessibleMock(LocalDriver::class, $mockedDriverMethods, [$driverConfiguration]);
$driver = $this->getAccessibleMock(
LocalDriver::class,
$mockedDriverMethods,
[$driverConfiguration]
);
$driver->expects($this->any())
->method('isPathValid')
->will(
......@@ -193,7 +198,13 @@ class LocalDriverTest extends BaseTestCase
public function determineBaseUrlUrlEncodesUriParts(): void
{
/** @var LocalDriver|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\TestingFramework\Core\AccessibleObjectInterface $driver */
$driver = $this->getAccessibleMock(LocalDriver::class, ['hasCapability'], [], '', false);
$driver = $this->getAccessibleMock(
LocalDriver::class,
['hasCapability'],
[],
'',
false
);
$driver->expects($this->once())
->method('hasCapability')
->with(ResourceStorage::CAPABILITY_PUBLIC)
......@@ -364,7 +375,7 @@ class LocalDriverTest extends BaseTestCase
/**
* @test
* @dataProvider getSpecificFileInformationDataProvider
* @param $expectedValue
* @param string|int $expectedValue
* @param string $property
*/
public function getSpecificFileInformationReturnsRequestedFileInformation($expectedValue, string $property): void
......@@ -373,7 +384,7 @@ class LocalDriverTest extends BaseTestCase
$subFolder = vfsStream::newDirectory('fileadmin');
$root->addChild($subFolder);
// Load fixture files and folders from disk
$directory = vfsStream::copyFromFileSystem(__DIR__ . '/Fixtures/', $subFolder, 1024*1024);
$directory = vfsStream::copyFromFileSystem(__DIR__ . '/Fixtures/', $subFolder, 1024 * 1024);
if (in_array($property, ['mtime', 'ctime', 'atime'])) {
$expectedValue = $directory->getChild('Dummy.html')->filemtime();
}
......@@ -563,7 +574,10 @@ class LocalDriverTest extends BaseTestCase
'baseUri' => $baseUri
]);
$publicUrl = $subject->getPublicUrl($fileIdentifier);
$this->assertTrue(GeneralUtility::isValidUrl($publicUrl), 'getPublicUrl did not return a valid URL:' . $publicUrl);
$this->assertTrue(
GeneralUtility::isValidUrl($publicUrl),
'getPublicUrl did not return a valid URL:' . $publicUrl
);
}
/**
......@@ -579,7 +593,11 @@ class LocalDriverTest extends BaseTestCase
$this->assertEquals($fileContents, $subject->getFileContents('/file.ext'), 'File contents could not be read');
$newFileContents = 'asdfgh';
$subject->setFileContents('/file.ext', $newFileContents);
$this->assertEquals($newFileContents, $subject->getFileContents('/file.ext'), 'New file contents could not be read.');
$this->assertEquals(
$newFileContents,
$subject->getFileContents('/file.ext'),
'New file contents could not be read.'
);
}
/**
......@@ -640,7 +658,7 @@ class LocalDriverTest extends BaseTestCase
]
);
/** @var $subject LocalDriver */
list($basedir, $subject) = $this->prepareRealTestEnvironment();
[$basedir, $subject] = $this->prepareRealTestEnvironment();
mkdir($basedir . '/someDir');
$subject->createFile('testfile.txt', '/someDir');
$this->assertEquals((int)$testpattern, (int)(decoct(fileperms($basedir . '/someDir/testfile.txt') & 0777)));
......@@ -658,7 +676,7 @@ class LocalDriverTest extends BaseTestCase
$subFolder = vfsStream::newDirectory('fileadmin');
$root->addChild($subFolder);
// Load fixture files and folders from disk
vfsStream::copyFromFileSystem(__DIR__ . '/Fixtures/', $subFolder, 1024*1024);
vfsStream::copyFromFileSystem(__DIR__ . '/Fixtures/', $subFolder, 1024 * 1024);
FileStreamWrapper::init(Environment::getPublicPath() . '/');
FileStreamWrapper::registerOverlayPath('fileadmin/', 'vfs://root/fileadmin/', false);
......@@ -706,7 +724,7 @@ class LocalDriverTest extends BaseTestCase
$this->addToMount($dirStructure);
$subject = $this->createDriver(
[],
// Mocked because finfo() can not deal with vfs streams and throws warnings
// Mocked because finfo() can not deal with vfs streams and throws warnings
['getMimeTypeOfFile']
);
$fileList = $subject->getFilesInFolder('/');
......@@ -731,7 +749,7 @@ class LocalDriverTest extends BaseTestCase
$this->addToMount($dirStructure);
$subject = $this->createDriver(
[],
// Mocked because finfo() can not deal with vfs streams and throws warnings
// Mocked because finfo() can not deal with vfs streams and throws warnings
['getMimeTypeOfFile']
);
$fileList = $subject->getFilesInFolder('/', 0, 0, true);
......@@ -801,7 +819,7 @@ class LocalDriverTest extends BaseTestCase
$this->addToMount($dirStructure);
$subject = $this->createDriver(
[],
// Mocked because finfo() can not deal with vfs streams and throws warnings
// Mocked because finfo() can not deal with vfs streams and throws warnings
['getMimeTypeOfFile']
);
$filterCallbacks = [
......@@ -926,7 +944,7 @@ class LocalDriverTest extends BaseTestCase
/**
* @test
* @covers LocalDriver::getFileForLocalProcessing
* @covers \TYPO3\CMS\Core\Resource\Driver\LocalDriver::getFileForLocalProcessing
*/
public function getFileForLocalProcessingCreatesCopyOfFileByDefault(): void
{
......@@ -981,7 +999,7 @@ class LocalDriverTest extends BaseTestCase
public function permissionsAreCorrectlyRetrievedForAllowedFile(): void
{
/** @var $subject LocalDriver */
list($basedir, $subject) = $this->prepareRealTestEnvironment();
[$basedir, $subject] = $this->prepareRealTestEnvironment();
touch($basedir . '/someFile');
chmod($basedir . '/someFile', 448);
clearstatcache();
......@@ -993,13 +1011,13 @@ class LocalDriverTest extends BaseTestCase
*/
public function permissionsAreCorrectlyRetrievedForForbiddenFile(): void
{
if (function_exists('posix_getegid') && posix_getegid() === 0) {
if (\function_exists('posix_getegid') && posix_getegid() === 0) {
$this->markTestSkipped('Test skipped if run on linux as root');
} elseif (Environment::isWindows()) {
$this->markTestSkipped('Test skipped if run on Windows system');
}
/** @var $subject LocalDriver */
list($basedir, $subject) = $this->prepareRealTestEnvironment();
[$basedir, $subject] = $this->prepareRealTestEnvironment();
touch($basedir . '/someForbiddenFile');
chmod($basedir . '/someForbiddenFile', 0);
clearstatcache();
......@@ -1012,7 +1030,7 @@ class LocalDriverTest extends BaseTestCase
public function permissionsAreCorrectlyRetrievedForAllowedFolder(): void
{
/** @var $subject LocalDriver */
list($basedir, $subject) = $this->prepareRealTestEnvironment();
[$basedir, $subject] = $this->prepareRealTestEnvironment();
mkdir($basedir . '/someFolder');
chmod($basedir . '/someFolder', 448);
clearstatcache();
......@@ -1030,7 +1048,7 @@ class LocalDriverTest extends BaseTestCase
$this->markTestSkipped('Test skipped if run on Windows system');
}
/** @var $subject LocalDriver */
list($basedir, $subject) = $this->prepareRealTestEnvironment();
[$basedir, $subject] = $this->prepareRealTestEnvironment();
mkdir($basedir . '/someForbiddenFolder');
chmod($basedir . '/someForbiddenFolder', 0);
clearstatcache();
......@@ -1185,7 +1203,7 @@ class LocalDriverTest extends BaseTestCase
]);
$subject = $this->createDriver(
[],
// Mocked because finfo() can not deal with vfs streams and throws warnings
// Mocked because finfo() can not deal with vfs streams and throws warnings
['getMimeTypeOfFile']
);
$newIdentifier = $subject->moveFileWithinStorage('/someFile', '/targetFolder/', 'file');
......@@ -1284,8 +1302,12 @@ class LocalDriverTest extends BaseTestCase
* @param string $newFolderName
* @param string $expectedNewIdentifier
*/
public function renamingFoldersChangesFolderNameOnDisk(array $filesystemStructure, string $oldFolderIdentifier, string $newFolderName, string $expectedNewIdentifier)
{
public function renamingFoldersChangesFolderNameOnDisk(
array $filesystemStructure,
string $oldFolderIdentifier,
string $newFolderName,
string $expectedNewIdentifier
): void {
$this->addToMount($filesystemStructure);
$subject = $this->createDriver();
$mapping = $subject->renameFolder($oldFolderIdentifier, $newFolderName);
......@@ -1418,7 +1440,10 @@ class LocalDriverTest extends BaseTestCase
$subject = $this->createDriver();
$mappingInformation = $subject->moveFolderWithinStorage('/sourceFolder/', '/targetFolder/', 'sourceFolder');
$this->assertEquals('/targetFolder/sourceFolder/file', $mappingInformation['/sourceFolder/file']);
$this->assertEquals('/targetFolder/sourceFolder/subFolder/file', $mappingInformation['/sourceFolder/subFolder/file']);
$this->assertEquals(
'/targetFolder/sourceFolder/subFolder/file',
$mappingInformation['/sourceFolder/subFolder/file']
);
$this->assertEquals('/targetFolder/sourceFolder/subFolder/', $mappingInformation['/sourceFolder/subFolder/']);
}
......@@ -1459,7 +1484,7 @@ class LocalDriverTest extends BaseTestCase
*/
public function copyFolderWithinStorageCopiesSingleSubFolderToNewFolderName(): void
{
list($basePath, $subject) = $this->prepareRealTestEnvironment();
[$basePath, $subject] = $this->prepareRealTestEnvironment();
GeneralUtility::mkdir_deep($basePath . '/sourceFolder/subFolder');
GeneralUtility::mkdir_deep($basePath . '/targetFolder');
......@@ -1472,7 +1497,7 @@ class LocalDriverTest extends BaseTestCase
*/
public function copyFolderWithinStorageCopiesFileInSingleSubFolderToNewFolderName(): void
{
list($basePath, $subject) = $this->prepareRealTestEnvironment();
[$basePath, $subject] = $this->prepareRealTestEnvironment();
GeneralUtility::mkdir_deep($basePath . '/sourceFolder/subFolder');
GeneralUtility::mkdir_deep($basePath . '/targetFolder');
file_put_contents($basePath . '/sourceFolder/subFolder/file', $this->getUniqueId());
......
<?php
declare(strict_types = 1);
namespace TYPO3\CMS\Core\Tests\Unit\Resource;
......@@ -24,11 +25,6 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
*/
class ResourceCompressorIntegrationTest extends BaseTestCase
{
/**
* Subject is not notice free, disable E_NOTICES
*/
protected static $suppressNotices = true;
/**
* @var TestableResourceCompressor
*/
......@@ -44,7 +40,7 @@ class ResourceCompressorIntegrationTest extends BaseTestCase
*/
protected $fixtureDirFromTest;
public function setUp()
public function setUp(): void
{
$this->fixtureDir = 'sysext/core/Tests/Unit/Resource/ResourceCompressorTest/Fixtures/';
$this->fixtureDirFromTest = GeneralUtility::fixWindowsFilePath(__DIR__ . '/ResourceCompressorTest/Fixtures/');
......@@ -53,7 +49,7 @@ class ResourceCompressorIntegrationTest extends BaseTestCase
/**
* @test
*/
public function constructorCreatesTargetDirectory()
public function constructorCreatesTargetDirectory(): void
{
$this->resourceCompressor = new TestableResourceCompressor();
$dir = Environment::getPublicPath() . '/' . $this->resourceCompressor->getTargetDirectory();
......@@ -63,7 +59,7 @@ class ResourceCompressorIntegrationTest extends BaseTestCase
/**
* @test
*/
public function constructorCreatesHtaccessFileIfSet()
public function constructorCreatesHtaccessFileIfSet(): void
{
$GLOBALS['TYPO3_CONF_VARS']['SYS']['generateApacheHtaccess'] = true;
$this->resourceCompressor = new TestableResourceCompressor();
......@@ -74,7 +70,7 @@ class ResourceCompressorIntegrationTest extends BaseTestCase
/**
* @test
*/
public function constructorDoesNotCreateHtaccessFileIfSetToFalse()
public function constructorDoesNotCreateHtaccessFileIfSetToFalse(): void
{
$GLOBALS['TYPO3_CONF_VARS']['SYS']['generateApacheHtaccess'] = false;
$this->resourceCompressor = new TestableResourceCompressor();
......@@ -85,7 +81,7 @@ class ResourceCompressorIntegrationTest extends BaseTestCase
/**
* @test
*/
public function concatenateCssFiles()
public function concatenateCssFiles(): void
{
$files = [
'sampleFile1' => [
......@@ -107,7 +103,7 @@ class ResourceCompressorIntegrationTest extends BaseTestCase
/**
* @test
*/
public function concatenateCssFilesWorksWithFileFromNonRootPath()
public function concatenateCssFilesWorksWithFileFromNonRootPath(): void
{
$testFile = Environment::getPublicPath() . '/typo3temp/var/transient/css_input_with_import.css';
$this->testFilesToDelete[] = $testFile;
......@@ -129,7 +125,7 @@ class ResourceCompressorIntegrationTest extends BaseTestCase
self::assertStringEqualsFile(GeneralUtility::fixWindowsFilePath(Environment::getPublicPath() . '/' . $mergedFile['file']), $expected);
}
public function tearDown()
public function tearDown(): void
{
$this->testFilesToDelete[] = Environment::getPublicPath() . '/' . $this->resourceCompressor->getTargetDirectory();
parent::tearDown();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment