Skip to content

Commit

Permalink
[BUGFIX] Fix PHP 8.0 warning with inline sychronize
Browse files Browse the repository at this point in the history
Scenario:
* Add a content element with an image in default language.
* Translate the content element to some other language,
  this will create the image in the localized element, too.
* Edit the default language element and add another image.
* Edit the localized element, see the 'shadowed' new image,
  click "localize" button on the right.
-> Red error pop up, logged warning: "Array to string
conversion" in FormInlineAjaxController.php

The patch fixes this, and adds two acceptance tests to
have a basic coverage for the new content element wizard,
the element browser inline image selection, and the
localization 'synchronize' process.

Change-Id: I9c930d3b7b625b96b6321c14c455d0e62f70b5dc
Resolves: #97090
Releases: main, 11.5
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/73803
Tested-by: core-ci <typo3@b13.com>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
  • Loading branch information
lolli42 committed Mar 3, 2022
1 parent da8be96 commit 4310191
Show file tree
Hide file tree
Showing 4 changed files with 192 additions and 6 deletions.
5 changes: 0 additions & 5 deletions Build/phpstan/phpstan-baseline.neon
Expand Up @@ -75,11 +75,6 @@ parameters:
count: 1
path: ../../typo3/sysext/backend/Classes/Controller/File/ThumbnailController.php

-
message: "#^Call to function is_array\\(\\) with string\\|null will always evaluate to false\\.$#"
count: 1
path: ../../typo3/sysext/backend/Classes/Controller/FormInlineAjaxController.php

-
message: "#^Parameter \\#1 \\.\\.\\.\\$expressions of method TYPO3\\\\CMS\\\\Core\\\\Database\\\\Query\\\\Expression\\\\ExpressionBuilder\\:\\:orX\\(\\) expects string, TYPO3\\\\CMS\\\\Core\\\\Database\\\\Query\\\\Expression\\\\CompositeExpression given\\.$#"
count: 1
Expand Down
Expand Up @@ -355,7 +355,7 @@ public function synchronizeLocalizeAction(ServerRequestInterface $request): Resp

// Get the name of the field used as foreign selector (if any):
$foreignSelector = isset($parentConfig['foreign_selector']) && $parentConfig['foreign_selector'] ? $parentConfig['foreign_selector'] : false;
$selectedValue = $foreignSelector ? GeneralUtility::quoteJSvalue($childData['databaseRow'][$foreignSelector]) : null;
$selectedValue = $foreignSelector ? $childData['databaseRow'][$foreignSelector] : null;
if (is_array($selectedValue)) {
$selectedValue = $selectedValue[0];
}
Expand Down
@@ -0,0 +1,119 @@
<?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\Acceptance\Application\FormEngine;

use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\WebDriverBy;
use TYPO3\CMS\Core\Tests\Acceptance\Support\ApplicationTester;
use TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\PageTree;

class InlineContentElementLocalizeSynchronizeCest
{
public function _before(ApplicationTester $I, PageTree $pageTree): void
{
$I->useExistingSession('admin');

$I->click('Page');
$I->waitForElement('svg .nodes .node');
$pageTree->openPath(['styleguide TCA demo', 'staticdata']);
$I->switchToContentFrame();
$I->waitForText('staticdata', 20);
}

public function addingResourceToDefaultLangPageAddResourceToLocalizedPage(ApplicationTester $I): void
{
// Add a content element type images and localize it
$I->click('.module-body td[data-language-uid="0"] span[data-identifier="actions-add"]');
$I->switchToWindow();
$I->waitForText('Images Only');
$I->click('Images Only');
$I->switchToContentFrame();
$I->waitForText('Create new Page Content on page "staticdata"', 3, 'h1');
$I->click('Images');
// Inline add record in Resources tab
$I->click('Images');
$I->click('span[data-identifier="actions-insert-record"]', 'div.active');
$I->switchToWindow();
$I->switchToIFrame('modal_frame');
// Find page 'styleguide' in page tree of modal and click it
$context = $I->executeInSelenium(function (RemoteWebDriver $webdriver) {
$context = $webdriver->findElement(WebDriverBy::cssSelector('div.element-browser-main-sidebar'));
return $context->findElement(WebDriverBy::xpath('//*[text()=\'styleguide\']/..'));
});
// Add an image, closes modal again
$context->findElement(WebDriverBy::cssSelector('text.node-name'))->click();
$I->waitForElementVisible('#typo3-filelist a[data-file-name="telephone_box.jpg"]');
$I->click('#typo3-filelist a[data-file-name="telephone_box.jpg"]');
// Save, go back to page
$I->switchToWindow();
$I->switchToContentFrame();
$I->click('.module-docheader a[title="Close"]');
$I->switchToWindow();
$I->waitForText('Save and close');
$I->click('Save and close');
// Switch to "All languages" view and localize content element
$I->switchToContentFrame();
$I->waitForElementVisible('select[name=actionMenu]');
$I->selectOption('select[name=actionMenu]', 'Languages');
$I->waitForElementVisible('select[name=languageMenu]');
$I->selectOption('select[name=languageMenu]', 'All languages');
$I->waitForText('Translate');
$I->click('Translate');
$I->switchToWindow();
$I->waitForText('Localize page "staticdata - language 1" into styleguide demo language danish');
$I->click('span[data-identifier="actions-localize"]');
$I->click('Next');
$I->waitForText('Normal');
$I->click('Next');
$I->switchToContentFrame();
$I->waitForText('(copy 1)');
// Edit default language content element again and add another image
$I->click('.module-body td[data-language-uid="0"] span[data-identifier="actions-open"]');
$I->waitForText('Edit Page Content on page "staticdata"', 3, 'h1');
$I->click('Images');
$I->click('span[data-identifier="actions-insert-record"]', 'div.active');
$I->switchToWindow();
$I->switchToIFrame('modal_frame');
// Find page 'styleguide' in page tree of modal and click it
$context = $I->executeInSelenium(function (RemoteWebDriver $webdriver) {
$context = $webdriver->findElement(WebDriverBy::cssSelector('div.element-browser-main-sidebar'));
return $context->findElement(WebDriverBy::xpath('//*[text()=\'styleguide\']/..'));
});
// Add an image, closes modal again
$context->findElement(WebDriverBy::cssSelector('text.node-name'))->click();
$I->waitForElementVisible('#typo3-filelist a[data-file-name="underground.jpg"]');
$I->click('#typo3-filelist a[data-file-name="underground.jpg"]');
// Save, go back to page
$I->switchToWindow();
$I->switchToContentFrame();
$I->click('.module-docheader a[title="Close"]');
$I->switchToWindow();
$I->waitForText('Save and close');
$I->click('Save and close');
// Open the localized element and see that the second image can be synchronized
$I->switchToContentFrame();
$I->waitForText('(copy 1)');
$I->click('.module-body td[data-language-uid="1"] span[data-identifier="actions-open"]');
$I->waitForText('Edit Page Content " (copy 1)" on page "staticdata"', 3, 'h1');
$I->click('Images');
$I->waitForText('underground.jpg');
$I->click('span[data-identifier="actions-document-localize"]');
// Synchronized image has been opened
$I->waitForText('Image Metadata');
}
}
@@ -0,0 +1,72 @@
<?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\Acceptance\Application\FormEngine;

use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\WebDriverBy;
use TYPO3\CMS\Core\Tests\Acceptance\Support\ApplicationTester;
use TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\PageTree;

class InlinePagesLocalizeResourceCest
{
public function _before(ApplicationTester $I, PageTree $pageTree): void
{
$I->useExistingSession('admin');

$I->click('List');
$I->waitForElement('svg .nodes .node');
$pageTree->openPath(['styleguide TCA demo', 'staticdata']);
$I->switchToContentFrame();
$I->waitForText('staticdata', 20);
}

public function addingResourceToDefaultLangPageAddResourceToLocalizedPage(ApplicationTester $I): void
{
// Add an image to media field of default lang page
$I->click('.module-docheader a[title="Edit page properties"]');
$I->waitForText('Edit Page "staticdata"', 3, 'h1');
// Inline add record in Resources tab
$I->click('Resources');
$I->click('span[data-identifier="actions-insert-record"]', 'div.active');
$I->switchToWindow();
$I->switchToIFrame('modal_frame');
// Find page 'styleguide' in page tree of modal and click it
$context = $I->executeInSelenium(function (RemoteWebDriver $webdriver) {
$context = $webdriver->findElement(WebDriverBy::cssSelector('div.element-browser-main-sidebar'));
return $context->findElement(WebDriverBy::xpath('//*[text()=\'styleguide\']/..'));
});
// Add an image, closes modal again
$context->findElement(WebDriverBy::cssSelector('text.node-name'))->click();
$I->waitForElementVisible('#typo3-filelist a[data-file-name="telephone_box.jpg"]');
$I->click('#typo3-filelist a[data-file-name="telephone_box.jpg"]');
// Save, go back to list
$I->switchToWindow();
$I->switchToContentFrame();
$I->click('.module-docheader a[title="Close"]');
$I->switchToWindow();
$I->waitForText('Save and close');
$I->click('Save and close');
// Edit the page translation and see if that resource has been added.
$I->switchToContentFrame();
$I->waitForText('staticdata - language 1');
$I->click('staticdata - language 1');
$I->waitForText('Edit Page "staticdata - language 1"', 3, 'h1');
$I->click('Resources');
$I->see('telephone_box.jpg');
}
}

0 comments on commit 4310191

Please sign in to comment.