[TASK] Make failing acceptance tests after image update run again
[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 $I->waitForElementNotVisible('#t3js-ui-block');
57
58 $I->comment('Test value of visible and hidden field');
59 $I->canSeeInField($inputField, $data['expectedValue']);
60 $I->canSeeInField($hiddenField, $data['expectedInternalValue']);
61
62 $I->comment('Save the form');
63 $saveButtonLink = '//*/button[@name="_savedok"][1]';
64 $I->waitForElement($saveButtonLink, 30);
65 $I->click($saveButtonLink);
66 $I->waitForElementNotVisible('#t3js-ui-block');
67 $I->waitForElement('//*/button[@name="_savedok"][not(@disabled)][1]', 30);
68 $I->waitForElement($initializedInputFieldXpath, 30);
69
70 // Find the fields again (after reload of iFrame)
71 $formSection = $this->getFormSectionByFieldLabel($I, $fieldLabel);
72 $inputField = $this->getInputField($formSection);
73 $hiddenField = $this->getHiddenField($formSection, $inputField);
74
75 // Validate save was successful
76 $I->comment('Test value of visible and hidden field');
77 $I->canSeeInField($inputField, $data['expectedValue']);
78 $I->canSeeInField($hiddenField, $data['expectedValueAfterSave']);
79 }
80 }
81 }
82
83 /**
84 * Return the visible input field of element in question.
85 *
86 * @param $formSection
87 * @return RemoteWebElement
88 */
89 protected function getInputField(RemoteWebElement $formSection)
90 {
91 return $formSection->findElement(\WebDriverBy::xpath('.//*/input[@data-formengine-input-name]'));
92 }
93
94 /**
95 * Return the hidden input field of element in question.
96 *
97 * @param RemoteWebElement $formSection
98 * @param RemoteWebElement $inputField
99 * @return RemoteWebElement
100 */
101 protected function getHiddenField(RemoteWebElement $formSection, RemoteWebElement $inputField)
102 {
103 $hiddenFieldXPath = './/*/input[@name="' . $inputField->getAttribute('data-formengine-input-name') . '"]';
104 return $formSection->findElement(\WebDriverBy::xpath($hiddenFieldXPath));
105 }
106
107 /**
108 * Find this element in form.
109 *
110 * @param Admin $I
111 * @param string $fieldLabel
112 * @return RemoteWebElement
113 */
114 protected function getFormSectionByFieldLabel(Admin $I, string $fieldLabel)
115 {
116 $I->comment('Get context for field "' . $fieldLabel . '"');
117 return $I->executeInSelenium(
118 function (RemoteWebDriver $webDriver) use ($fieldLabel) {
119 return $webDriver->findElement(
120 \WebDriverBy::xpath(
121 '(//label[contains(text(),"' . $fieldLabel . '")])[1]/ancestor::fieldset[@class="form-section"][1]'
122 )
123 );
124 }
125 );
126 }
127 }