diff --git a/.gitattributes b/.gitattributes index 2a242f9b5d..027a6dac9d 100644 --- a/.gitattributes +++ b/.gitattributes @@ -31,6 +31,9 @@ /phpunit.xml.dist export-ignore /pulsar.sublime-project export-ignore /Vagrantfile export-ignore +/tests/validation/w3cError* export-ignore +/validation-status.json export-ignore +/validation-report.json export-ignore ## ## /images/ diff --git a/.gitignore b/.gitignore index f33c745b25..d94a8cef67 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,7 @@ pulsar.zip /fonts/_config.fonts.scss /.csscomb.json +/validation-status.json +/validation-report.json +/tests/validation/error_reports/* +/tests/validation/html_output/* diff --git a/Gruntfile.js b/Gruntfile.js index 28bfd95e02..994598c4f7 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -475,9 +475,35 @@ module.exports = function(grunt) { reloadOnRestart: true, watchTask: true } + }, + + casperjs: { + options: { + async: { + parallel: false + }, + silent: false + }, + files: ['../pulsar/js/casper.js'] }, - 'gh-pages': { + validation: { + options: { + reset: grunt.option('reset') || false, + stoponerror: false, + maxTry: 3, + relaxerror: ['Bad value X-UA-Compatible for attribute http-equiv on element meta.'], // ignores these errors + generateReport: true, + errorHTMLRootDir: "tests/validation/error_reports", + useTimeStamp: true, + errorTemplate: "tests/validation/w3c_validation_error_Template.html" + }, + files: { + src: ['../pulsar/tests/validation/html_output/*.html'] + } + }, + + 'gh-pages': { options: { base: 'docs/_site', repo: 'https://github.com/jadu/pulsar.git' @@ -575,6 +601,11 @@ module.exports = function(grunt) { 'exec:updateNpm' ]); + grunt.registerTask('validate', [ + 'casperjs', + 'validation' + ]); + // load all grunt tasks require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks); diff --git a/js/casper.js b/js/casper.js new file mode 100644 index 0000000000..3951a00155 --- /dev/null +++ b/js/casper.js @@ -0,0 +1,56 @@ +var fs = require('fs'); +var links; + +function getLinks() { + var links = document.querySelectorAll('.nav-link.t-nav-link'); + return Array.prototype.map.call(links, function (e) { + return e.getAttribute('href'); + }); +} + +casper.start('http://192.168.13.37/index.php', function() { + "use strict"; + fs.write('tests/validation/html_output/_index.html', this.getPageContent(), 'w'); +}); + +casper.then(function () { + var links = this.evaluate(getLinks); + var current = 0; + var end = links.length; + // Get the word before .html.twig, the word before the last '/' and the word in urls like '/lexicon' + var regex = /((\w*)(\/|.html.twig)$)|(\/\w*$)/gm; + var match = []; + var newlinks = []; + + // Remove links within the same page + for (var i = 0; i < links.length; i++) { + if (links[i].indexOf('#') === -1) { + newlinks.push(links[i]); + } + } + + // Get Page Name from URL + for (i = 0; i < newlinks.length; i++) { + if (newlinks[i].match(regex)) { // Remove null items that didn't pass the regex + var link = newlinks[i].match(regex); + var filtered = link[0]; // Get just the name from the results array + var splited = filtered.split('.'); // Split dots to remove .html.twig part + var replaced = splited[0].replace('/', ''); // Remove '/' + match.push(replaced); // Keep just the names in a separata array + }; + }; + + for (;current < end;) { + (function(cntr) { + casper.thenOpen('http://192.168.13.37' + newlinks[cntr] + '', function() { + fs.write('tests/validation/html_output/_' + match[cntr] + '_.html', this.getPageContent(), 'w'); + }); + })(current); + current++; + } +}); + +casper.run(function() { + "use strict"; + this.exit(); +}); diff --git a/package.json b/package.json index a29c60e6e2..26a5f897da 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "grunt-browser-sync": "^2.2.0", "grunt-browserify": "^5.0.0", "grunt-bump": "^0.7.2", + "grunt-casperjs": "^2.2.1", "grunt-contrib-clean": "^1.0.0", "grunt-contrib-compress": "^1.2.0", "grunt-contrib-copy": "^1.0.0", @@ -54,6 +55,7 @@ "grunt-real-favicon": "^0.1.3", "grunt-sass": "^1.1.0", "grunt-scss-lint": "0.3.8", + "grunt-w3c-html-validation": "^0.1.8", "jquery": "1.x", "jsdom": "^8.4.0", "matchdep": "^1.0.1", diff --git a/tests/validation/w3c_validation_error_Template.html b/tests/validation/w3c_validation_error_Template.html new file mode 100644 index 0000000000..9da8df172d --- /dev/null +++ b/tests/validation/w3c_validation_error_Template.html @@ -0,0 +1,44 @@ + + +
+W3C Validation Report + | +|||||
{{filename}} | Error Count : {{error.length}} + | +|||||
Error Number + | +Error Type + | +Line Number + | +Error Message + | +Error Source Code Reference + | +Error Explanation + | +
{{@index}} | +{{type}} | +{{lastLine}} | +{{message}} | +{{errSrcFirstPart}}{{{errSrcToHighlight}}}{{errSrcSecondPart}} |
+ {{{explanation}}} | +