Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tests to work with root-less travis-ci #961

Merged
merged 7 commits into from Feb 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
54 changes: 29 additions & 25 deletions .travis.yml
@@ -1,30 +1,34 @@
sudo: false
language: php
cache:
directories:
- $HOME/.composer/cache
- build/vendor
- node_modules
php:
- 5.4
before_install:
# configure apache virtual hosts
- sudo apt-get update
- sudo apt-get install apache2
- sudo apt-get install php5-curl
- sudo cp -f build/travis-ci-apache /etc/apache2/sites-available/default
- sudo sed -e "s?%TRAVIS_BUILD_DIR%?$(pwd)?g" --in-place /etc/apache2/sites-available/default
- sudo a2enmod include
- sudo a2enmod headers
- sudo apachectl configtest
- sudo service apache2 restart
before_script:
# install `pa11y`
- npm install
- npm install pa11y@2.4.4
- npm install grunt-cli
# build the templates
- ./node_modules/grunt-cli/bin/grunt
# import test dependencies
- cd build
- composer install --prefer-source
- cd ../
script: ./tests/run-tests.sh
- 5.6
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- gcc-4.8
- g++-4.8
install:
- nvm install stable
- CXX=g++-4.8 npm install
# install `pa11y`
- npm install phantomjs-prebuilt pa11y http-server grunt-cli
# build the templates
- ./node_modules/.bin/grunt
# import test dependencies
- cd build
- composer install --prefer-source
- cd ../
script:
# start a localhost server on 8080 for the root
- nohup node_modules/.bin/http-server -d false -r >/dev/null &
- phpunit tests
branches:
only:
- develop
- accessibility-tests
6 changes: 3 additions & 3 deletions build/find-node-or-install
Expand Up @@ -47,9 +47,9 @@ else
# Load nvm into current shell
. nvm/nvm.sh >/dev/null

# Install and use latest 0.x node
nvm install 0 >/dev/null
nvm alias default 0 >/dev/null
# Install and use latest stable node
nvm install stable >/dev/null
nvm alias default stable >/dev/null
nvm use default >/dev/null

# Find and output node's bin directory
Expand Down
16 changes: 0 additions & 16 deletions build/travis-ci-apache

This file was deleted.

102 changes: 70 additions & 32 deletions tests/Accessibility/accessibility.phpt
Expand Up @@ -3,7 +3,8 @@ Validate all example pages for accessibility
--FILE--
<?php
//Load composer
require_once dirname(__FILE__) . '/../../build/vendor/autoload.php';
require_once __DIR__ . '/../../build/vendor/autoload.php';
require_once __DIR__ . '/../mod_include.php';

if (file_exists(__DIR__ . '/../config.inc.php')) {
require_once __DIR__ . '/../config.inc.php';
Expand All @@ -12,40 +13,40 @@ if (file_exists(__DIR__ . '/../config.inc.php')) {
class AccessibilityTester {
protected $examples_directory = '';
protected $wrapper_html;
public static $base_url = 'http://localhost/';
public static $base_url = 'http://localhost:8080/';
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to have the http-server use port 80?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. Root is required to bind to ports < 1024.


public function __construct()
{
$this->examples_directory = dirname(__FILE__) . '/../../wdn/templates_4.1/examples/';
$this->examples_directory = __DIR__ . '/../../wdn/templates_4.1/examples/';
$this->wrapper_html = file_get_contents($this->examples_directory . 'index.shtml');
}

public function getFilesToCheck() {
$files_to_check = array();

foreach (new DirectoryIterator($this->examples_directory) as $file_info) {
foreach (new DirectoryIterator($this->examples_directory) as $file_info) {
if ($file_info->getExtension() !== 'html') {
continue;
}

$files_to_check[] = $file_info->getFilename();
}

return $files_to_check;
}

/**
* @param string $file the filename of the example page to check
* @return array|bool false on error, array of errors on success
*/
protected function checkExample($file) {
echo "checking: " . $file . PHP_EOL;
$url = self::$base_url . 'tests/Accessibility/tmp/' . $file . '.shtml';
$url = self::$base_url . 'tests/Accessibility/tmp/' . $file;
$command = 'pa11y ' .
'-r json ' .
'-s WCAG2AA ' .
'-w 500 ' .
'--config ' . dirname(__FILE__) . '/pa11y.json ' .
'-w 500 ' .
'--config ' . __DIR__ . '/pa11y.json ' .
'--htmlcs "http://webaudit.unl.edu/plugins/metric_pa11y/html_codesniffer/build/HTMLCS.js" ' .
escapeshellarg($url);
$errors = array();
Expand All @@ -54,36 +55,47 @@ class AccessibilityTester {
$example_html = file_get_contents($this->examples_directory . $file);
$new_dom = \HTML5::loadHTML($this->wrapper_html);
$example_dom = \HTML5::loadHTML($example_html);

$main_content = $new_dom->getElementById('maincontent');
while ($main_content->hasChildNodes()) {
//Clear out the main content area
$main_content->removeChild($main_content->firstChild);
}

if (!$example_node = $example_dom->getElementById('example-code')) {
//The example code needs to be wrapped in a #example-code div
return false;
return ['Missing #example-code wrapper.'];
}

//Import the example element into the new node
$new_element = $new_dom->importNode($example_node, true);

//Append the example element as the only child of the main content area
$main_content->appendChild($new_element);

//Save to an example file.
file_put_contents(__DIR__ . '/tmp/' . $file . '.shtml', \HTML5::saveHTML($new_dom));
$exampleSHTML = mod_include_string(\HTML5::saveHTML($new_dom), dirname(dirname(__DIR__)));
$tmpHTMLFile = __DIR__ . '/tmp/' . $file;
file_put_contents($tmpHTMLFile, $exampleSHTML);

//Run pa11y on the test page
$output_file = __DIR__ . '/output.json';
$result = exec($command . ' > ' . $output_file);
$errorFile = __DIR__ . '/error_output.txt';
$result = exec($command . ' > ' . $output_file . ' 2>' . $errorFile);
$errorOutput = file_get_contents($errorFile);
$json = file_get_contents($output_file);
unlink($output_file);
unlink($tmpHTMLFile);
unlink($errorFile);

if (!$data = json_decode($json, true)) {
return false;
return [
'Bad pa11y output:',
$json,
$errorOutput,
];
}

foreach ($data as $result) {
if ($result['type'] != 'error') {
continue;
Expand All @@ -96,18 +108,18 @@ class AccessibilityTester {
. "\r\n\t context: " . $result['context']
. "\r\n------------\r\n";
}

return $errors;
}

public function check()
{
foreach ($this->getFilesToCheck() as $file) {
$errors = $this->checkExample($file);
if ($errors === false) {
echo 'Unable to check ' . $file . PHP_EOL;
}

if (!empty($errors)) {
echo $file . ' FAILED!' . PHP_EOL;
foreach ($errors as $error) {
Expand All @@ -118,16 +130,42 @@ class AccessibilityTester {
}
}

putenv('PATH=' . realpath(__DIR__ . '/../../node_modules/.bin') . ':' . getenv('PATH'));
$tester = new AccessibilityTester();
$tester->check();

//Save what we expect to see if all tests pass to a file.
$expect = '';
foreach($tester->getFilesToCheck() as $file) {
$expect .= 'checking: ' . $file . PHP_EOL;
}
file_put_contents(__DIR__ . '/tmp/expect.txt', $expect);
// //Save what we expect to see if all tests pass to a file.
// $expect = '';
// foreach($tester->getFilesToCheck() as $file) {
// $expect .= 'checking: ' . $file . PHP_EOL;
// }
// file_put_contents(__DIR__ . '/tmp/expect.txt', $expect);

?>
--EXPECTFILE--
tmp/expect.txt
--EXPECT--
checking: audioplayer.html
checking: band_imagery.html
checking: buttons.html
checking: carousel.html
checking: colorbox.html
checking: events.html
checking: forms.html
checking: formvalidator.html
checking: idm.html
checking: image.html
checking: infographics.html
checking: jqueryui.html
checking: layouts.html
checking: notice.html
checking: pagination.html
checking: promo_image.html
checking: quote.html
checking: randomizer.html
checking: rss_widget.html
checking: table.html
checking: tabs.html
checking: tooltips.html
checking: typography.html
checking: videoplayer.html
checking: zenboxes.html
checking: zentables.html
17 changes: 0 additions & 17 deletions tests/run-tests.sh

This file was deleted.