non-html code coverage
This commit is contained in:
parent
99afbd9ee8
commit
6765862e68
@ -9,15 +9,29 @@ class PostFixtures {
|
|||||||
/**
|
/**
|
||||||
* Initialize the plugin.
|
* Initialize the plugin.
|
||||||
*/
|
*/
|
||||||
|
// @codeCoverageIgnoreStart
|
||||||
function init() {
|
function init() {
|
||||||
add_action('admin_menu', array(&$this, 'admin_menu'));
|
foreach (array(
|
||||||
add_action('admin_notices', array(&$this, 'admin_notices'));
|
'admin_init' => array(),
|
||||||
add_action("admin_enqueue_scripts", array(&$this, 'admin_enqueue_scripts'), 10, 1);
|
'admin_menu' => array(),
|
||||||
|
'admin_notices' => array(),
|
||||||
|
'admin_enqueue_scripts' => array(10, 1),
|
||||||
|
) as $method => $additional_params) {
|
||||||
|
call_user_func_array(
|
||||||
|
'add_action',
|
||||||
|
array_merge(
|
||||||
|
array($method, array(&$this, $method)),
|
||||||
|
$additional_params
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Print any admin notices.
|
* Print any admin notices.
|
||||||
*/
|
*/
|
||||||
|
// @codeCoverageIgnoreStart
|
||||||
function admin_notices() {
|
function admin_notices() {
|
||||||
if (!empty($this->messages)) { ?>
|
if (!empty($this->messages)) { ?>
|
||||||
<div class="fade updated">
|
<div class="fade updated">
|
||||||
@ -27,6 +41,7 @@ class PostFixtures {
|
|||||||
</div>
|
</div>
|
||||||
<?php }
|
<?php }
|
||||||
}
|
}
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle an update.
|
* Handle an update.
|
||||||
@ -49,30 +64,39 @@ class PostFixtures {
|
|||||||
/**
|
/**
|
||||||
* Handle the admin_menu action.
|
* Handle the admin_menu action.
|
||||||
*/
|
*/
|
||||||
|
// @codeCoverageIgnoreStart
|
||||||
function admin_menu() {
|
function admin_menu() {
|
||||||
global $plugin_page;
|
global $plugin_page;
|
||||||
|
|
||||||
$this->hook_suffix = add_submenu_page('tools.php', __('Post Fixtures', 'post-fixtures'), __('Post Fixtures', 'post-fixtures'), 'manage_options', 'post-fixtures', array(&$this, 'render_admin'));
|
$this->hook_suffix = add_submenu_page('tools.php', __('Post Fixtures', 'post-fixtures'), __('Post Fixtures', 'post-fixtures'), 'manage_options', 'post-fixtures', array(&$this, 'render_admin'));
|
||||||
|
}
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
|
|
||||||
if (isset($_POST['pf'])) {
|
/**
|
||||||
if (isset($_POST['pf']['_nonce'])) {
|
* Handle the admin_init action.
|
||||||
if (wp_verify_nonce($_POST['pf']['_nonce'], 'post-fixtures')) {
|
* This is where the processing happens.
|
||||||
$this->handle_update($_POST['pf']);
|
*/
|
||||||
}
|
function admin_init() {
|
||||||
|
if (isset($_POST['pf']['_nonce'])) {
|
||||||
|
if (wp_verify_nonce($_POST['pf']['_nonce'], 'post-fixtures')) {
|
||||||
|
$this->handle_update($_POST['pf']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
unset($_POST['pf']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle the admin_enqueue_scripts action.
|
* Handle the admin_enqueue_scripts action.
|
||||||
* @param string $hook_suffix The hook suffix for the page being loaded.
|
* @param string $hook_suffix The hook suffix for the page being loaded.
|
||||||
*/
|
*/
|
||||||
|
// @codeCoverageIgnoreStart
|
||||||
function admin_enqueue_scripts($hook_suffix) {
|
function admin_enqueue_scripts($hook_suffix) {
|
||||||
if ($this->hook_suffix == $hook_suffix) {
|
if ($this->hook_suffix == $hook_suffix) {
|
||||||
wp_enqueue_script('jquery');
|
wp_enqueue_script('jquery');
|
||||||
wp_enqueue_style('post-fixtures', plugin_dir_url(dirname(__FILE__)) . 'style.css');
|
wp_enqueue_style('post-fixtures', plugin_dir_url(dirname(__FILE__)) . 'style.css');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render the admin page.
|
* Render the admin page.
|
||||||
|
@ -9,6 +9,11 @@ class PostFixturesTest extends PHPUnit_Framework_TestCase {
|
|||||||
_reset_wp();
|
_reset_wp();
|
||||||
|
|
||||||
$this->pf = new PostFixtures();
|
$this->pf = new PostFixtures();
|
||||||
|
$_POST = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
function tearDown() {
|
||||||
|
$_POST = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
function providerTestParseJSON() {
|
function providerTestParseJSON() {
|
||||||
@ -278,4 +283,51 @@ class PostFixturesTest extends PHPUnit_Framework_TestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function providerTestHandleUpdate() {
|
||||||
|
return array(
|
||||||
|
array(array(), false),
|
||||||
|
array(array('is_ok' => true, 'data' => '{]'), false),
|
||||||
|
array(array('is_ok' => true, 'data' => '{"test": "test"}'), true),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider providerTestHandleUpdate
|
||||||
|
*/
|
||||||
|
function testHandleUpdate($info, $should_succeed) {
|
||||||
|
$pf = $this->getMock('PostFixtures', array('process_data', 'remove', 'create'));
|
||||||
|
|
||||||
|
foreach (array('process_data', 'remove', 'create') as $method) {
|
||||||
|
$pf->expects($this->{$should_succeed ? 'once' : 'never'}())->method($method);
|
||||||
|
}
|
||||||
|
|
||||||
|
$pf->handle_update($info);
|
||||||
|
}
|
||||||
|
|
||||||
|
function providerTestAdminInit() {
|
||||||
|
return array(
|
||||||
|
array(array(), false),
|
||||||
|
array(array('pf' => false), false),
|
||||||
|
array(array('pf' => array()), false),
|
||||||
|
array(array('pf' => array('_nonce' => false)), false),
|
||||||
|
array(array('pf' => array('_nonce' => 'post-fixtures')), true),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider providerTestAdminInit
|
||||||
|
*/
|
||||||
|
function testAdminInit($post, $should_update) {
|
||||||
|
$_POST = $post;
|
||||||
|
|
||||||
|
$pf = $this->getMock('PostFixtures', array('handle_update'));
|
||||||
|
$pf->expects($this->{$should_update ? 'once' : 'never'}())->method('handle_update');
|
||||||
|
|
||||||
|
_set_valid_nonce('post-fixtures', 'post-fixtures');
|
||||||
|
|
||||||
|
$pf->admin_init();
|
||||||
|
|
||||||
|
$this->assertTrue(!isset($_POST['pf']));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user