[!!!][FEATURE] Replace ExtJS page tree
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Acceptance / Backend / Formhandler / AbstractElementsBasicCest.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\Remote\RemoteWebDriver;
18 use Facebook\WebDriver\Remote\RemoteWebElement;
19 use Facebook\WebDriver\WebDriverKeys;
20 use TYPO3\TestingFramework\Core\Acceptance\Step\Backend\Admin;
21
22 /**
23 * Abstract class for "elements_basic" tests of styleguide
24 */
25 abstract class AbstractElementsBasicCest
26 {
27 /**
28 * Execute given test sets.
29 * Incoming array operates on fields of ext:styleguide, each field can have multiple test tests.
30 *
31 * @param Admin $I
32 * @param array $dataSets
33 */
34 protected function runTests(Admin $I, array $dataSets)
35 {
36 foreach ($dataSets as $fieldLabel => $testData) {
37 $initializedInputFieldXpath = '(//label[contains(text(),"' . $fieldLabel . '")])'
38 . '[1]/parent::*//*/input[@data-formengine-input-name][@data-formengine-input-initialized]';
39 foreach ($testData as $data) {
40 // Wait until JS initialized everything
41 $I->waitForElement($initializedInputFieldXpath, 30);
42
43 $formSection = $this->getFormSectionByFieldLabel($I, $fieldLabel);
44 $inputField = $this->getInputField($formSection);
45 $hiddenField = $this->getHiddenField($formSection, $inputField);
46
47 if ($data['comment'] !== '') {
48 $I->comment($data['comment']);
49 }
50
51 $I->fillField($inputField, $data['inputValue']);
52 // Change focus to trigger validation
53 $inputField->sendKeys(WebDriverKeys::TAB);
54 // Click on the div so that any opened popup (potentially from the field below) is closed
55 $formSection->click();
56
57 $I->comment('Test value of visible and hidden field');
58 $I->canSeeInField($inputField, $data['expectedValue']);
59 $I->canSeeInField($hiddenField, $data['expectedInternalValue']);
60
61 $I->comment('Save the form');
62 $saveButtonLink = '//*/button[@name="_savedok"][1]';
63 $I->waitForElement($saveButtonLink, 30);
64 $I->click($saveButtonLink);
65 $I->waitForElement('//*/button[@name="_savedok"][not(@disabled)][1]', 30);
66 $I->waitForElement($initializedInputFieldXpath, 30);
67
68 // Find the fields again (after reload of iFrame)
69 $formSection = $this->getFormSectionByFieldLabel($I, $fieldLabel);
70 $inputField = $this->getInputField($formSection);
71 $hiddenField = $this->getHiddenField($formSection, $inputField);
72
73 // Validate save was successful
74 $I->comment('Test value of visible and hidden field');
75 $I->canSeeInField($inputField, $data['expectedValue']);
76 $I->canSeeInField($hiddenField, $data['expectedValueAfterSave']);
77 }
78 }
79 }
80
81 /**
82 * Return the visible input field of element in question.
83 *
84 * @param $formSection
85 * @return RemoteWebElement
86 */
87 protected function getInputField(RemoteWebElement $formSection)
88 {
89 return $formSection->findElement(\WebDriverBy::xpath('.//*/input[@data-formengine-input-name]'));
90 }
91
92 /**
93 * Return the hidden input field of element in question.
94 *
95 * @param RemoteWebElement $formSection
96 * @param RemoteWebElement $inputField
97 * @return RemoteWebElement
98 */
99 protected function getHiddenField(RemoteWebElement $formSection, RemoteWebElement $inputField)
100 {
101 $hiddenFieldXPath = './/*/input[@name="' . $inputField->getAttribute('data-formengine-input-name') . '"]';
102 return $formSection->findElement(\WebDriverBy::xpath($hiddenFieldXPath));
103 }
104
105 /**
106 * Find this element in form.
107 *
108 * @param Admin $I
109 * @param string $fieldLabel
110 * @return RemoteWebElement
111 */
112 protected function getFormSectionByFieldLabel(Admin $I, string $fieldLabel)
113 {
114 $I->comment('Get context for field "' . $fieldLabel . '"');
115 return $I->executeInSelenium(
116 function (RemoteWebDriver $webDriver) use ($fieldLabel) {
117 return $webDriver->findElement(
118 \WebDriverBy::xpath(
119 '(//label[contains(text(),"' . $fieldLabel . '")])[1]/ancestor::fieldset[@class="form-section"][1]'
120 )
121 );
122 }
123 );
124 }
125 }