add handle action test
This commit is contained in:
parent
05ce3cdb6c
commit
eb14822995
@ -164,12 +164,11 @@ class PluginWonderful {
|
||||
}
|
||||
|
||||
function handle_action() {
|
||||
if (!empty($_POST['_pw_nonce'])) {
|
||||
if (wp_verify_nonce($_POST['_pw_nonce'], 'plugin-wonderful')) {
|
||||
$action = "handle_action_" . str_replace("-", "_", preg_replace('#[^a-z\-]#', '', strtolower($_POST['action'])));
|
||||
if (method_exists($this, $action)) { call_user_func(array($this, $action)); }
|
||||
|
||||
// handle widget updates
|
||||
if (isset($_POST['pw']['_nonce'])) {
|
||||
if (wp_verify_nonce($_POST['pw']['_nonce'], "plugin-wonderful")) { $this->handle_action_save_widgets(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -266,8 +266,31 @@ class PluginWonderfulTest extends PHPUnit_Framework_TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
function testHandleAction() {
|
||||
$this->markTestIncomplete();
|
||||
function providerTestHandleAction() {
|
||||
return array(
|
||||
array(false, false, false),
|
||||
array(true, false, false),
|
||||
array(true, true, true)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerTestHandleAction
|
||||
*/
|
||||
function testHandleAction($has_nonce, $has_verify_nonce, $method_exists) {
|
||||
if ($has_nonce) { $_POST['_pw_nonce'] = "12345"; }
|
||||
_set_valid_nonce('plugin-wonderful', $has_verify_nonce ? '12345' : '54321');
|
||||
|
||||
$pw = $this->getMock('PluginWonderful', $method_exists ? array('handle_action_test') : array('handle_action_invalid'));
|
||||
$_POST['action'] = 'test';
|
||||
|
||||
if ($method_exists) {
|
||||
$pw->expects($this->once())->method('handle_action_test');
|
||||
} else {
|
||||
$pw->expects($this->never())->method('handle_action_invalid');
|
||||
}
|
||||
|
||||
$pw->handle_action();
|
||||
}
|
||||
|
||||
function testHandleActionSaveWidgets() {
|
||||
|
Loading…
Reference in New Issue
Block a user