Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[BUGFIX] Correctly retrieve workspace versions
* Clipboard now correctly resolves record localizations of a workspace
* PageLayoutController new correctly determines sub-pages that are new
  in a particular workspace
* SlugHelper & TypoScriptTemplateModuleController can be simplified
  by using WorkspaceRestriction directly
* common function test scenario tree (based on YAML) is introduced
  for ext:backend in order to be used as structure for other tests
* required testing framework changes support version and language
  variants and combination much better now

Resolves: #89138
Releases: master
Change-Id: Ia4b412d48dd3ea92adc60c729ad6feb27c22b812
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/61663
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Daniel Gorges <daniel.gorges@b13.com>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Daniel Gorges <daniel.gorges@b13.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Reviewed-by: Achim Fritz <af@achimfritz.de>
  • Loading branch information
ohader authored and bmack committed Sep 11, 2019
1 parent 2d8a956 commit b55e146
Show file tree
Hide file tree
Showing 12 changed files with 497 additions and 80 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -76,7 +76,7 @@
"friendsofphp/php-cs-fixer": "^2.15.2",
"phpspec/prophecy": "^1.7.5",
"typo3/cms-styleguide": "~10.0.2",
"typo3/testing-framework": "~5.0.12"
"typo3/testing-framework": "~5.0.13"
},
"suggest": {
"ext-gd": "GDlib/Freetype is required for building images with text (GIFBUILDER) and can also be used to scale images",
Expand Down
28 changes: 14 additions & 14 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 6 additions & 7 deletions typo3/sysext/backend/Classes/Clipboard/Clipboard.php
Expand Up @@ -18,6 +18,7 @@
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\WorkspaceRestriction;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Resource\ResourceFactory;
Expand Down Expand Up @@ -474,6 +475,8 @@ public function getLocalizations($table, $parentRec)
{
$lines = [];
$tcaCtrl = $GLOBALS['TCA'][$table]['ctrl'];
$workspaceId = (int)$this->getBackendUser()->workspace;

if (BackendUtility::isTableLocalizable($table)) {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
$queryBuilder->getRestrictions()
Expand All @@ -499,13 +502,9 @@ public function getLocalizations($table, $parentRec)
);

if (BackendUtility::isTableWorkspaceEnabled($table)) {
$queryBuilder
->andWhere(
$queryBuilder->expr()->eq(
't3ver_wsid',
$queryBuilder->createNamedParameter($parentRec['t3ver_wsid'], \PDO::PARAM_INT)
)
);
$queryBuilder->getRestrictions()->add(
GeneralUtility::makeInstance(WorkspaceRestriction::class, $workspaceId)
);
}
$rows = $queryBuilder->execute()->fetchAll();
if (is_array($rows)) {
Expand Down
20 changes: 6 additions & 14 deletions typo3/sysext/backend/Classes/Controller/PageLayoutController.php
Expand Up @@ -29,6 +29,7 @@
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\WorkspaceRestriction;
use TYPO3\CMS\Core\Domain\Repository\PageRepository;
use TYPO3\CMS\Core\Http\HtmlResponse;
use TYPO3\CMS\Core\Imaging\Icon;
Expand Down Expand Up @@ -1216,30 +1217,21 @@ protected function makeLanguageMenu(): void
*/
protected function currentPageHasSubPages(): bool
{
// get workspace id
$workspaceId = (int)$this->getBackendUser()->workspace;

/** @var QueryBuilder $queryBuilder */
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
$queryBuilder->getRestrictions()
->removeAll()
->add(GeneralUtility::makeInstance(DeletedRestriction::class))
->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));

// get workspace id
$workspaceId = (int)$this->getBackendUser()->workspace;
$comparisonExpression = $workspaceId === 0 ? 'neq' : 'eq';
->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, $workspaceId));

$count = $queryBuilder
->count('uid')
->from('pages')
->where(
$queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT)),
$queryBuilder->expr()->eq(
't3ver_wsid',
$queryBuilder->createNamedParameter($workspaceId, \PDO::PARAM_INT)
),
$queryBuilder->expr()->{$comparisonExpression}(
'pid',
$queryBuilder->createNamedParameter(-1, \PDO::PARAM_INT)
)
$queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT))
)
->execute()
->fetchColumn(0);
Expand Down
158 changes: 158 additions & 0 deletions typo3/sysext/backend/Tests/Functional/Clipboard/ClipboardTest.php
@@ -0,0 +1,158 @@
<?php
namespace TYPO3\CMS\Backend\Tests\Functional\Clipboard;

/*
* 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!
*/

use TYPO3\CMS\Backend\Clipboard\Clipboard;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Core\Bootstrap;
use TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\TestingFramework\Core\Functional\Framework\DataHandling\Scenario\DataHandlerFactory;
use TYPO3\TestingFramework\Core\Functional\Framework\DataHandling\Scenario\DataHandlerWriter;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;

/**
* Functional database test for Clipboard behaviour
*/
class ClipboardTest extends FunctionalTestCase
{
use SiteBasedTestTrait;

/**
* @var string[]
*/
protected $coreExtensionsToLoad = ['workspaces'];

/**
* @var Clipboard
*/
private $subject;

/**
* @var BackendUserAuthentication
*/
private $backendUser;

public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();
static::initializeDatabaseSnapshot();
}

public static function tearDownAfterClass(): void
{
static::destroyDatabaseSnapshot();
parent::tearDownAfterClass();
}

protected function setUp(): void
{
parent::setUp();

$this->subject = GeneralUtility::makeInstance(Clipboard::class);
$this->backendUser = $this->setUpBackendUserFromFixture(1);

$this->withDatabaseSnapshot(function () {
$this->setUpDatabase();
});
}

protected function setUpDatabase()
{
Bootstrap::initializeLanguageObject();

$scenarioFile = __DIR__ . '/../Fixtures/CommonScenario.yaml';
$factory = DataHandlerFactory::fromYamlFile($scenarioFile);
$writer = DataHandlerWriter::withBackendUser($this->backendUser);
$writer->invokeFactory($factory);
static::failIfArrayIsNotEmpty(
$writer->getErrors()
);
}

/**
* @return array
*/
public function localizationsAreResolvedDataProvider(): array
{
return [
'live workspace with live & version localizations' => [
1100,
0,
[
'FR: Welcome',
'FR-CA: Welcome',
]
],
'draft workspace with live & version localizations' => [
1100,
1,
[
'FR: Welcome',
'FR-CA: Welcome',
'ES: Bienvenido',
]
],
'live workspace with live localizations only' => [
1400,
0,
[
'FR: ACME in your Region',
'FR-CA: ACME in your Region',
]
],
'draft workspace with live localizations only' => [
1400,
1,
[
'FR: ACME in your Region',
'FR-CA: ACME in your Region',
]
],
'live workspace with version localizations only' => [
1500,
0,
[]
],
'draft workspace with version localizations only' => [
1500,
1,
[
'FR: Interne',
]
],
];
}

/**
* @param int $pageId
* @param int $workspaceId
* @param array $expectation
*
* @dataProvider localizationsAreResolvedDataProvider
* @test
*/
public function localizationsAreResolved(int $pageId, int $workspaceId, array $expectation)
{
$this->backendUser->workspace = $workspaceId;
$record = BackendUtility::getRecordWSOL('pages', $pageId);
$actualResult = array_column(
$this->subject->getLocalizations('pages', $record),
'title'
);
static::assertSame($expectation, $actualResult);
}
}

0 comments on commit b55e146

Please sign in to comment.