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