Skip to content
This repository was archived by the owner on Apr 20, 2021. It is now read-only.
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions src/Context/AccesibilityContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Sanpi\Behatch\Context;

Copy link
Copy Markdown
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
Copy Markdown
Author

Choose a reason for hiding this comment

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

done

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

also test added


use Behat\Gherkin\Node\TableNode;
use Behat\Mink\Exception\ExpectationException;
use Behat\Mink\Exception\ResponseTextException;
use Behat\Mink\Exception\ElementNotFoundException;

class AccesibilityContext extends BaseContext
{

public function __construct()

Copy link
Copy Markdown
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
Copy Markdown
Author

Choose a reason for hiding this comment

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

done

{
}

/**
* @Then all images should have an alt attribute
*/
public function allImagesShouldHaveAnAltAttribute()
{
$images = $this->getSession()->getPage()->findAll('xpath', '//img[not(@alt)]');

Copy link
Copy Markdown

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

if ($images != null) {

Copy link
Copy Markdown
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
Copy Markdown
Author

Choose a reason for hiding this comment

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

done

throw new \Exception("There are images without an alt attribute");
}
}

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

Copy link
Copy Markdown
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

{
$title = $this->getSession()->getPage()->find('css', 'h1')->getText();
if (strlen($title) > $arg1) {
throw new \Exception("The h1 title is more than '$arg1' characters long");
}
}

/**
* @Then all tables should have a table header
*/
public function allTablesShouldHaveATableHeader()
{
$tables = $this->getSession()->getPage()->findAll('xpath', '//table/*[not(th)]');
if ($tables != null) {

Copy link
Copy Markdown
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
Copy Markdown
Author

Choose a reason for hiding this comment

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

done

throw new \Exception("There are tables without a table header");
}
}
}