Automated A11y tests in PHPUnit

Created on 2 February 2023, almost 2 years ago
Updated 26 May 2023, over 1 year ago

Problem/Motivation

It could be useful to be able to easily run accessibility tests directly from PHPUnit using FunctionalJavascriptTests. It would help detect any level of issues that could prevent passing the Accessibility gate β†’ (even if we should always underline that automated tests are never enough to guarantee accessibility).

Proposed resolution

Add axe-core library to Core's dependencies and provide a Trait to run axe tests easily.

πŸ“Œ Task
Status

Needs work

Version

11.0 πŸ”₯

Component
OtherΒ  β†’

Last updated about 3 hours ago

Created by

πŸ‡«πŸ‡·France duaelfr Montpellier, France

Live updates comments and jobs are added and updated live.
  • Accessibility

    It affects the ability of people with disabilities or special needs (such as blindness or color-blindness) to use Drupal.

  • JavaScript

    Affects the content, performance, or handling of Javascript.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Issue created by @duaelfr
  • @duaelfr opened merge request.
  • Status changed to Needs review almost 2 years ago
  • πŸ‡«πŸ‡·France duaelfr Montpellier, France

    MR open for thoughts and reviews
    I added a very basic test on Olivero to ensure it works (I never added a dependency so I'm not sure).

  • πŸ‡«πŸ‡·France duaelfr Montpellier, France

    This is related to πŸ“Œ Automated A11y tests in Nightwatch Fixed
    We might discuss if we want both to be integrated or not.

  • Status changed to Needs work over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Not sure if this is a valid test but I reused MediaSourceImageTest::testMediaImageSource
    Disabled required alt text
    Commented out line $page->fillField("{$source_field_id}[0][alt]", ''); so the image had no alt text

    Then ran

        $this->drupalGet($this->assertLinkToCreatedMedia());
    
        $this->executeAxe();;
    

    Expected it to fail but I didn't and just continued along.

    Is there something I'm missing?

  • πŸ‡«πŸ‡·France duaelfr Montpellier, France

    @smustgrave Thanks for testing! An empty alt text is not a failure. What's forbidden is no alt attribute at all!
    It would be a failure if the image was the only content of a link for example.

  • πŸ‡¨πŸ‡¦Canada mgifford Ottawa, Ontario

    Now we have https://www.drupal.org/project/drupal/issues/3293469 πŸ“Œ Automated A11y tests in Nightwatch Fixed

    Do we need this issue? Is PHPUnit going to give us different or better results?

  • πŸ‡«πŸ‡·France duaelfr Montpellier, France

    Hi @mgifford!

    On its current state, I believe that my patch is less interesting that Nightwatch's one because you can only ignore some problems based on their severity. I believe it could be improved by adding a way to alter the axe rules like it's done in JS. I also considered adding some ways to assert expected success or failures in a future version of my patch.

    All that to say that I think the only advantage of this one instead of Nightwatch's one would be that some devs could be more comfortable using PHPUnit than Nigthwatch.

    Do you think it could be interesting to have both available?

  • πŸ‡¨πŸ‡¦Canada mgifford Ottawa, Ontario

    That I don't know. You've got the PHP developers & the JavaScript developers. Do you think PHPUnit is better supported by modules/themes than Nightwatch?

    I think there's some split between nightwatch/cypress in the JS testing community. I'll ask around and see if we can get some other thoughts on this.

    I'd suggest that we might want to test different things with them.

  • πŸ‡ΊπŸ‡ΈUnited States dmundra Eugene, OR

    I think since axe-core package is now available in version 10.1.x (with the nightwatch update) I think a PHP example could be good to have but I am not sure if we need the same setup for an install profile and such.

    Is the AccessibilityTest being picked up by the pipeline? I am not seeing it https://dispatcher.drupalci.org/job/drupal_patches/164094/console if it is.

Production build 0.71.5 2024