Draft: Issue #3338664: Automated Axe tests in PHPUnit
8 open threads
8 open threads
Adds Axe testing capability to PHPUnit with support for axe.run()
options and the reporting of errors thrown by Axe.
Closes #3338664
Merge request reports
Activity
added 2 commits
added 1007 commits
-
6f36936a...3a9f2bab - 978 commits from branch
project:11.x
- 3a9f2bab...ff03dbce - 19 earlier commits
- 3e3f2f05 - Issue #3338664: Move axe-core to dev dependencies and update constraint
- d764f2e4 - Issue #3338664: Fix @covers reference
- 93340e48 - Issue #3338664: Format javascript
- f27cbe0b - Issue #3338664: Remove dev code
- 75701715 - Issue #3338664: Improve test
- 8979342a - Issue #3338664: Fix phpstan errors
- c35952b5 - Issue #3338664: Fix namespace
- 41d94d25 - Issue #3338664: Fix coding style issues
- 38c81d30 - Issue #3338664: Include yarn for Functional Javascript tests
- 0e3fb748 - Issue #3338664: Redo axe-core installation
Toggle commit list-
6f36936a...3a9f2bab - 978 commits from branch
added 2 commits
added 1 commit
added 26 commits
-
c0c93176...34fa5918 - 25 commits from branch
project:11.x
- c1e9ae3d - Merge branch drupal:11.x into 3338664-automated-a11y-tests-11.x
-
c0c93176...34fa5918 - 25 commits from branch
changed this file in version 11 of the diff
- Resolved by Kent Richards
32 /** 33 * A user with permission to access all admin pages & functionality. 34 * 35 * @var \Drupal\user\UserInterface 36 */ 37 protected UserInterface $user; 38 39 /** 40 * {@inheritdoc} 41 */ 42 protected function setUp(): void { 43 parent::setUp(); 44 45 // Create an admin user and log in. 46 $this->user = $this->drupalCreateUser(admin: TRUE); 47 $this->drupalLogin($this->user); changed this line in version 13 of the diff
- Resolved by Kent Richards
- Resolved by Kent Richards
- Resolved by Kent Richards
- Resolved by Kent Richards
- Resolved by Kent Richards
- Resolved by Kent Richards
167 $exception->getMessage() 168 ); 169 // If above assertion passes, it was an unexpected error. 170 // Re-throw so PHPUnit can handle it. 171 throw $exception; 172 } 173 } 174 175 /** 176 * Data provider. 177 * 178 * @return \Generator 179 * Test scenarios. 180 */ 181 public static function providerAxeCoreTestTraitWithOptions(): \Generator { 182 // The global $base_url isn't available here for some reason. - core/tests/Drupal/Tests/AxeCoreTestTrait.php 0 → 100644
1 <?php 2 3 declare(strict_types=1); 4 5 namespace Drupal\Tests; 6 7 /** 8 * Provides methods to run axe-core tests in the WebDriver. 9 * 10 * This trait is meant to be used only by Functional Javascript test classes. - Resolved by Kent Richards
- core/tests/Drupal/Tests/AxeCoreTestTrait.php 0 → 100644
31 * 'rules' => [ 32 * 'region' => ['enabled' => false] 33 * ] 34 * ] 35 * ```. 36 * 37 * @throws \Behat\Mink\Exception\DriverException 38 * @throws \Behat\Mink\Exception\UnsupportedDriverActionException 39 * 40 * @see https://github.com/dequelabs/axe-core/blob/develop/doc/API.md#options-parameter 41 */ 42 protected function executeAxe(?array $options = NULL): void { 43 $session = $this->getSession(); 44 45 // Load axe-core script. 46 $axe_src = file_get_contents(DRUPAL_ROOT . '/core/node_modules/axe-core/axe.min.js'); - core/tests/Drupal/Tests/AxeCoreTestTrait.php 0 → 100644
56 // Analyze page. 57 axe 58 .run('body', {$options_json}) 59 .then((results) => { 60 window.axe_results = results; 61 }) 62 .catch((e) => { 63 if (window.axe_errors) { 64 window.axe_errors.push(e.message); 65 } else { 66 window.axe_errors = [e.message]; 67 } 68 }); 69 JS); 70 71 $session->wait(1000, 'window.axe_results !== undefined || window.axe_errors !== undefined'); changed this line in version 13 of the diff
- Resolved by Kent Richards
48 * @param array|null $browser_options 49 * (optional) Associative array of browser options. 50 */ 51 #[DataProvider('providerTestAdminPages')] 52 public function testAdminPages(string $uri, array $axe_options = [], ?array $browser_options = NULL): void { 53 $this->drupalGet($uri); 54 if (isset($browser_options['window_size'])) { 55 $this->getSession()->resizeWindow($browser_options['window_size']['width'], $browser_options['window_size']['height']); 56 } 57 $this->executeAxe($axe_options); 58 } 59 60 /** 61 * Data provider for testAdminPages. 62 * 63 * @return array 33 * 34 * @param string $uri 35 * The path to be tested. 36 * @param array|null $options 37 * (optional) Associative array of Axe options. 38 */ 39 #[DataProvider('providerTestAnonymousPages')] 40 public function testAnonymousPages(string $uri, array $options = []): void { 41 $this->drupalGet($uri); 42 $this->executeAxe($options); 43 } 44 45 /** 46 * Data provider for testAnonymousPages. 47 * 48 * @return array
Please register or sign in to reply