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