Skip to content
This repository has been archived by the owner on Apr 20, 2021. It is now read-only.

added a few accesibility checks. more to come. #202

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

marijndaniels
Copy link

Extending the BaseContext for some accesibility checks.

Plan to add these as well:

  • Headings:
    ** each page should have one and only one H1 element.
    ** the H1 element should not be longer than 70 chars in length.
    ** each page should have at least one H2 element
  • Images
    ** Each image should have an alt attribute, possibly empty.
    ** If a title attribute is present, it should differ in value from the alt attribute
  • Tables
  • Each table should have a heading and at least one data row
  • Anchors
    ** for each a:hover there should also be an a:focus
    ** title attribute should differ in value from the text in between the a tags
  • Forms
    ** each formfield should have a label
    ** all labels should have a for attribute, linked to the formfield
  • Page
    ** check for skip navigation
    ** check doctype present
    ** check lang attribute

Copy link
Member

@sanpii sanpii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea!

Please add a test for these definitions.

It’s maybe a good idea to add a reference from w3c standard in error messages. For example, in the first text error message, I have added a link to https://www.w3.org/TR/WCAG10/#gl-provide-equivalents

@@ -0,0 +1,49 @@
<?php

namespace Sanpi\Behatch\Context;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the last version, the right namespace is Behatch\Context.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also test added

class AccesibilityContext extends BaseContext
{

public function __construct()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No empty construct.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

public function allImagesShouldHaveAnAltAttribute()
{
$images = $this->getSession()->getPage()->findAll('xpath', '//img[not(@alt)]');
if ($images != null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use strict (===) equality.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

public function allTablesShouldHaveATableHeader()
{
$tables = $this->getSession()->getPage()->findAll('xpath', '//table/*[not(th)]');
if ($tables != null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use strict (===) equality.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


@trigger_error('The Sanpi\\Behatch\\Context\\AccesibilityContext class is deprecated since version 2.3 and will be removed in 3.0. Use the Behatch\\Context\\AccesibilityContext class instead.', E_USER_DEPRECATED);

class_alias('\\Behatch\\Context\\AccesibilityContext', '\\Sanpi\\Behatch\\Context\\AccesibilityContext');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t think it's necessary.

@@ -0,0 +1,48 @@
@accesibility
Feature: toegankelijkheid verschillende types paginas
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use english language.

Then I should see 1 "h1" elements
And I should see an "h2" element

Examples:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s not necessary if you have only one url.

Given I am on "<url>"
Then the title should not be longer than 70

Examples:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s not necessary if you have only one url.

Given I am on "<url>"
Then all images should have an alt attribute

Examples:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s not necessary if you have only one url.

Given I am on "<url>"
Then all tables should have a table header

Examples:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s not necessary if you have only one url.

Given I am on "<url>"
Then all tables should have at least one data row

Examples:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s not necessary if you have only one url.

/**
* @Then the title should not be longer than :arg1
*/
public function theTitleShouldNotBeLongerThan($arg1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use explicite argument name, like $length

@sanpii sanpii added this to the 2.7 milestone Apr 13, 2017
@sanpii sanpii removed this from the 2.7 milestone Apr 28, 2017
*/
public function allImagesShouldHaveAnAltAttribute()
{
$images = $this->getSession()->getPage()->findAll('xpath', '//img[not(@alt)]');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, could you tell me this would refer to test image without alt?
I pull your code and test my website. There are alt attribute, but still said There are images without an alt attribute

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants