This repository has been archived by the owner on Apr 29, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Completing the demo theme for the Theme Unit Testing article
- Loading branch information
1 parent
5d80377
commit b59e438
Showing
4 changed files
with
115 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' ); | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
||
|
||
?> |