PressTigers

WordPress Theme Unit Testing

WordPress Theme unit testing is a process to make sure our developed theme is maintaining the standard of quality in WordPress themes. In WordPress, a theme is a collection of style sheets and templates that are placed inside a folder and that folder is called a WordPress theme.

General Requirement for WordPress Theme Unit Testing:

  • A unique prefix must be used for all function names, classes, hooks, public/global variables, action/filter hooks.
  • The wp_ prefix is reserved for WordPress core functionality and must not be used by a theme.
  • These functions should be used in preference to basename, dirname, pathinfo, etc.
  • Deprecated template tags or functions are not allowed.

Following function must be available in a theme

  • The wp_enqueue_style() function must be used to enqueue all stylesheets. For more information, refer to wp_enqueue_style().
  • The wp_enqueue_script() function must be used to enqueue JavaScript code. For more information, refer to wp_enqueue_script().
  • Assets loaded from the theme directory must use get_template_directory_uri() or get_stylesheet_directory_uri() to build the URL.

Theme unit test is a WordPress xml file containing (text and images) that you can import into your WordPress package to test your theme.

Steps for WordPress Theme unit testing:

To test your theme package,

  • Keep your debug mode to “TRUE” in the wp-config file.

  • Download theme unit test data file from Github – Connect to preview
  • Import file into a WordPress instance by going to Dashboard = > Tools => Import
  • Select XML and click import

Once a file is imported successfully, check the front page of your website and see how your theme responds to each HTML tag with content and settings.

Theme check Plugin

Download and install the theme check plugin on your website, then
go to Dashboard => Appearance > Theme Check, select theme and click on “check it” button

Make sure there is no error showing at the bottom and your theme pass the test just like this.

If you have any further queries related to WordPress or WordPress Theme unit testing, please feel free to get to PressTigers experts and we will work out the issue together.

Written By: Hijab e Fatima

User Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

    Get in Touch