‪TYPO3CMS  ‪main
FormFrameworkCest.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 Facebook\WebDriver\Remote\RemoteWebDriver;
23 
25 {
26  private string ‪$sidebarSelector = '.sidebar.list-group';
27  private string ‪$nameSelector = '[id^=simpleform] input[placeholder="Name"]';
28  private string ‪$subjectSelector = '[id^=simpleform] input[placeholder="Subject"]';
29  private string ‪$emailSelector = '[id^=simpleform] input[placeholder="Email address"]';
30  private string ‪$textareaSelector = '[id^=simpleform] textarea';
31  private string ‪$submitSelector = '[id^=simpleform] button[type=submit]:not([formnovalidate])';
32  private string ‪$summaryValueSelector = '[id^=simpleform] table td:not(.summary-table-first-col)';
33 
34  public function ‪_before(‪ApplicationTester $I, ‪PageTree $pageTree): void
35  {
36  $I->useExistingSession('admin');
37  $I->click('Page');
38  $pageTree->‪openPath(['styleguide frontend demo']);
39  $I->switchToContentFrame();
40  $I->waitForElementVisible('select[name=actionMenu]');
41  $I->selectOption('select[name=actionMenu]', 'Layout');
42  $I->waitForElementVisible('.t3js-module-docheader-bar a[title="View webpage"]');
43  $I->wait(1);
44  $I->click('.t3js-module-docheader-bar a[title="View webpage"]');
45  $I->wait(1);
46  $I->executeInSelenium(static function (RemoteWebDriver $webdriver) {
47  $handles = $webdriver->getWindowHandles();
48  $lastWindow = end($handles);
49  $webdriver->switchTo()->window($lastWindow);
50  });
51  $I->wait(1);
52  $I->see('TYPO3 Styleguide Frontend', '.content');
53  $I->scrollTo('//a[contains(., "form_formframework")]');
54  $I->click('form_formframework', $this->sidebarSelector);
55  }
56 
57  public function ‪_after(‪ApplicationTester $I): void
58  {
59  // Close FE tab again and switch to BE to avoid side effects
60  $I->executeInSelenium(static function (RemoteWebDriver $webdriver) {
61  $handles = $webdriver->getWindowHandles();
62  // Avoid closing the main backend tab (holds the webdriver session) if the test failed to open the frontend tab
63  // (All subsequent tests would fail with "[Facebook\WebDriver\Exception\InvalidSessionIdException] invalid session id"
64  if (count($handles) > 1) {
65  $webdriver->close();
66  $firstWindow = current($handles);
67  $webdriver->switchTo()->window($firstWindow);
68  }
69  });
70  }
71 
72  public function ‪sentInvalidForm(‪ApplicationTester $I): void
73  {
74  $mandatory = 'This field is mandatory.';
75  $mandatoryEmail = 'You must enter a valid email address.';
76 
77  $I->fillField($this->emailSelector, 'invalid mail');
78  $I->click($this->submitSelector);
79  $I->see($mandatory, $this->nameSelector . ' + div');
80  $I->see($mandatory, $this->subjectSelector . ' + div');
81  $I->see($mandatoryEmail, $this->emailSelector . ' + div');
82  $I->see($mandatory, $this->textareaSelector . ' + div');
83  }
84 
85  public function ‪sentValidForm(‪ApplicationTester $I): void
86  {
87  $name = 'Jane Doe';
88  $subject = 'Welcome to TYPO3';
89  $email = 'jane.doe@example.org';
90  $message = 'Happy to have you!';
91 
92  $I->fillField($this->nameSelector, $name);
93  $I->fillField($this->subjectSelector, $subject);
94  $I->fillField($this->emailSelector, $email);
95  $I->fillField($this->textareaSelector, $message);
96 
97  $I->click($this->submitSelector);
98  $I->see($name, $this->summaryValueSelector);
99  $I->see($subject, $this->summaryValueSelector);
100  $I->see($email, $this->summaryValueSelector);
101  $I->see($email, $this->summaryValueSelector);
102 
103  $I->click($this->submitSelector);
104  $I->see('E-Mail sent', '[id^=simpleform]');
105  }
106 }
‪TYPO3\CMS\Core\Tests\Acceptance\Application\Frontend\FormFrameworkCest\$textareaSelector
‪string $textareaSelector
Definition: FormFrameworkCest.php:30
‪TYPO3\CMS\Core\Tests\Acceptance\Application\Frontend\FormFrameworkCest\$submitSelector
‪string $submitSelector
Definition: FormFrameworkCest.php:31
‪TYPO3\CMS\Core\Tests\Acceptance\Application\Frontend
Definition: ContentElementsCest.php:18
‪TYPO3\CMS\Core\Tests\Acceptance\Support\ApplicationTester
Definition: ApplicationTester.php:28
‪TYPO3\CMS\Core\Tests\Acceptance\Application\Frontend\FormFrameworkCest\_before
‪_before(ApplicationTester $I, PageTree $pageTree)
Definition: FormFrameworkCest.php:34
‪TYPO3\CMS\Core\Tests\Acceptance\Application\Frontend\FormFrameworkCest\$subjectSelector
‪string $subjectSelector
Definition: FormFrameworkCest.php:28
‪TYPO3\CMS\Core\Tests\Acceptance\Application\Frontend\FormFrameworkCest\sentValidForm
‪sentValidForm(ApplicationTester $I)
Definition: FormFrameworkCest.php:85
‪TYPO3\CMS\Core\Tests\Acceptance\Application\Frontend\FormFrameworkCest\_after
‪_after(ApplicationTester $I)
Definition: FormFrameworkCest.php:57
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\AbstractTree\openPath
‪openPath(array $path)
Definition: AbstractTree.php:55
‪TYPO3\CMS\Core\Tests\Acceptance\Application\Frontend\FormFrameworkCest
Definition: FormFrameworkCest.php:25
‪TYPO3\CMS\Core\Tests\Acceptance\Application\Frontend\FormFrameworkCest\sentInvalidForm
‪sentInvalidForm(ApplicationTester $I)
Definition: FormFrameworkCest.php:72
‪TYPO3\CMS\Core\Tests\Acceptance\Application\Frontend\FormFrameworkCest\$summaryValueSelector
‪string $summaryValueSelector
Definition: FormFrameworkCest.php:32
‪TYPO3\CMS\Core\Tests\Acceptance\Application\Frontend\FormFrameworkCest\$sidebarSelector
‪string $sidebarSelector
Definition: FormFrameworkCest.php:26
‪TYPO3\CMS\Core\Tests\Acceptance\Application\Frontend\FormFrameworkCest\$emailSelector
‪string $emailSelector
Definition: FormFrameworkCest.php:29
‪TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\PageTree
Definition: PageTree.php:26
‪TYPO3\CMS\Core\Tests\Acceptance\Application\Frontend\FormFrameworkCest\$nameSelector
‪string $nameSelector
Definition: FormFrameworkCest.php:27