-
Notifications
You must be signed in to change notification settings - Fork 653
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUGFIX] Allow XCLASSing of WorkspaceRecord
The factory method WorkspaceRecord::get() now uses a proper makeInstance() call instead of new for creating new instances, which allows XCLASSing the class and aligns object creation to "the TYPO3 way" in that place. Also add a regression test. Resolves: #97423 Relates: #97754 Releases: main, 11.5 Change-Id: I76e5ce3a1f908bf0efa4faaa439724e2d1d7cbb2 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/74960 Tested-by: core-ci <typo3@b13.com> Tested-by: Stefan Bürk <stefan@buerk.tech> Reviewed-by: Stefan Bürk <stefan@buerk.tech>
- Loading branch information
1 parent
1ee475f
commit ccbbe90
Showing
3 changed files
with
101 additions
and
8 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
99 changes: 99 additions & 0 deletions
99
typo3/sysext/workspaces/Tests/Unit/Domain/Model/WorkspaceRecordTest.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,99 @@ | ||
<?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\Workspaces\Tests\Unit\Domain\Model; | ||
|
||
use TYPO3\CMS\Core\Tests\Unit\Utility\Fixtures\GeneralUtilityFixture; | ||
use TYPO3\CMS\Workspaces\Domain\Record\AbstractRecord; | ||
use TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord; | ||
use TYPO3\TestingFramework\Core\Unit\UnitTestCase; | ||
|
||
class WorkspaceRecordTest extends UnitTestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
GeneralUtilityFixture::resetFinalClassNameCache(); | ||
} | ||
|
||
protected function tearDown(): void | ||
{ | ||
GeneralUtilityFixture::resetFinalClassNameCache(); | ||
parent::tearDown(); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function isAbstractRecord(): void | ||
{ | ||
$subject = new WorkspaceRecord([]); | ||
|
||
self::assertInstanceOf(AbstractRecord::class, $subject); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function getReturnsWorkspaceRecordInstance(): void | ||
{ | ||
$instance = WorkspaceRecord::get(1, ['title' => '']); | ||
|
||
self::assertInstanceOf(WorkspaceRecord::class, $instance); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function getWithNonZeroUidAndNonEmptyDataReturnsInstanceWithTheProvidedData(): void | ||
{ | ||
$title = 'some record title'; | ||
|
||
$instance = WorkspaceRecord::get(1, ['title' => $title]); | ||
|
||
self::assertSame($title, $instance->getTitle()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function getCalledTwoTimesWithTheSameUidAndDataDataReturnsDifferentInstancesForEachCall(): void | ||
{ | ||
$uid = 1; | ||
$data = ['title' => '']; | ||
|
||
$instance1 = WorkspaceRecord::get($uid, $data); | ||
$instance2 = WorkspaceRecord::get($uid, $data); | ||
|
||
self::assertNotSame($instance1, $instance2); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function getForConfiguredXclassReturnsInstanceOfXclass(): void | ||
{ | ||
$xclassInstance = new class([]) extends WorkspaceRecord { | ||
}; | ||
$xclassName = get_class($xclassInstance); | ||
$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][WorkspaceRecord::class] = ['className' => $xclassName]; | ||
|
||
$instance = WorkspaceRecord::get(1, ['title' => '']); | ||
|
||
self::assertInstanceOf($xclassName, $instance); | ||
} | ||
} |