‪TYPO3CMS  ‪main
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 Codeception\Exception\ElementNotFound;
21 use Facebook\WebDriver\Remote\RemoteWebElement;
22 use Facebook\WebDriver\WebDriverBy;
25 
30 {
31  private static string ‪$saveButtonLink = '//*/button[@name="_savedok"][1]';
32 
36  public function ‪_before(‪ApplicationTester $I, ‪PageTree $pageTree): void
37  {
38  $I->useExistingSession('admin');
39 
40  $I->click('List');
41  $pageTree->‪openPath(['styleguide TCA demo', 'elements basic']);
42  $I->switchToContentFrame();
43 
44  // Open record and wait until form is ready
45  $I->waitForText('elements basic', 20);
46  $editRecordLinkCssPath = '#recordlist-tx_styleguide_elements_basic a[aria-label="Edit record"]';
47  $I->click($editRecordLinkCssPath);
48  $I->waitForElementNotVisible('#t3js-ui-block');
49 
50  $I->waitForText('Edit Form', 3, 'h1');
51 
52  // Make sure the test operates on the "text" tab
53  $I->click('text');
54  }
55 
59  private function ‪tableDataProvider(): array
60  {
61  return [
62  ['row1 col1', 'row1 col2'],
63  ['row2 col1', 'row2 col2'],
64  ['row3 col1', 'row3 col2'],
65  ];
66  }
67 
69  {
70  $I->amGoingTo('check for correct data in each column');
71  foreach ($this->‪tableDataProvider() as $keyRow => $row) {
72  foreach ($row as $keyCol => $col) {
73  $input = $this->‪getTable($I)->findElement(WebDriverBy::cssSelector('input[data-row="' . $keyRow . '"][data-col="' . $keyCol . '"]'));
74  $value = $input->getAttribute('value');
75  $I->assertEquals($col, $value);
76  }
77  }
78  }
79 
80  private function ‪addRemoveTableDataProvider(): array
81  {
82  return [
83  [
84  'description' => 'add a column',
85  'click' => 'typo3-backend-table-wizard tr > th:nth-child(2) button[title="Add column to the right"]',
86  'expected' => 9,
87  ],
88  [
89  'description' => 'remove a column',
90  'click' => 'typo3-backend-table-wizard tr > th:nth-child(2) button[title="Remove column"]',
91  'expected' => 6,
92  ],
93  [
94  'description' => 'add a row',
95  'click' => 'typo3-backend-table-wizard tbody tr:first-child > td button[title="Add row below"]',
96  'expected' => 8,
97  ],
98  [
99  'description' => 'remove a row',
100  'click' => 'typo3-backend-table-wizard tbody tr:first-child > td button[title="Remove row"]',
101  'expected' => 6,
102  ],
103  ];
104  }
105 
107  {
108  $formSection = $this->‪getTable($I);
109  $formSection->getLocationOnScreenOnceScrolledIntoView();
110 
111  foreach ($this->‪addRemoveTableDataProvider() as $action) {
112  $I->amGoingTo($action['description']);
113  $formSection->findElement(WebDriverBy::cssSelector($action['click']))->click();
114  $elementCountSelector = count($formSection->findElements(WebDriverBy::cssSelector('typo3-backend-table-wizard td input')));
115  $formSection->getLocationOnScreenOnceScrolledIntoView();
116  $I->assertEquals($elementCountSelector, $action['expected']);
117  }
118  }
119 
121  {
122  $formSection = $this->‪getTable($I);
123  $formSection->getLocationOnScreenOnceScrolledIntoView();
124 
125  $I->fillField('input[data-row="0"][data-col="0"]', 'Test Column 1');
126  $I->fillField('input[data-row="0"][data-col="1"]', 'Test Column 2');
127 
128  $I->amGoingTo('move column to the right');
129  $textOriginColumn = $I->grabValueFrom('input[data-row="0"][data-col="0"]');
130  $I->click('typo3-backend-table-wizard tr > th:nth-child(2) button[title="Move right"]');
131  $I->click(self::$saveButtonLink);
132  try {
133  $I->wait(0.2);
134  $I->click('.close', '#alert-container');
135  } catch (ElementNotFound) {
136  }
137  $textNewColumn = $I->grabValueFrom('input[data-row="0"][data-col="1"]');
138  $I->assertEquals($textOriginColumn, $textNewColumn);
139 
140  $I->amGoingTo('move column to the left');
141  $textOriginColumn = $I->grabValueFrom('input[data-row="0"][data-col="1"]');
142  $I->click('typo3-backend-table-wizard tr > th:nth-child(3) button[title="Move left"]');
143  $I->click(self::$saveButtonLink);
144  try {
145  $I->wait(0.2);
146  $I->click('.close', '#alert-container');
147  } catch (ElementNotFound) {
148  }
149  $textNewColumn = $I->grabValueFrom('input[data-row="0"][data-col="0"]');
150  $I->assertEquals($textOriginColumn, $textNewColumn);
151 
152  $I->amGoingTo('move row down');
153  $textOriginColumn = $I->grabValueFrom('input[data-row="0"][data-col="0"]');
154  $I->click('typo3-backend-table-wizard tbody tr:first-child > td button[title="Move down"]');
155  $I->click(self::$saveButtonLink);
156  try {
157  $I->wait(0.2);
158  $I->click('.close', '#alert-container');
159  } catch (ElementNotFound) {
160  }
161  $textNewColumn = $I->grabValueFrom('input[data-row="1"][data-col="0"]');
162  $I->assertEquals($textOriginColumn, $textNewColumn);
163 
164  $I->amGoingTo('move row up');
165  $textOriginColumn = $I->grabValueFrom('input[data-row="2"][data-col="0"]');
166  $I->click('typo3-backend-table-wizard tbody tr:nth-child(3) > td button[title="Move up"]');
167  $I->click(self::$saveButtonLink);
168  try {
169  $I->wait(0.2);
170  $I->click('.close', '#alert-container');
171  } catch (ElementNotFound) {
172  }
173  $textNewColumn = $I->grabValueFrom('input[data-row="1"][data-col="0"]');
174  $I->assertEquals($textOriginColumn, $textNewColumn);
175  }
176 
181  {
182  $fieldCount = 6;
183  $formSection = $this->‪getTable($I);
184  $formSection->getLocationOnScreenOnceScrolledIntoView();
185 
186  $smallFieldsButton = $this->‪getTable($I)->findElement(WebDriverBy::cssSelector('typo3-backend-table-wizard button[title="Small fields"]'));
187  $smallFieldsButton->click();
188 
189  $textareaFields = $this->‪getTable($I)->findElements(WebDriverBy::cssSelector('typo3-backend-table-wizard td textarea'));
190  $I->assertCount($fieldCount, $textareaFields);
191  $smallFieldsButton->click();
192  $inputFields = $this->‪getTable($I)->findElements(WebDriverBy::cssSelector('typo3-backend-table-wizard td input'));
193  $I->assertCount($fieldCount, $inputFields);
194  }
195 
197  {
198  $I->amGoingTo('check for expected initial columns');
199  $formSection = $this->‪getTable($I);
200  $I->click('button[title="Remove column"]');
201  $I->click('button[title="Remove row"]');
202 
203  $fieldCount = count($formSection->findElements(WebDriverBy::cssSelector('typo3-backend-table-wizard input')));
204 
205  // Styleguide creates 3 rows and 2 columns for this field (3*2=6 input fields).
206  // Removing 1 row and 1 column means 2 rows and 1 column should be left (2*1=2 input fields).
207  $I->assertEquals(2, $fieldCount);
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:68
‪TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine\ElementsBasicInputTextTableCest\clickSmallFieldsButton
‪clickSmallFieldsButton(ApplicationTester $I)
Definition: ElementsBasicInputTextTableCest.php:180
‪TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine
Definition: AbstractElementsBasicCest.php:18
‪TYPO3\CMS\Core\Tests\Acceptance\Support\ApplicationTester
Definition: ApplicationTester.php:28
‪TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine\ElementsBasicInputTextTableCest\seeTableWizardInitialWithoutContent
‪seeTableWizardInitialWithoutContent(ApplicationTester $I)
Definition: ElementsBasicInputTextTableCest.php:196
‪TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine\ElementsBasicInputTextTableCest\getTable
‪getTable(ApplicationTester $I)
Definition: ElementsBasicInputTextTableCest.php:210
‪TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine\ElementsBasicInputTextTableCest\moveTableColumnsAndRows
‪moveTableColumnsAndRows(ApplicationTester $I)
Definition: ElementsBasicInputTextTableCest.php:120
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\AbstractTree\openPath
‪openPath(array $path)
Definition: AbstractTree.php:55
‪TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine\ElementsBasicInputTextTableCest\tableDataProvider
‪tableDataProvider()
Definition: ElementsBasicInputTextTableCest.php:59
‪TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine\ElementsBasicInputTextTableCest\addAndRemoveTableColumnsAndRows
‪addAndRemoveTableColumnsAndRows(ApplicationTester $I)
Definition: ElementsBasicInputTextTableCest.php:106
‪TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine\ElementsBasicInputTextTableCest\addRemoveTableDataProvider
‪addRemoveTableDataProvider()
Definition: ElementsBasicInputTextTableCest.php:80
‪TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine\ElementsBasicInputTextTableCest\$saveButtonLink
‪static string $saveButtonLink
Definition: ElementsBasicInputTextTableCest.php:31
‪TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine\ElementsBasicInputTextTableCest\_before
‪_before(ApplicationTester $I, PageTree $pageTree)
Definition: ElementsBasicInputTextTableCest.php:36
‪TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine\ElementsBasicInputTextTableCest
Definition: ElementsBasicInputTextTableCest.php:30
‪TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine\AbstractElementsBasicCest\getFormSectionByFieldLabel
‪getFormSectionByFieldLabel(ApplicationTester $I, string $fieldLabel)
Definition: AbstractElementsBasicCest.php:102
‪TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine\AbstractElementsBasicCest
Definition: AbstractElementsBasicCest.php:31
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\PageTree
Definition: PageTree.php:26