From d851466b11a52014f2657150344f6d320c7e1bef Mon Sep 17 00:00:00 2001 From: Daniel Convissor Date: Thu, 8 Nov 2012 15:48:41 -0500 Subject: [PATCH] Move logout/redirect to method in the main class -- more realistic. --- oop-plugin-template-solution.php | 14 ++++++++++++-- readme.txt | 4 ++++ tests/LoginTest.php | 5 +---- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/oop-plugin-template-solution.php b/oop-plugin-template-solution.php index 3a1577d..5921666 100644 --- a/oop-plugin-template-solution.php +++ b/oop-plugin-template-solution.php @@ -7,7 +7,7 @@ * object-oriented programming practices. * * Plugin URI: http://wordpress.org/extend/plugins/oop-plugin-template-solution/ - * Version: 1.0.2 + * Version: 1.1.0 * (Remember to change the VERSION constant, below, as well!) * Author: Daniel Convissor * Author URI: http://www.analysisandsolutions.com/ @@ -49,7 +49,7 @@ class oop_plugin_template_solution { /** * This plugin's version */ - const VERSION = '1.0.2'; + const VERSION = '1.1.0'; /** * This plugin's table name prefix @@ -197,6 +197,16 @@ public function wp_login($user_name, $user) { * ===== INTERNAL METHODS ==== */ + /** + * Log the user out and send them to the lost password page + * + * This is here solely for demonstration of unit testing. + */ + protected function force_retrieve_pw() { + wp_logout(); + wp_redirect(wp_login_url() . '?action=retrievepassword'); + } + /** * Obtains the email addresses the notifications should go to * @return string diff --git a/readme.txt b/readme.txt index 401868b..4a04dd4 100644 --- a/readme.txt +++ b/readme.txt @@ -185,6 +185,10 @@ the `.pot`, `.po` and `.mo` files: == Changelog == += 1.1.0 (2012-11-08) = +* Move the `wp_logout()` and `wp_redirect()` calls from direct calls in the +test method to a method in the tested class instead. + = 1.0.2 (2012-11-05) = * Explain why can't use PHPUnit's @expectedException functionality. diff --git a/tests/LoginTest.php b/tests/LoginTest.php index 65ac2af..592214e 100644 --- a/tests/LoginTest.php +++ b/tests/LoginTest.php @@ -82,10 +82,7 @@ public function test_redirect() { $this->expected_errors($expected_error); self::$location_expected = wp_login_url() . '?action=retrievepassword'; - // For demonstration purposes only. In the real world, the logout - // and redirect would be triggred by some method in your plugin. - wp_logout(); - wp_redirect(wp_login_url() . '?action=retrievepassword'); + self::$o->force_retrieve_pw(); $this->assertTrue($this->were_expected_errors_found(), "Expected error not found: '$expected_error'");