WP_UnitTest_Factory: The Missing Documentation

Most WordPress functions interact with data objects like posts, users, or terms. This creates a problem for developers, as every test starts with an empty WordPress installation. The WordPress Unit Test Factory helps to solve this issue.

It provides a set offers a set of helper classes to create these database objects, called database fixtures in a unit testing scenario.

The test framework offers factories for creating:

  • Attachments
  • Comments
  • Posts
  • Categories, Tags, and Terms
  • Users

It also has multisite specific factories for:

  • Networks
  • Blogs

In this article, we’ll see about how you can interact with these factories, and what issues to watch out for.

Read More

How To Add JavaScript to WordPress

Adding JavaScript to an HTML page is straightforward: you add a script tag into the <head> section of the HTML code. But in WordPress, adding JavaScript is more complex, because you do not directly change the HTML templates. Instead you rely on a dedicated WordPress API for handling JavaScript code.

In this article, we will have an in-depth look at this fundamental API, and learn how to add JavaScript to WordPress.

Together we will:

Read More