Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUGFIX] Properly handle array key access in ExtendedTemplateService
This fixes the ExtendedTemplateService->ext_getSetup() method, which now properly handles array key accesses. A new early return now also checks for an empty key and returns the whole setup in this case. This is a special case, needed for e.g. the object browser, to still show the full setup when object lists exist. Resolves: #94971 Releases: master Change-Id: I7b6615022ba59dc99929b05744c1cb33805098aa Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/71461 Tested-by: core-ci <typo3@b13.com> Tested-by: Tymoteusz Motylewski <t.motylewski@gmail.com> Tested-by: Jochen <rothjochen@gmail.com> Tested-by: Benni Mack <benni@typo3.org> Reviewed-by: Tymoteusz Motylewski <t.motylewski@gmail.com> Reviewed-by: Jochen <rothjochen@gmail.com> Reviewed-by: Benni Mack <benni@typo3.org>
- Loading branch information
Showing
3 changed files
with
240 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
195 changes: 195 additions & 0 deletions
195
typo3/sysext/core/Tests/Unit/TypoScript/ExtendedTemplateServiceTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the TYPO3 CMS project. | ||
* | ||
* It is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License, either version 2 | ||
* of the License, or any later version. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
* | ||
* The TYPO3 project - inspiring people to share! | ||
*/ | ||
|
||
namespace TYPO3\CMS\Core\Tests\Unit\TypoScript; | ||
|
||
use PHPUnit\Framework\MockObject\MockObject; | ||
use TYPO3\CMS\Core\TypoScript\ExtendedTemplateService; | ||
use TYPO3\TestingFramework\Core\AccessibleObjectInterface; | ||
use TYPO3\TestingFramework\Core\Unit\UnitTestCase; | ||
|
||
/** | ||
* Test case | ||
*/ | ||
class ExtendedTemplateServiceTest extends UnitTestCase | ||
{ | ||
|
||
/** | ||
* @var ExtendedTemplateService|MockObject|AccessibleObjectInterface | ||
*/ | ||
protected $extendedTemplateServiceMock; | ||
|
||
/** | ||
* Set up | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->extendedTemplateServiceMock = $this->getAccessibleMock( | ||
ExtendedTemplateService::class, | ||
null, | ||
[], | ||
'', | ||
false | ||
); | ||
} | ||
|
||
/** | ||
* @dataProvider ext_getSetupDataProvider | ||
* @test | ||
*/ | ||
public function ext_getSetupTest($setup, $key, $expected): void | ||
{ | ||
$actual = $this->extendedTemplateServiceMock->ext_getSetup($setup, $key); | ||
self::assertEquals($expected, $actual); | ||
} | ||
|
||
public function ext_getSetupDataProvider(): array | ||
{ | ||
return [ | ||
'empty setup and key' => [ | ||
[], | ||
'', | ||
[[], ''], | ||
], | ||
'empty setup and not empty key' => [ | ||
[], | ||
'key', | ||
[[], ''], | ||
], | ||
'empty key' => [ | ||
'typoScriptSetup' => [ | ||
'10.' => [ | ||
'value' => 'Hello World!', | ||
'foo.' => [ | ||
'bar' => 5, | ||
], | ||
], | ||
'10' => 'TEXT', | ||
], | ||
'key' => '', | ||
'expected' => [ | ||
[ | ||
'10.' => [ | ||
'value' => 'Hello World!', | ||
'foo.' => [ | ||
'bar' => 5, | ||
], | ||
], | ||
'10' => 'TEXT', | ||
], | ||
'', | ||
], | ||
], | ||
'special key "0" which is considered as empty' => [ | ||
'typoScriptSetup' => [ | ||
'10.' => [ | ||
'value' => 'Hello World!', | ||
'foo.' => [ | ||
'bar' => 5, | ||
], | ||
], | ||
'10' => 'TEXT', | ||
], | ||
'key' => '0', | ||
'expected' => [ | ||
[ | ||
'10.' => [ | ||
'value' => 'Hello World!', | ||
'foo.' => [ | ||
'bar' => 5, | ||
], | ||
], | ||
'10' => 'TEXT', | ||
], | ||
'', | ||
], | ||
], | ||
'not empty key - 1st level' => [ | ||
'typoScriptSetup' => [ | ||
'10.' => [ | ||
'value' => 'Hello World!', | ||
'foo.' => [ | ||
'bar' => 5, | ||
], | ||
], | ||
'10' => 'TEXT', | ||
], | ||
'key' => '10', | ||
'expected' => [ | ||
[ | ||
'value' => 'Hello World!', | ||
'foo.' => [ | ||
'bar' => 5, | ||
], | ||
], | ||
'TEXT', | ||
], | ||
], | ||
'not empty key - 2nd level' => [ | ||
'typoScriptSetup' => [ | ||
'10.' => [ | ||
'value' => 'Hello World!', | ||
'foo.' => [ | ||
'bar' => 5, | ||
], | ||
], | ||
'10' => 'TEXT', | ||
], | ||
'key' => '10.foo', | ||
'expected' => [ | ||
[ | ||
'bar' => 5, | ||
], | ||
'', | ||
], | ||
], | ||
'not empty key - 3rd level - leaf' => [ | ||
'typoScriptSetup' => [ | ||
'10.' => [ | ||
'value' => 'Hello World!', | ||
'foo.' => [ | ||
'bar' => 5, | ||
], | ||
], | ||
'10' => 'TEXT', | ||
], | ||
'key' => '10.foo.bar', | ||
'expected' => [ | ||
[], | ||
'5', | ||
], | ||
], | ||
'not empty key - 4th, non existing level' => [ | ||
'typoScriptSetup' => [ | ||
'10.' => [ | ||
'value' => 'Hello World!', | ||
'foo.' => [ | ||
'bar' => 5, | ||
], | ||
], | ||
'10' => 'TEXT', | ||
], | ||
'key' => '10.foo.bar.baz', | ||
'expected' => [ | ||
[], | ||
'', | ||
], | ||
], | ||
]; | ||
} | ||
} |