‪TYPO3CMS  ‪main
ElementsEmptyElementsCest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Codeception\Attribute\DataProvider;
21 use Codeception\Example;
22 use Facebook\WebDriver\WebDriverBy;
23 use Facebook\WebDriver\WebDriverKeys;
26 
31 {
35  public function ‪_before(‪ApplicationTester $I, ‪PageTree $pageTree): void
36  {
37  $I->useExistingSession('admin');
38  $I->click('List');
39  $pageTree->‪openPath(['styleguide TCA demo', 'elements basic']);
40  // Wait until DOM actually rendered everything
41  $I->switchToContentFrame();
42 
43  // Open record and wait until form is ready
44  $I->waitForText('elements basic', 20);
45  $editRecordLinkCssPath = '#recordlist-tx_styleguide_elements_basic a[aria-label="Edit record"]';
46  $I->click($editRecordLinkCssPath);
47  $I->waitForElementNotVisible('#t3js-ui-block');
48  $I->waitForText('Edit Form', 3, 'h1');
49 
50  // Make sure the test operates on the "radio" tab
51  $I->click('radio');
52  }
53 
57  private function ‪runRadioFieldTest(‪ApplicationTester $I, Example $testData): void
58  {
59  $fieldLabel = $testData['label'];
60  $waitElementXpath = '(//legend/code[contains(text(),"[' . $fieldLabel . ']")]/..)';
61  $initializedInputFieldXpath = $waitElementXpath
62  . '[1]/parent::*//*/input[@value="' . $testData['inputValue'] . '"]';
63 
64  // If we expect to not find a radio button, enforce this step to succeed and quit.
65  // Else, we expect a valid radio element and can continue.
66  if ($testData['expectedValue'] === false) {
67  $I->dontSeeElement($initializedInputFieldXpath);
68  return;
69  }
70 
71  // Wait until JS initialized everything
72  $I->waitForElement($waitElementXpath, 30);
73 
74  if ($testData['comment'] !== '') {
75  $I->comment($testData['comment']);
76  }
77 
78  $formSection = $this->‪getFormSectionByFieldLabel($I, $fieldLabel);
79 
80  $I->comment('Check radio button ' . $fieldLabel . ' with value "' . $testData['inputValue'] . '"');
81  $I->seeElement($initializedInputFieldXpath);
82 
83  $radioField = $formSection->findElement(WebDriverBy::xpath($initializedInputFieldXpath));
84  $radioField->click();
85  // Change focus to trigger validation
86  $radioField->sendKeys(WebDriverKeys::TAB);
87  // Press ESC so that any opened popup (potentially from the field below) is closed
88  $radioField->sendKeys(WebDriverKeys::ESCAPE);
89  $I->waitForElementNotVisible('#t3js-ui-block');
90 
91  $I->comment('Test value radio field before saving');
92  $I->assertEquals($testData['expectedValue'], $radioField->isSelected());
93 
94  $I->comment('Save the form');
95  $saveButtonLink = '//*/button[@name="_savedok"][1]';
96  $I->waitForElement($saveButtonLink, 30);
97  $I->click($saveButtonLink);
98  $I->waitForElementNotVisible('#t3js-ui-block');
99  $I->waitForElement('//*/button[@name="_savedok"][not(@disabled)][1]', 30);
100  $I->waitForElement($waitElementXpath, 30);
101 
102  // Find the fields again (after reload of iFrame)
103  $formSection = $this->‪getFormSectionByFieldLabel($I, $fieldLabel);
104  $I->seeElement($initializedInputFieldXpath);
105  $radioField = $formSection->findElement(WebDriverBy::xpath($initializedInputFieldXpath));
106 
107  // Validate save was successful
108  $I->comment('Compare value radio state after saving');
109  $I->assertEquals($testData['expectedValue'], $radioField->isSelected());
110  }
111 
116  private function ‪simpleRadioFieldsDataProvider(): array
117  {
118  return [
119  [
120  'label' => 'radio_4',
121  'inputValue' => 'foo',
122  'expectedValue' => true,
123  'comment' => 'Existing radio, selectable',
124  ],
125  [
126  'label' => 'radio_4',
127  'inputValue' => '',
128  'expectedValue' => true,
129  'comment' => 'Existing radio, empty selectable',
130  ],
131  [
132  'label' => 'radio_4',
133  'inputValue' => 'foob',
134  'expectedValue' => false,
135  'comment' => 'Existing radio, invalid value',
136  ],
137  [
138  'label' => 'non_existing_radio_4',
139  'inputValue' => 'foo',
140  'expectedValue' => false,
141  'comment' => 'Non-existing radio',
142  ],
143  ];
144  }
145 
146  #[DataProvider('simpleRadioFieldsDataProvider')]
147  public function ‪simpleRadioFields(‪ApplicationTester $I, Example $testData): void
148  {
149  $this->‪runRadioFieldTest($I, $testData);
150  }
151 }
‪TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine
Definition: AbstractElementsBasicCest.php:18
‪TYPO3\CMS\Core\Tests\Acceptance\Support\ApplicationTester
Definition: ApplicationTester.php:28
‪TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine\ElementsEmptyElementsCest\_before
‪_before(ApplicationTester $I, PageTree $pageTree)
Definition: ElementsEmptyElementsCest.php:35
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\AbstractTree\openPath
‪openPath(array $path)
Definition: AbstractTree.php:55
‪TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine\ElementsEmptyElementsCest\simpleRadioFields
‪simpleRadioFields(ApplicationTester $I, Example $testData)
Definition: ElementsEmptyElementsCest.php:147
‪TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine\ElementsEmptyElementsCest\runRadioFieldTest
‪runRadioFieldTest(ApplicationTester $I, Example $testData)
Definition: ElementsEmptyElementsCest.php:57
‪TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine\AbstractElementsBasicCest\getFormSectionByFieldLabel
‪getFormSectionByFieldLabel(ApplicationTester $I, string $fieldLabel)
Definition: AbstractElementsBasicCest.php:102
‪TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine\AbstractElementsBasicCest
Definition: AbstractElementsBasicCest.php:31
‪TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine\ElementsEmptyElementsCest
Definition: ElementsEmptyElementsCest.php:31
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\PageTree
Definition: PageTree.php:26
‪TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine\ElementsEmptyElementsCest\simpleRadioFieldsDataProvider
‪simpleRadioFieldsDataProvider()
Definition: ElementsEmptyElementsCest.php:116