[TASK] Raise testing-framework and styleguide
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Acceptance / Backend / FormEngine / Inline1nCest.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Core\Tests\Acceptance\Backend\FormEngine;
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
18 use Facebook\WebDriver\WebDriverKeys;
19 use TYPO3\CMS\Core\Tests\Acceptance\Support\BackendTester;
20 use TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\ModalDialog;
21 use TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\PageTree;
22
23 /**
24 * Tests for inline 1n
25 */
26 class Inline1nCest
27 {
28 /**
29 * Open styleguide inline 1n page in list module
30 *
31 * @param BackendTester $I
32 * @param PageTree $pageTree
33 * @throws \Exception
34 */
35 public function _before(BackendTester $I, PageTree $pageTree)
36 {
37 $I->useExistingSession('admin');
38
39 $I->click('List');
40 $I->waitForElement('svg .nodes .node');
41 $pageTree->openPath(['styleguide TCA demo', 'inline 1n']);
42 $I->switchToContentFrame();
43
44 $I->waitForText('inline 1n', 20);
45 $editRecordLinkCssPath = '#recordlist-tx_styleguide_inline_1n a[data-original-title="Edit record"]';
46 $I->click($editRecordLinkCssPath);
47 $I->waitForText('Edit Form', 3, 'h1');
48 }
49
50 /**
51 * @param Admin $I
52 */
53 public function checkIfExpandsAndCollapseShowInput(BackendTester $I)
54 {
55 $I->wantTo('Expands the inline Element');
56 $I->click('div[data-toggle="formengine-inline"]', '#data-52-tx_styleguide_inline_1n-1-inline_1-tx_styleguide_inline_1n_child-1_div');
57 $I->waitForElement('input[data-formengine-input-name="data[tx_styleguide_inline_1n_child][1][input_1]"]');
58 $I->wantTo('check is the value in input');
59 $I->seeInField('input[data-formengine-input-name="data[tx_styleguide_inline_1n_child][1][input_1]"]', 'lipsum');
60 $I->wantTo('Collapse the inline Element');
61 $I->click('div[data-toggle="formengine-inline"]', '#data-52-tx_styleguide_inline_1n-1-inline_1-tx_styleguide_inline_1n_child-1_div');
62 $I->waitForElementNotVisible('#data-52-tx_styleguide_inline_1n-1-inline_1-tx_styleguide_inline_1n_child-1_fields.panel-collapse');
63 }
64
65 /**
66 * @param Admin $I
67 */
68 public function hideAndUnhideInline1nInlineElement(BackendTester $I)
69 {
70 $I->wantTo('Can hide a Inline Element');
71 $I->click('a span[data-identifier="actions-edit-hide"]', '#data-52-tx_styleguide_inline_1n-1-inline_1-tx_styleguide_inline_1n_child-1_div');
72 $I->waitForElement('#data-52-tx_styleguide_inline_1n-1-inline_1_records .t3-form-field-container-inline-hidden');
73 $I->wantTo('Can unhide a Inline Element');
74 $I->click('a span[data-identifier="actions-edit-unhide"]', '#data-52-tx_styleguide_inline_1n-1-inline_1-tx_styleguide_inline_1n_child-1_div');
75 $I->waitForElementNotVisible('#data-52-tx_styleguide_inline_1n-1-inline_1_records .t3-form-field-container-inline-hidden', 2);
76 }
77
78 /**
79 * @param Admin $I
80 */
81 public function createInline1nInlineElement(BackendTester $I)
82 {
83 $I->click('span[data-identifier="actions-add"]', 'div.typo3-newRecordLink');
84
85 $fieldLabel = 'input_1';
86 $testValue = 'Fo Bar';
87
88 $this->fillFieldByLabel($I, $fieldLabel, $testValue);
89
90 $I->click('button[name="_savedok"]');
91 $I->wait(3);
92 $I->click('a[title="Close"]');
93 $I->wait(3);
94
95 $I->executeJS('$(\'a[data-table="pages"] .icon-actions-view-list-collapse\').click();');
96 $I->wait(1);
97 $I->executeJS('$(\'a[data-table="tx_styleguide_inline_1n"] .icon-actions-view-list-collapse\').click();');
98 $I->wait(1);
99
100 $I->see('lipsum', '#recordlist-tx_styleguide_inline_1n_child > div:nth-child(1) > table:nth-child(1) > tbody:nth-child(2) > tr:nth-child(1) > td:nth-child(2) > a');
101 $I->see('Fo Bar', '#recordlist-tx_styleguide_inline_1n_child > div:nth-child(1) > table:nth-child(1) > tbody:nth-child(2) > tr:nth-child(4) > td:nth-child(2) > a');
102 }
103
104 /**
105 * @depends createInline1nInlineElement
106 * @param Admin $I
107 */
108 public function checkIfCanSortingInlineElement(BackendTester $I)
109 {
110 $I->wantTo('Can sort an Inline Element');
111 $I->click('a span[data-identifier="actions-move-down"]', '#data-52-tx_styleguide_inline_1n-1-inline_1-tx_styleguide_inline_1n_child-1_div');
112 $I->click('button[name="_savedok"]');
113 $I->wait(3);
114 $I->click('a[title="Close"]');
115 $I->wait(3);
116
117 $I->executeJS('$(\'a[data-table="pages"] .icon-actions-view-list-collapse\').click();');
118 $I->wait(1);
119 $I->executeJS('$(\'a[data-table="tx_styleguide_inline_1n"] .icon-actions-view-list-collapse\').click();');
120 $I->wait(1);
121
122 $I->wantTo('Check new sorting');
123 $I->see('Fo Bar', '#recordlist-tx_styleguide_inline_1n_child > div:nth-child(1) > table:nth-child(1) > tbody:nth-child(2) > tr:nth-child(1) > td:nth-child(2) > a');
124 $I->see('lipsum', '#recordlist-tx_styleguide_inline_1n_child > div:nth-child(1) > table:nth-child(1) > tbody:nth-child(2) > tr:nth-child(2) > td:nth-child(2) > a');
125 }
126
127 /**
128 * @param Admin $I
129 */
130 public function changeInline1nInlineInput(BackendTester $I)
131 {
132 $I->click('div[data-toggle="formengine-inline"]', '#data-52-tx_styleguide_inline_1n-1-inline_1-tx_styleguide_inline_1n_child-1_div');
133 $I->waitForElement('input[data-formengine-input-name="data[tx_styleguide_inline_1n_child][1][input_1]"]');
134 $I->fillField('input[data-formengine-input-name="data[tx_styleguide_inline_1n_child][1][input_1]"]', 'hello world');
135 $I->click('button[name="_savedok"]');
136 $I->wait(3);
137 $I->click('a[title="Close"]');
138 $I->wait(3);
139 $I->see('hello world');
140 }
141
142 /**
143 * @param Admin $I
144 * @param ModalDialog $modalDialog
145 */
146 public function deleteInline1nInlineElement(BackendTester $I, ModalDialog $modalDialog)
147 {
148 $inlineElementToDelete = '#data-52-tx_styleguide_inline_1n-1-inline_1-tx_styleguide_inline_1n_child-1_div';
149 $I->wantTo('Cancel the delete dialog');
150 $I->click('a span[data-identifier="actions-edit-delete"]', $inlineElementToDelete);
151 $modalDialog->clickButtonInDialog('button[name="no"]');
152 // switch form Dialogbox back to IFrame
153 $I->switchToContentFrame();
154 $I->seeElement($inlineElementToDelete);
155
156 $I->wantTo('Accept the delete dialog');
157 $I->click('a span[data-identifier="actions-edit-delete"]', $inlineElementToDelete);
158
159 // don't use $modalDialog->clickButtonInDialog due to too low timeout
160 $modalDialog->canSeeDialog();
161 $I->click('button[name="yes"]', ModalDialog::$openedModalButtonContainerSelector);
162 $I->waitForElementNotVisible(ModalDialog::$openedModalSelector, 30);
163 // switch form Dialogbox back to IFrame
164 $I->switchToContentFrame();
165 $I->waitForElementNotVisible($inlineElementToDelete);
166 }
167
168 /**
169 * @param Admin $I
170 * @param $fieldLabel
171 * @param $testValue
172 */
173 protected function fillFieldByLabel(BackendTester $I, $fieldLabel, $testValue)
174 {
175 $fieldContext = $I->executeInSelenium(function (\Facebook\WebDriver\Remote\RemoteWebDriver $webdriver) use (
176 $fieldLabel
177 ) {
178 return $webdriver->findElement(
179 \Facebook\WebDriver\WebDriverBy::xpath('(//label[contains(text(),"' . $fieldLabel . '")])[1]/ancestor::fieldset[@class="form-section"][1]')
180 );
181 });
182
183 $visibleFieldXpath = './/*/input[@data-formengine-input-name]';
184 $clearButtonXpath = '(//label[contains(text(),"' . $fieldLabel . '")])[1]/parent::*//*/button[@class="close"]';
185 $initializedInputFieldXpath = '(//label[contains(text(),"' . $fieldLabel . '")])[1]/parent::*//*/input[@data-formengine-input-name][@data-formengine-input-initialized]';
186 $I->waitForElement($initializedInputFieldXpath, 30);
187 $inputField = $fieldContext->findElement(\WebDriverBy::xpath($visibleFieldXpath));
188 $internalInputFieldXpath = '(//label[contains(text(),"' . $fieldLabel . '")])[1]/parent::*//*/input[@name="' . $inputField->getAttribute('data-formengine-input-name') . '"]';
189
190 $I->waitForElement($internalInputFieldXpath, 30);
191 $I->waitForElement($clearButtonXpath, 30);
192
193 $I->fillField($inputField, $testValue);
194 $inputField->sendKeys(WebDriverKeys::TAB);
195 $fieldContext->click();
196 $I->comment('Test value of "visible" field');
197 $I->canSeeInField($inputField, $testValue);
198 }
199 }