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