From ad6008470ffe295d9f0471d7ac33ce0bfddbe370 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sun, 28 Jun 2009 21:37:20 -0400 Subject: [PATCH] get view testing --- classes/PluginWonderful.php | 9 ++++++--- test/PluginWonderfulTest.php | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/classes/PluginWonderful.php b/classes/PluginWonderful.php index 3af35c6..b7baaf9 100644 --- a/classes/PluginWonderful.php +++ b/classes/PluginWonderful.php @@ -135,9 +135,12 @@ class PluginWonderful { return dirname(__FILE__) . "/../{$source}/{$name}.php"; } + function _include($target) { include($target); } + function _file_exists($target) { return @file_exists($target); } + function get_view($function_name) { $target = $this->_create_target(str_replace('plugin_wonderful_', '', $function_name), "views"); - if (file_exists($target)) { + if ($this->_file_exists($target)) { $info = get_plugin_data(realpath(__FILE__)); echo '
'; @@ -146,7 +149,7 @@ class PluginWonderful { $this->show_messages(); - include($target); + $this->_include($target); echo '
'; echo '
'; @@ -156,7 +159,7 @@ class PluginWonderful { echo '
'; echo '
'; } else { - die(__("View not found: ", 'plugin-wonderful') . str_replace('plugin-wonderful_', '', $function_name)); + echo __("View not found: ", 'plugin-wonderful') . str_replace('plugin_wonderful_', '', $function_name); } } diff --git a/test/PluginWonderfulTest.php b/test/PluginWonderfulTest.php index e0c1f31..ea2445c 100644 --- a/test/PluginWonderfulTest.php +++ b/test/PluginWonderfulTest.php @@ -240,8 +240,39 @@ class PluginWonderfulTest extends PHPUnit_Framework_TestCase { $this->assertEquals($expected_body, $this->pw->inject_ads_into_body_copy("body")); } - function testGetView() { - $this->markTestIncomplete(); + function providerTestGetView() { + return array( + array("**bad**", false), + array("**good**", true), + ); + } + + /** + * @dataProvider providerTestGetView + */ + function testGetView($function_extension, $file_exists) { + global $wp_test_expectations; + $wp_test_expectations['plugin_data'][realpath(dirname(__FILE__) . '/../classes/PluginWonderful.php')] = array( + 'Title' => '**title**', + 'Version' => '**version**', + 'Author' => '**author**' + ); + + $pw = $this->getMock('PluginWonderful', array('_create_target', '_include', '_file_exists')); + + $pw->expects($this->once())->method("_file_exists")->will($this->returnValue($file_exists)); + + ob_start(); + $pw->get_view("plugin_wonderful_" . $function_extension); + $source = ob_get_clean(); + + $this->assertEquals($file_exists, strpos($source, $function_extension) === false); + + if ($file_exists) { + foreach (array("title", "version", "author") as $name) { + $this->assertTrue(strpos($source, "**${name}**") !== false); + } + } } function testHandleAction() {