Initial commit - Typo3 11.5.41
This commit is contained in:
51
typo3conf/ext/news/Tests/Unit/Utility/ImportJobTest.php
Normal file
51
typo3conf/ext/news/Tests/Unit/Utility/ImportJobTest.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace GeorgRinger\News\Tests\Unit\Utility;
|
||||
|
||||
/**
|
||||
* This file is part of the "news" Extension for TYPO3 CMS.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*/
|
||||
use GeorgRinger\News\Utility\ImportJob;
|
||||
use TYPO3\TestingFramework\Core\BaseTestCase;
|
||||
|
||||
/**
|
||||
* Test class for ImportJob
|
||||
*
|
||||
*/
|
||||
class ImportJobTest extends BaseTestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function classCanBeRegistered(): void
|
||||
{
|
||||
$importJobInstance = new ImportJob();
|
||||
|
||||
$jobs = [];
|
||||
$this->assertEquals($importJobInstance->getRegisteredJobs(), $jobs);
|
||||
|
||||
// Add job #1
|
||||
$jobs[] = [
|
||||
'className' => 'Class 1',
|
||||
'title' => 'Some title',
|
||||
'description' => ''
|
||||
];
|
||||
$importJobInstance->register('Class 1', 'Some title', '');
|
||||
$this->assertEquals($importJobInstance->getRegisteredJobs(), $jobs);
|
||||
|
||||
// Add job #2
|
||||
$jobs[] = [
|
||||
'className' => 'Class 2',
|
||||
'title' => '',
|
||||
'description' => 'Some description'
|
||||
];
|
||||
$importJobInstance->register('Class 2', '', 'Some description');
|
||||
$this->assertEquals($importJobInstance->getRegisteredJobs(), $jobs);
|
||||
}
|
||||
}
|
||||
113
typo3conf/ext/news/Tests/Unit/Utility/TemplateLayoutTest.php
Normal file
113
typo3conf/ext/news/Tests/Unit/Utility/TemplateLayoutTest.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace GeorgRinger\News\Tests\Unit\Utility;
|
||||
|
||||
/**
|
||||
* This file is part of the "news" Extension for TYPO3 CMS.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use GeorgRinger\News\Utility\TemplateLayout;
|
||||
use TYPO3\TestingFramework\Core\BaseTestCase;
|
||||
|
||||
/**
|
||||
* TemplateLayout utility class unit tests
|
||||
*/
|
||||
class TemplateLayoutTest extends BaseTestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function templatesFoundInTypo3ConfVars(): void
|
||||
{
|
||||
$GLOBALS['TYPO3_CONF_VARS']['EXT']['news']['templateLayouts'] = [
|
||||
0 => [
|
||||
0 => 'Layout 1',
|
||||
1 => 'layout1'
|
||||
],
|
||||
1 => [
|
||||
0 => 'Layout 2',
|
||||
1 => 'layout2'
|
||||
],
|
||||
];
|
||||
|
||||
$templateLayoutUtility = $this->getAccessibleMock(TemplateLayout::class, ['getTemplateLayoutsFromTsConfig']);
|
||||
$templateLayoutUtility->expects($this->once())->method('getTemplateLayoutsFromTsConfig')->will($this->returnValue([]));
|
||||
$templateLayouts = $templateLayoutUtility->_call('getAvailableTemplateLayouts', 1);
|
||||
$this->assertSame($GLOBALS['TYPO3_CONF_VARS']['EXT']['news']['templateLayouts'], $templateLayouts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function templatesFoundInPageTsConfig(): void
|
||||
{
|
||||
$tsConfigArray = [
|
||||
'layout1' => 'Layout 1',
|
||||
'layout2' => 'Layout 2',
|
||||
];
|
||||
$result = [
|
||||
0 => [
|
||||
0 => 'Layout 1',
|
||||
1 => 'layout1'
|
||||
],
|
||||
1 => [
|
||||
0 => 'Layout 2',
|
||||
1 => 'layout2'
|
||||
],
|
||||
];
|
||||
|
||||
// clear TYPO3_CONF_VARS
|
||||
unset($GLOBALS['TYPO3_CONF_VARS']['EXT']['news']['templateLayouts']);
|
||||
|
||||
$templateLayoutUtility = $this->getAccessibleMock(TemplateLayout::class, ['getTemplateLayoutsFromTsConfig']);
|
||||
$templateLayoutUtility->expects($this->once())->method('getTemplateLayoutsFromTsConfig')->will($this->returnValue($tsConfigArray));
|
||||
$templateLayouts = $templateLayoutUtility->_call('getAvailableTemplateLayouts', 1);
|
||||
$this->assertSame($result, $templateLayouts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function templatesFoundInCombinedResources(): void
|
||||
{
|
||||
$tsConfigArray = [
|
||||
'layout1' => 'Layout 1',
|
||||
'layout2' => 'Layout 2',
|
||||
];
|
||||
$GLOBALS['TYPO3_CONF_VARS']['EXT']['news']['templateLayouts'] = [
|
||||
0 => [
|
||||
0 => 'Layout 4',
|
||||
1 => 'layout4'
|
||||
],
|
||||
];
|
||||
$result = [
|
||||
0 => [
|
||||
0 => 'Layout 4',
|
||||
1 => 'layout4'
|
||||
],
|
||||
1 => [
|
||||
0 => 'Layout 1',
|
||||
1 => 'layout1'
|
||||
],
|
||||
2 => [
|
||||
0 => 'Layout 2',
|
||||
1 => 'layout2'
|
||||
],
|
||||
];
|
||||
|
||||
$templateLayoutUtility = $this->getAccessibleMock(TemplateLayout::class, ['getTemplateLayoutsFromTsConfig']);
|
||||
$templateLayoutUtility->expects($this->once())->method('getTemplateLayoutsFromTsConfig')->will($this->returnValue($tsConfigArray));
|
||||
$templateLayouts = $templateLayoutUtility->_call('getAvailableTemplateLayouts', 1);
|
||||
$this->assertSame($result, $templateLayouts);
|
||||
}
|
||||
}
|
||||
273
typo3conf/ext/news/Tests/Unit/Utility/TypoScriptTest.php
Normal file
273
typo3conf/ext/news/Tests/Unit/Utility/TypoScriptTest.php
Normal file
@@ -0,0 +1,273 @@
|
||||
<?php
|
||||
|
||||
namespace GeorgRinger\News\Tests\Unit\Utility;
|
||||
|
||||
/**
|
||||
* This file is part of the "news" Extension for TYPO3 CMS.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*/
|
||||
use GeorgRinger\News\Utility\TypoScript;
|
||||
use TYPO3\TestingFramework\Core\BaseTestCase;
|
||||
|
||||
/**
|
||||
* Test class for TypoScript
|
||||
*
|
||||
*/
|
||||
class TypoScriptTest extends BaseTestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @dataProvider overrideWorksDataProvider
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function overrideWorks($base, $overload, $expected): void
|
||||
{
|
||||
$utility = new TypoScript();
|
||||
|
||||
$result = $utility->override($base, $overload);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function overrideWorksDataProvider()
|
||||
{
|
||||
return [
|
||||
'basic' => [
|
||||
[
|
||||
'value_1' => 'fo',
|
||||
'value_2' => ''
|
||||
],
|
||||
[],
|
||||
[
|
||||
'value_1' => 'fo',
|
||||
'value_2' => ''
|
||||
]
|
||||
],
|
||||
'simple' => [
|
||||
[
|
||||
'value_1' => 'fo',
|
||||
'value_2' => ''
|
||||
],
|
||||
[
|
||||
'settings' => [
|
||||
'value_2' => 'bar',
|
||||
'overrideFlexformSettingsIfEmpty' => 'value_2'
|
||||
]
|
||||
],
|
||||
[
|
||||
'value_1' => 'fo',
|
||||
'value_2' => 'bar'
|
||||
]
|
||||
],
|
||||
'simple2' => [
|
||||
[
|
||||
'value_1' => 'fo',
|
||||
'sub' => [
|
||||
'sub_1' => 'xy'
|
||||
]
|
||||
],
|
||||
[
|
||||
'settings' => [
|
||||
'value_2' => 'bar',
|
||||
'overrideFlexformSettingsIfEmpty' => 'value_2'
|
||||
]
|
||||
],
|
||||
[
|
||||
'value_1' => 'fo',
|
||||
'value_2' => 'bar',
|
||||
'sub' => [
|
||||
'sub_1' => 'xy'
|
||||
]
|
||||
]
|
||||
],
|
||||
'deep' => [
|
||||
[
|
||||
'value_1' => 'fo',
|
||||
'sub_1' => [
|
||||
'sub_1a' => ''
|
||||
],
|
||||
'sub_2' => [
|
||||
'sub_2a' => 'xy',
|
||||
],
|
||||
],
|
||||
[
|
||||
'settings' => [
|
||||
'value_2' => 'bar',
|
||||
'sub_1' => [
|
||||
'sub_1a' => 'lorem'
|
||||
],
|
||||
'sub_2' => [
|
||||
'sub_2a' => 'xy',
|
||||
'sub_2b' => 'abc'
|
||||
],
|
||||
'overrideFlexformSettingsIfEmpty' => 'value_2, sub_1.sub_1a,sub_2.sub_2b'
|
||||
]
|
||||
],
|
||||
[
|
||||
'value_1' => 'fo',
|
||||
'value_2' => 'bar',
|
||||
'sub_1' => [
|
||||
'sub_1a' => 'lorem'
|
||||
],
|
||||
'sub_2' => [
|
||||
'sub_2a' => 'xy',
|
||||
],
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @dataProvider correctValueIsReturnedDataProvider
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function correctValueIsReturned($path, $expected): void
|
||||
{
|
||||
$mockedUtility = $this->getAccessibleMock(TypoScript::class, ['dummy']);
|
||||
|
||||
$in = [
|
||||
'level_1' => [
|
||||
'in_1' => 'value in 1',
|
||||
'level_2' => [
|
||||
'level_3' => [
|
||||
'in_3' => 'value in 3'
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$path = explode('.', $path);
|
||||
$result = $mockedUtility->_call('getValue', $in, $path);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function correctValueIsReturnedDataProvider()
|
||||
{
|
||||
return [
|
||||
'valueFoundInDeepLevel' => [
|
||||
'level_1.level_2.level_3.in_3', 'value in 3'
|
||||
],
|
||||
'valueFoundInFirstLevel' => [
|
||||
'level_1.in_1', 'value in 1'
|
||||
],
|
||||
'firstLevelNotFound' => [
|
||||
'wrong.wronger.stillWrong', null
|
||||
],
|
||||
'lastLevelNotFound' => [
|
||||
'level_1.level_2.level_3.in_Nothing', null
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @dataProvider correctValueIsSetDataProvider
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function correctValueIsSet($path, $newValue, $expected): void
|
||||
{
|
||||
$mockedUtility = $this->getAccessibleMock(TypoScript::class, ['dummy'], [], '', true, false);
|
||||
|
||||
$in = [
|
||||
'level_1' => [
|
||||
'in_1' => 'value in 1',
|
||||
'level_2' => [
|
||||
'level_3' => [
|
||||
'in_3' => 'value in 3'
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$path = explode('.', $path);
|
||||
$result = $mockedUtility->_call('setValue', $in, $path, $newValue);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function correctValueIsSetDataProvider()
|
||||
{
|
||||
return [
|
||||
'overrideValueLow' => [
|
||||
'level_1.in_1',
|
||||
'new value in 1',
|
||||
[
|
||||
'level_1' => [
|
||||
'in_1' => 'new value in 1',
|
||||
'level_2' => [
|
||||
'level_3' => [
|
||||
'in_3' => 'value in 3'
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
'overrideValueDeep' => [
|
||||
'level_1.level_2.level_3.in_3',
|
||||
'new value in 3',
|
||||
[
|
||||
'level_1' => [
|
||||
'in_1' => 'value in 1',
|
||||
'level_2' => [
|
||||
'level_3' => [
|
||||
'in_3' => 'new value in 3'
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
'newValueDeep' => [
|
||||
'level_1.level_2.level_3.level_4.level_5.in_5',
|
||||
'new value in 5',
|
||||
[
|
||||
'level_1' => [
|
||||
'in_1' => 'value in 1',
|
||||
'level_2' => [
|
||||
'level_3' => [
|
||||
'in_3' => 'value in 3',
|
||||
'level_4' => [
|
||||
'level_5' => [
|
||||
'in_5' => 'new value in 5'
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
'overrideArrayWithValue' => [
|
||||
'level_1.level_2',
|
||||
'new value as 2',
|
||||
[
|
||||
'level_1' => [
|
||||
'in_1' => 'value in 1',
|
||||
'level_2' => 'new value as 2'
|
||||
]
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
54
typo3conf/ext/news/Tests/Unit/Utility/UrlTest.php
Normal file
54
typo3conf/ext/news/Tests/Unit/Utility/UrlTest.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace GeorgRinger\News\Tests\Unit\Utility;
|
||||
|
||||
/**
|
||||
* This file is part of the "news" Extension for TYPO3 CMS.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*/
|
||||
use GeorgRinger\News\Utility\Url;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\TestingFramework\Core\BaseTestCase;
|
||||
|
||||
/**
|
||||
* Test class for Url
|
||||
*
|
||||
*/
|
||||
class UrlTest extends BaseTestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @dataProvider correctUrlIsDeliveredDataProvider
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function correctUrlIsDelivered($actual, $expected): void
|
||||
{
|
||||
$this->assertEquals($expected, Url::prependDomain($actual));
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function correctUrlIsDeliveredDataProvider()
|
||||
{
|
||||
$currentDomain = GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
|
||||
return [
|
||||
'absoluteUrlIsUsed' => [
|
||||
$currentDomain . 'index.php?id=123', $currentDomain . 'index.php?id=123'
|
||||
],
|
||||
'relativeUrlIsUsed' => [
|
||||
'index.php?id=123', $currentDomain . 'index.php?id=123'
|
||||
],
|
||||
'domainOnlyIsGiven' => [
|
||||
$currentDomain, $currentDomain
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
81
typo3conf/ext/news/Tests/Unit/Utility/ValidationTest.php
Normal file
81
typo3conf/ext/news/Tests/Unit/Utility/ValidationTest.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace GeorgRinger\News\Tests\Unit\Utility;
|
||||
|
||||
/**
|
||||
* This file is part of the "news" Extension for TYPO3 CMS.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*/
|
||||
use GeorgRinger\News\Utility\Validation;
|
||||
use TYPO3\TestingFramework\Core\BaseTestCase;
|
||||
|
||||
/**
|
||||
* Tests for Validation
|
||||
*
|
||||
*/
|
||||
class ValidationTest extends BaseTestCase
|
||||
{
|
||||
const ALLOWED_FIELDS = 'author,uid,title,teaser,author,tstamp,crdate,datetime,categories.title';
|
||||
|
||||
/**
|
||||
* Test if default file format works
|
||||
*
|
||||
* @test
|
||||
*
|
||||
* @dataProvider orderDataProvider
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testForValidOrdering($expectedFields, $expected): void
|
||||
{
|
||||
$validation = Validation::isValidOrdering($expectedFields, self::ALLOWED_FIELDS);
|
||||
$this->assertEquals($validation, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return (bool|string)[][]
|
||||
*
|
||||
* @psalm-return array{allowedOrdering: array{0: string, 1: true}, allowedOrderingWithSorting: array{0: string, 1: true}, allowedOrderingWithSorting2: array{0: string, 1: true}, allowedOrderingWithSorting3: array{0: string, 1: true}, allowedOrderingWithDotsAndSorting: array{0: string, 1: true}, nonAllowedField: array{0: string, 1: false}, nonAllowedSorting: array{0: string, 1: false}, nonAllowedDoubleSorting: array{0: string, 1: false}, nonAllowedDoubleFields: array{0: string, 1: false}, emptySorting: array{0: string, 1: true}, emptySorting2: array{0: string, 1: true}}
|
||||
*/
|
||||
public function orderDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'allowedOrdering' => [
|
||||
'title,uid', true
|
||||
],
|
||||
'allowedOrderingWithSorting' => [
|
||||
'title ASC, uid', true
|
||||
],
|
||||
'allowedOrderingWithSorting2' => [
|
||||
'title ASC, uid DESC', true
|
||||
],
|
||||
'allowedOrderingWithSorting3' => [
|
||||
'title, uid desc,teaser', true
|
||||
],
|
||||
'allowedOrderingWithDotsAndSorting' => [
|
||||
'categories.title DESC, uid ASC,author,teaser desc', true
|
||||
],
|
||||
'nonAllowedField' => [
|
||||
'title,teaserFo,uid', false
|
||||
],
|
||||
'nonAllowedSorting' => [
|
||||
'title,teaser ASCx,uid', false
|
||||
],
|
||||
'nonAllowedDoubleSorting' => [
|
||||
'title,teaser ASC DESC,uid', false
|
||||
],
|
||||
'nonAllowedDoubleFields' => [
|
||||
'title teaser,uid', false
|
||||
],
|
||||
'emptySorting' => [
|
||||
'', true
|
||||
],
|
||||
'emptySorting2' => [
|
||||
' ', true
|
||||
],
|
||||
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user