Commit edc137cb authored by Jochen Roth's avatar Jochen Roth Committed by Christian Kuhn
Browse files

[BUGFIX] Undefined key warning in table wizard for PHP8

Open the table wizard with empty test in the text area
or a click on the save button on table wizard page
thow undefined key warning.
This will avoid php warnings by adding a fallback
value or a check if the key is present.

Added acceptance tests for the table wizard to  make
sure the wizard will work as expected.

Resolves: #94417
Releases: master
Change-Id: I9283c9203f71710c8bffcc74432781d2159dcde7
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/69575


Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
parent ffb59e65
......@@ -264,8 +264,8 @@ class TableController extends AbstractWizardController
protected function getConfiguration(array $row, ServerRequestInterface $request)
{
// Get delimiter settings
$this->tableParsing_quote = $row['table_enclosure'] ? chr((int)$row['table_enclosure']) : '';
$this->tableParsing_delimiter = $row['table_delimiter'] ? chr((int)$row['table_delimiter']) : '|';
$this->tableParsing_quote = ($row['table_enclosure'] ?? false) ? chr((int)$row['table_enclosure']) : '';
$this->tableParsing_delimiter = ($row['table_delimiter'] ?? false) ? chr((int)$row['table_delimiter']) : '|';
// If some data has been submitted, then construct
if (isset($this->TABLECFG['c'])) {
// Process incoming:
......@@ -281,10 +281,10 @@ class TableController extends AbstractWizardController
$bodyText = $this->configurationArrayToString($this->TABLECFG['c']);
// Create cfgArr from the string based configuration - that way it is cleaned up
// and any incompatibilities will be removed!
$configuration = $this->configurationStringToArray($bodyText, (int)$row[$this->colsFieldName]);
$configuration = $this->configurationStringToArray($bodyText, (int)($row[$this->colsFieldName] ?? 0));
}
// If a save button has been pressed, then save the new field content:
if ($_POST['_savedok'] || $_POST['_saveandclosedok']) {
if (($_POST['_savedok'] ?? false) || ($_POST['_saveandclosedok'] ?? false)) {
// Get DataHandler object:
/** @var DataHandler $dataHandler */
$dataHandler = GeneralUtility::makeInstance(DataHandler::class);
......@@ -304,7 +304,7 @@ class TableController extends AbstractWizardController
$dataHandler->start($data, []);
$dataHandler->process_datamap();
// If the save/close button was pressed, then redirect the screen:
if ($_POST['_saveandclosedok']) {
if ($_POST['_saveandclosedok'] ?? false) {
return new RedirectResponse(GeneralUtility::sanitizeLocalUrl($this->P['returnUrl']));
}
}
......@@ -426,7 +426,7 @@ class TableController extends AbstractWizardController
) {
$valueParts[$a] = substr(trim($valueParts[$a]), 1, -1);
}
$configurationArray[$key][$a] = (string)$valueParts[$a];
$configurationArray[$key][$a] = (string)($valueParts[$a] ?? '');
}
}
return $configurationArray;
......
<?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\Backend\FormEngine;
use Facebook\WebDriver\WebDriverBy;
use TYPO3\CMS\Core\Tests\Acceptance\Support\BackendTester;
use TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\PageTree;
/**
* Tests for table wizard
*/
class ElementsBasicInputTextTableCest extends AbstractElementsBasicCest
{
protected static string $saveButtonLink = '//*/button[@name="_savedok"][1]';
/**
* Open styleguide elements basic page in list module
*
* @param BackendTester $I
* @param PageTree $pageTree
* @throws \Exception
*/
public function _before(BackendTester $I, PageTree $pageTree)
{
$I->useExistingSession('admin');
$I->click('List');
$I->waitForElement('svg .nodes .node');
$pageTree->openPath(['styleguide TCA demo', 'elements basic']);
$I->switchToContentFrame();
// Open record and wait until form is ready
$I->waitForText('elements basic', 20);
$editRecordLinkCssPath = '#recordlist-tx_styleguide_elements_basic a[data-bs-original-title="Edit record"]';
$I->click($editRecordLinkCssPath);
$I->waitForElementNotVisible('#t3js-ui-block');
$I->waitForText('Edit Form', 3, 'h1');
// scroll up all the way to get a clean shot to the tab panel
$I->executeJS('document.querySelector(".module h1").scrollIntoView({ block: "end" });');
$I->click('text');
}
/**
* @param BackendTester $I
*/
public function seeTableWizardWithContent(BackendTester $I)
{
$this->openTableWizard($I);
$I->amGoingTo('check for correct data in each column');
foreach ($this->tableDataProvider() as $keyRow => $row) {
foreach ($row as $keyCol => $col) {
$value = $I->grabValueFrom('input[name="TABLE[c][' . $keyRow . '][' . $keyCol . ']"]');
$I->assertEquals($col, $value);
}
}
}
/**
* @param BackendTester $I
*/
public function addAndRemoveTableColumnsAndRows(BackendTester $I)
{
$this->openTableWizard($I);
$elementCountSelector = '#typo3-tablewizard td input';
foreach ($this->addRemoveTableDataProvider() as $action) {
$I->amGoingTo($action['description']);
$I->click($action['click']);
$I->click(self::$saveButtonLink);
$I->canSeeNumberOfElements($elementCountSelector, $action['expected']);
}
}
/**
* @param BackendTester $I
*/
public function moveTableColumnsAndRows(BackendTester $I)
{
$this->openTableWizard($I);
$I->fillField('input[name="TABLE[c][0][0]"]', 'Test Column 1');
$I->fillField('input[name="TABLE[c][0][1]"]', 'Test Column 2');
$I->amGoingTo('move column to the right');
$textOriginColumn = $I->grabValueFrom('input[name="TABLE[c][0][0]"]');
$I->click('#typo3-tablewizard tr > th:nth-child(2) button[title="Move right"]');
$I->click(self::$saveButtonLink);
$textNewColumn = $I->grabValueFrom('input[name="TABLE[c][0][1]"]');
$I->assertEquals($textOriginColumn, $textNewColumn);
$I->amGoingTo('move column to the left');
$textOriginColumn = $I->grabValueFrom('input[name="TABLE[c][0][1]"]');
$I->click('#typo3-tablewizard tr > th:nth-child(3) button[title="Move left"]');
$I->click(self::$saveButtonLink);
$textNewColumn = $I->grabValueFrom('input[name="TABLE[c][0][0]"]');
$I->assertEquals($textOriginColumn, $textNewColumn);
$I->amGoingTo('move row down');
$textOriginColumn = $I->grabValueFrom('input[name="TABLE[c][0][0]"]');
$I->click('#typo3-tablewizard tbody tr:first-child > th button[title="Move down"]');
$I->click(self::$saveButtonLink);
$textNewColumn = $I->grabValueFrom('input[name="TABLE[c][1][0]"]');
$I->assertEquals($textOriginColumn, $textNewColumn);
$I->amGoingTo('move row up');
$textOriginColumn = $I->grabValueFrom('input[name="TABLE[c][2][0]"]');
$I->click('#typo3-tablewizard tbody tr:nth-child(3) > th button[title="Move up"]');
$I->click(self::$saveButtonLink);
$textNewColumn = $I->grabValueFrom('input[name="TABLE[c][1][0]"]');
$I->assertEquals($textOriginColumn, $textNewColumn);
}
/**
* Click field resize button to see if
* input fields change to textarea
*
* @param BackendTester $I
* @throws \Exception
*/
public function clickSmallFieldsButton(BackendTester $I)
{
$this->openTableWizard($I);
$fieldCount = 6;
$I->click('button[title="Small fields"]');
$I->seeNumberOfElements('#typo3-tablewizard td textarea', $fieldCount);
$I->click('button[title="Small fields"]');
$I->seeNumberOfElements('#typo3-tablewizard td input', $fieldCount);
}
/**
* @param BackendTester $I
*/
public function seeTableWizardInitialWithoutContent(BackendTester $I)
{
$expectedRowFields = ['', '', '', ''];
$I->amGoingTo('check for expected initial columns');
$formSection = $this->getFormSectionByFieldLabel($I, 'text_17');
$textarea = $formSection->findElement(WebDriverBy::xpath('.//*/textarea[@data-formengine-input-name]'));
$I->fillField($textarea, '');
$I->click(self::$saveButtonLink);
$this->openTableWizard($I);
foreach ($expectedRowFields as $keyCol => $col) {
$value = $I->grabValueFrom('input[name="TABLE[c][0][' . $keyCol . ']"]');
$I->assertEquals($col, $value);
}
}
protected function addRemoveTableDataProvider(): array
{
return [
[
'description' => 'add a column',
'click' => '#typo3-tablewizard tr > th:nth-child(2) button[title="Add column to the right"]',
'expected' => 9,
],
[
'description' => 'remove a column',
'click' => '#typo3-tablewizard tr > th:nth-child(2) button[title="Remove column"]',
'expected' => 6,
],
[
'description' => 'add a row',
'click' => '#typo3-tablewizard tbody tr:first-child > th button[title="Add row below"]',
'expected' => 8,
],
[
'description' => 'remove a row',
'click' => '#typo3-tablewizard tbody tr:first-child > th button[title="Remove row"]',
'expected' => 6,
],
];
}
/**
* Provide sample data for table cols/rows to compare with
*/
protected function tableDataProvider(): array
{
return [
['row1 col1', 'row1 col2'],
['row2 col1', 'row2 col2'],
['row3 col1', 'row3 col2'],
];
}
/**
* @param BackendTester $I
* @throws \Exception
*/
private function openTableWizard(BackendTester $I)
{
$I->amGoingTo('open the table wizard');
$formSection = $this->getFormSectionByFieldLabel($I, 'text_17');
$tableWizardButton = $formSection->findElement(WebDriverBy::className('btn-default'));
$tableWizardButton->click();
$I->see('Table wizard', 'h2');
$I->waitForElement('#typo3-tablewizard');
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment