WordPress is a very popular platform for hosting websites. Over 74 million websites are based on WordPress. WordPress is also increasingly being used to develop complex web based applications.
There is a need for a testing system that allows testing applications and websites based on WordPress. Recently I had the opportunity of setting up a simple testing system for WordPress that validates WordPress blogs using the WordPress XML-RPC API, PHP Tidy and the online Nu HTML Checker. I will describe my experience in this blog post. I will also briefly describe a couple of ways in which you can test server side code of your WordPress plugins.
Its a good idea to ensure that your WordPress blog conforms to W3C standards. The World Wide Web Consortium (W3C) is the main international standards organization for the World Wide Web. The W3C standard is recognized by all major search engines. Websites that conform to its standards can be understood by search engines and web browses more easily.
Such websites have fewer performance problems and function more reliably across multiple devices. They are also sure to receive a higher ranking on the major search engines.
The W3C validation website contains several tools that you can use to validate your website pages. These tools include:
The Nu HTML checker can be used to check any website for compliance with the new HTML 5 standard. I created a PHP script that uses the WordPress XML-RPC API for getting list of all pages, posts, custom posts on my blog. The XML-RPC API is very useful and you can use it to easily get list of all pages on your blog. Once you have the list of pages, you can test each page against different W3C standards.
For each post the script validates the post HTML using the PHP Tidy extension and the Nu HTML Checker. The PHP Tidy extension is a popular extension for PHP that allows repairing and formatting your HTML code. It supports HTML 4 validation but does not support HTML 5.
If a post cannot be validated the test ends with an error. I ran this script with PhpUnit and added it to Jenkins Continuous Integration Server. I scheduled the script to run every day, so the script tests all pages automatically and sends me an email if any of the tests fail.
Setting up projects in Jenkins is quite simple. You can refer to my earlier blog post titled Continuous integration and Project Management with Jenkins and Redmine for more information on how to add scripts to Jenkins.
Testing a WordPress website using PhpUnit is different from testing websites based on other platforms. WordPress has its own authentication system which prevents testing WordPress plugins and themes like normal PHP scripts. There are 2 main options for testing the server side code of your plugins:
WordPress is a very popular platform for websites. It is important to have a testing system in place that makes it easy to test WordPress based websites.
Ensuring that your website conforms to W3C standards is very useful. It not only improves your SEO score but also ensures compatibility of your website across different devices and browsers.