Skip to content

Instantly share code, notes, and snippets.

@rnagle
Created December 23, 2014 21:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rnagle/d1d06cb6717761f28359 to your computer and use it in GitHub Desktop.
Save rnagle/d1d06cb6717761f28359 to your computer and use it in GitHub Desktop.
"Hello World!" plugin tests
<?php
class HelloWorldTest extends WP_UnitTestCase {
function test_hello_world() {
// Test hello_world()
$this->assertEquals("Hello World!" == hello_world());
}
function test_hello_world_markup() {
// Test hello_world_markup()
ob_start();
hello_world_markup();
$result = ob_get_contents();
ob_end_clean();
$this->assertTrue(!empty(preg_match("/^<p\s+id='hello-world'>.*<\/p>$/", $result)));
}
function test_hello_world_css() {
// Test hello_world_css()
ob_start();
hello_world_css();
$result = ob_get_contents();
ob_end_clean();
// Make sure there are style tags being printed. Duh.
$this->assertTrue(!empty(preg_match("/.*?.*<\/style>/s", $result)));
// Make sure we're using the right selector
$this->assertTrue((bool) strpos('hello-world', $result)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment