‪TYPO3CMS  11.5
ElementsBasicInputTextTableCest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Facebook\WebDriver\Remote\RemoteWebElement;
21 use Facebook\WebDriver\WebDriverBy;
24 
29 {
30  protected static string ‪$saveButtonLink = '//*/button[@name="_savedok"][1]';
31 
39  public function ‪_before(‪ApplicationTester $I, ‪PageTree $pageTree): void
40  {
41  $I->useExistingSession('admin');
42 
43  $I->click('List');
44  $I->waitForElement('svg .nodes .node');
45  $pageTree->‪openPath(['styleguide TCA demo', 'elements basic']);
46  $I->switchToContentFrame();
47 
48  // Open record and wait until form is ready
49  $I->waitForText('elements basic', 20);
50  $editRecordLinkCssPath = '#recordlist-tx_styleguide_elements_basic a[aria-label="Edit record"]';
51  $I->click($editRecordLinkCssPath);
52  $I->waitForElementNotVisible('#t3js-ui-block');
53 
54  $I->waitForText('Edit Form', 3, 'h1');
55 
56  // Make sure the test operates on the "text" tab
57  $I->click('text');
58  }
59 
64  {
65  $I->amGoingTo('check for correct data in each column');
66  foreach ($this->‪tableDataProvider() as $keyRow => $row) {
67  foreach ($row as $keyCol => $col) {
68  $input = $this->‪getTable($I)->findElement(WebDriverBy::cssSelector('input[name="TABLE[c][' . $keyRow . '][' . $keyCol . ']"]'));
69  $value = $input->getAttribute('value');
70  $I->assertEquals($col, $value);
71  }
72  }
73  }
74 
79  {
80  $formSection = $this->‪getTable($I);
81  $formSection->getLocationOnScreenOnceScrolledIntoView();
82 
83  foreach ($this->‪addRemoveTableDataProvider() as $action) {
84  $I->amGoingTo($action['description']);
85  $formSection->findElement(WebDriverBy::cssSelector($action['click']))->click();
86  $elementCountSelector = count($formSection->findElements(WebDriverBy::cssSelector('typo3-backend-table-wizard td input')));
87  $formSection->getLocationOnScreenOnceScrolledIntoView();
88  $I->assertEquals($elementCountSelector, $action['expected']);
89  }
90  }
91 
96  {
97  $formSection = $this->‪getTable($I);
98  $formSection->getLocationOnScreenOnceScrolledIntoView();
99 
100  $I->fillField('input[name="TABLE[c][0][0]"]', 'Test Column 1');
101  $I->fillField('input[name="TABLE[c][0][1]"]', 'Test Column 2');
102 
103  $I->amGoingTo('move column to the right');
104  $textOriginColumn = $I->grabValueFrom('input[name="TABLE[c][0][0]"]');
105  $I->click('typo3-backend-table-wizard tr > th:nth-child(2) button[title="Move right"]');
106  $I->click(self::$saveButtonLink);
107  $textNewColumn = $I->grabValueFrom('input[name="TABLE[c][0][1]"]');
108  $I->assertEquals($textOriginColumn, $textNewColumn);
109 
110  $I->amGoingTo('move column to the left');
111  $textOriginColumn = $I->grabValueFrom('input[name="TABLE[c][0][1]"]');
112  $I->click('typo3-backend-table-wizard tr > th:nth-child(3) button[title="Move left"]');
113  $I->click(self::$saveButtonLink);
114  $textNewColumn = $I->grabValueFrom('input[name="TABLE[c][0][0]"]');
115  $I->assertEquals($textOriginColumn, $textNewColumn);
116 
117  $I->amGoingTo('move row down');
118  $textOriginColumn = $I->grabValueFrom('input[name="TABLE[c][0][0]"]');
119  $I->click('typo3-backend-table-wizard tbody tr:first-child > th button[title="Move down"]');
120  $I->click(self::$saveButtonLink);
121  $textNewColumn = $I->grabValueFrom('input[name="TABLE[c][1][0]"]');
122  $I->assertEquals($textOriginColumn, $textNewColumn);
123 
124  $I->amGoingTo('move row up');
125  $textOriginColumn = $I->grabValueFrom('input[name="TABLE[c][2][0]"]');
126  $I->click('typo3-backend-table-wizard tbody tr:nth-child(3) > th button[title="Move up"]');
127  $I->click(self::$saveButtonLink);
128  $textNewColumn = $I->grabValueFrom('input[name="TABLE[c][1][0]"]');
129  $I->assertEquals($textOriginColumn, $textNewColumn);
130  }
131 
140  {
141  $fieldCount = 6;
142  $formSection = $this->‪getTable($I);
143  $formSection->getLocationOnScreenOnceScrolledIntoView();
144 
145  $smallFieldsButton = $this->‪getTable($I)->findElement(WebDriverBy::cssSelector('typo3-backend-table-wizard button[title="Small fields"]'));
146  $smallFieldsButton->click();
147 
148  $textareaFields = $this->‪getTable($I)->findElements(WebDriverBy::cssSelector('typo3-backend-table-wizard td textarea'));
149  $I->assertCount($fieldCount, $textareaFields);
150  $smallFieldsButton->click();
151  $inputFields = $this->‪getTable($I)->findElements(WebDriverBy::cssSelector('typo3-backend-table-wizard td input'));
152  $I->assertCount($fieldCount, $inputFields);
153  }
154 
159  {
160  $I->amGoingTo('check for expected initial columns');
161  $formSection = $this->‪getTable($I);
162  $I->click('button[title="Remove column"]');
163  $I->click('button[title="Remove row"]');
164 
165  $fieldCount = count($formSection->findElements(WebDriverBy::cssSelector('typo3-backend-table-wizard input')));
166 
167  // Styleguide creates 3 rows and 2 columns for this field (3*2=6 input fields).
168  // Removing 1 row and 1 column means 2 rows and 1 column should be left (2*1=2 input fields).
169  $I->assertEquals(2, $fieldCount);
170  }
171 
172  protected function ‪addRemoveTableDataProvider(): array
173  {
174  return [
175  [
176  'description' => 'add a column',
177  'click' => 'typo3-backend-table-wizard tr > th:nth-child(2) button[title="Add column to the right"]',
178  'expected' => 9,
179  ],
180  [
181  'description' => 'remove a column',
182  'click' => 'typo3-backend-table-wizard tr > th:nth-child(2) button[title="Remove column"]',
183  'expected' => 6,
184  ],
185  [
186  'description' => 'add a row',
187  'click' => 'typo3-backend-table-wizard tbody tr:first-child > th button[title="Add row below"]',
188  'expected' => 8,
189  ],
190  [
191  'description' => 'remove a row',
192  'click' => 'typo3-backend-table-wizard tbody tr:first-child > th button[title="Remove row"]',
193  'expected' => 6,
194  ],
195  ];
196  }
197 
201  protected function ‪tableDataProvider(): array
202  {
203  return [
204  ['row1 col1', 'row1 col2'],
205  ['row2 col1', 'row2 col2'],
206  ['row3 col1', 'row3 col2'],
207  ];
208  }
209 
210  private function ‪getTable(‪ApplicationTester $I): RemoteWebElement
211  {
212  return $this->‪getFormSectionByFieldLabel($I, 'text_17');
213  }
214 }
‪TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine\ElementsBasicInputTextTableCest\seeTableWizardWithContent
‪seeTableWizardWithContent(ApplicationTester $I)
Definition: ElementsBasicInputTextTableCest.php:63
‪TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine\ElementsBasicInputTextTableCest\clickSmallFieldsButton
‪clickSmallFieldsButton(ApplicationTester $I)
Definition: ElementsBasicInputTextTableCest.php:139
‪TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine
Definition: AbstractElementsBasicCest.php:18
‪TYPO3\CMS\Core\Tests\Acceptance\Support\ApplicationTester
Definition: ApplicationTester.php:27
‪TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine\ElementsBasicInputTextTableCest\seeTableWizardInitialWithoutContent
‪seeTableWizardInitialWithoutContent(ApplicationTester $I)
Definition: ElementsBasicInputTextTableCest.php:158
‪TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine\ElementsBasicInputTextTableCest\getTable
‪getTable(ApplicationTester $I)
Definition: ElementsBasicInputTextTableCest.php:210
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\PageTree\openPath
‪openPath(array $path)
Definition: PageTree.php:76
‪TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine\ElementsBasicInputTextTableCest\moveTableColumnsAndRows
‪moveTableColumnsAndRows(ApplicationTester $I)
Definition: ElementsBasicInputTextTableCest.php:95
‪TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine\ElementsBasicInputTextTableCest\tableDataProvider
‪tableDataProvider()
Definition: ElementsBasicInputTextTableCest.php:201
‪TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine\AbstractElementsBasicCest\getFormSectionByFieldLabel
‪RemoteWebElement getFormSectionByFieldLabel(ApplicationTester $I, string $fieldLabel)
Definition: AbstractElementsBasicCest.php:116
‪TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine\ElementsBasicInputTextTableCest\addAndRemoveTableColumnsAndRows
‪addAndRemoveTableColumnsAndRows(ApplicationTester $I)
Definition: ElementsBasicInputTextTableCest.php:78
‪TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine\ElementsBasicInputTextTableCest\addRemoveTableDataProvider
‪addRemoveTableDataProvider()
Definition: ElementsBasicInputTextTableCest.php:172
‪TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine\ElementsBasicInputTextTableCest\$saveButtonLink
‪static string $saveButtonLink
Definition: ElementsBasicInputTextTableCest.php:30
‪TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine\ElementsBasicInputTextTableCest\_before
‪_before(ApplicationTester $I, PageTree $pageTree)
Definition: ElementsBasicInputTextTableCest.php:39
‪TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine\ElementsBasicInputTextTableCest
Definition: ElementsBasicInputTextTableCest.php:29
‪TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine\AbstractElementsBasicCest
Definition: AbstractElementsBasicCest.php:30
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\PageTree
Definition: PageTree.php:31