Skip to content
This repository has been archived by the owner on Apr 29, 2018. It is now read-only.

Commit

Permalink
Completing the demo theme for the Theme Unit Testing article
Browse files Browse the repository at this point in the history
  • Loading branch information
tommcfarlin committed Jul 11, 2012
1 parent 5d80377 commit b59e438
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 2 deletions.
20 changes: 20 additions & 0 deletions README.md
@@ -0,0 +1,20 @@
# Basic Theme

Basic Theme is a very simple theme used to demonstrate unit testing in a WordPress environment. The theme has been written for Envato's Tuts+ Network and relies on the following projects

* [PHPUnit](https://github.com/sebastianbergmann/phpunit) by Sebastian Bergmann
* [WordPress-Tests](http://unit-test.svn.wordpress.org/trunk/). Note that `WordPress-Tests` are already included with this plugin.


## Installation

Note that this theme is not in development. It serves as a demo for the companion article.

1. Clone the repository or extract the archive to your `wp-content/themes` directory
1. Verify that the theme is available in your Themes dashboard

## Changelog

_1.0 (2012.07.10)_

* Initial commit. Includes basic theme, unit tests, and WordPress Test framework.
21 changes: 20 additions & 1 deletion functions.php
@@ -1,5 +1,24 @@
<?php

/**
* Enqueues jQuery with the Basic Theme so that it's loaded on page request.
*/
function basic_add_jquery() {

wp_enqueue_script( 'jquery' );

} // end basic_remove_jquery
add_action( 'wp_enqueue_scripts', 'basic_add_jquery' );

?>
/**
* Writes a simple meta description to the head element using the description of the blog
* specified in the 'General Settings.'
*/
function basic_meta_description() {

echo '<meta name="description" content="' . get_bloginfo( 'description' ) . '" />';

} // end basic_meta_description
add_action( 'wp_head', 'basic_meta_description' );

?>
2 changes: 1 addition & 1 deletion style.css
@@ -1,6 +1,6 @@
/*
Theme Name: Basic Theme
Theme URI: TODO
Theme URI: http://github.com/tommcfarlin/Basic-Theme/
Version: 1.0
Description: A basic theme used to demonstrate how to write unit tests for themes.
Author: Tom McFarlin
Expand Down
74 changes: 74 additions & 0 deletions tests/test_basic_theme.php
@@ -0,0 +1,74 @@
<?php

// Include the functions for the theme
include_once('../functions.php');

/**
* This class contains all of the unit tests for testing the Basic Theme. Its
* primary purpose is to provide several examples of how to unit test themes.
*/
class Test_Basic_Theme extends WP_UnitTestCase {

/**
* Fired before the set of tests is run. After WordPress is installed,
* switches from the default theme to the Basic Theme.
*/
function setUp() {

parent::setUp();
switch_theme( 'Basic Theme', 'Basic Theme' );

} // end setup

/**
* Verifies that Basic Theme is the active theme.
*/
function testActiveTheme() {

$this->assertTrue( 'Basic Theme' == get_current_theme() );

} // end testThemeInitialization

/**
* Verifies that Twenty Eleven is not the active theme.
*/
function testInactiveTheme() {

$this->assertFalse( 'Twenty Eleven' == get_current_theme() );

} // end testInactiveTheme

/**
* First verifies that jQuery has not been loaded, then fires WordPress' 'wp_enqueue_scripts'
* action to enqueue specified JavaScript (in our case, jQuery).
*
* Next, asserts that jQuery has been enqueued.
*/
function testjQueryIsLoaded() {

// Typically, I'm not a fan of multiple assertions per function, but in this case,
// we need to make sure jQuery isn't loaded before the 'wp_enqueue_scripts' action
// is fired.
$this->assertFalse( wp_script_is( 'jquery' ) );

// Fire the enqueue action and now check for jQuery
do_action( 'wp_enqueue_scripts' );
$this->assertTrue( wp_script_is( 'jquery' ) );

} // end testjQueryIsLoaded

/**
* Verifies that the meta description is properly added to the head element.
*/
function testBasicMetaDescription() {

$meta_description = '<meta name="description" content="' . get_bloginfo( 'description' ) . '" />';
$this->expectOutputString( $meta_description, basic_meta_description() );

} // end testBasicMetaDescription


} // end class


?>

0 comments on commit b59e438

Please sign in to comment.