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