start work on theme options page
This commit is contained in:
parent
8148765724
commit
bc964971f7
@ -30,8 +30,15 @@ if (defined("CPM_DATE_FORMAT")) {
|
||||
$comic_filename_filters = array();
|
||||
$comic_filename_filters['default'] = "{date}*.*";
|
||||
|
||||
require_once(dirname(__FILE__) . '/options.php');
|
||||
|
||||
// load all of the comic & non-comic category information
|
||||
add_action('init', 'get_all_comic_categories');
|
||||
add_action('init', '__comicpress_init');
|
||||
|
||||
function __comicpress_init() {
|
||||
get_all_comic_categories();
|
||||
add_action('admin_init', '__comicpress_add_options_admin');
|
||||
}
|
||||
|
||||
function get_first_comic() {
|
||||
return get_terminal_post_in_category(get_all_comic_categories_as_cat_string());
|
||||
|
36
options.php
Normal file
36
options.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
class ComicPressOptionsAdmin {
|
||||
function render_admin() {
|
||||
$nonce = wp_create_nonce('comicpress');
|
||||
|
||||
echo '<div class="wrap">';
|
||||
echo '<h2>ComicPress Config</h2>';
|
||||
echo '<form method="post">';
|
||||
echo '<input type="hidden" name="cp[_nonce]" value="' . $nonce . '" />';
|
||||
echo '</form>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
function get_root_categories() {
|
||||
$root_categories = array();
|
||||
foreach (get_all_category_ids() as $id) {
|
||||
$category = get_category($id);
|
||||
if (!empty($category)) {
|
||||
if ($category->parent == 0) {
|
||||
$root_categories[] = $category;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $root_categories;
|
||||
}
|
||||
}
|
||||
|
||||
$comicpress_options_admin = new ComicPressOptionsAdmin();
|
||||
|
||||
function __comicpress_add_options_admin() {
|
||||
global $comicpress_options_admin;
|
||||
add_theme_page(__("ComicPress Options", 'comicpress'), __('ComicPress Options', 'comicpress'), 'edit_themes', basename(__FILE__), array($comicpress_options_admin, 'render_admin'));
|
||||
}
|
||||
|
||||
?>
|
58
test/OptionsPageTest.php
Normal file
58
test/OptionsPageTest.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
require_once('PHPUnit/Framework.php');
|
||||
require_once(dirname(__FILE__) . '/../../mockpress/mockpress.php');
|
||||
require_once(dirname(__FILE__) . '/../options.php');
|
||||
|
||||
class OptionsPageTest extends PHPUnit_Framework_TestCase {
|
||||
function setUp() {
|
||||
_reset_wp();
|
||||
$this->admin = new ComicPressOptionsAdmin();
|
||||
}
|
||||
|
||||
function testShowOptionsPage() {
|
||||
$nonce = wp_create_nonce('comicpress');
|
||||
|
||||
ob_start();
|
||||
$this->admin->render_admin();
|
||||
$source = ob_get_clean();
|
||||
|
||||
$this->assertTrue(($xml = _to_xml($source)) !== false);
|
||||
foreach (array(
|
||||
'//input[@name="cp[_nonce]" and @value="' . $nonce . '"]' => true
|
||||
) as $xpath => $value) {
|
||||
$this->assertTrue(_xpath_test($xml, $xpath, $value), $xpath);
|
||||
}
|
||||
}
|
||||
|
||||
function providerTestGetRootComicCategories() {
|
||||
return array(
|
||||
array(array(), array()),
|
||||
array(
|
||||
array(
|
||||
array('id' => 1, 'parent' => 0),
|
||||
array('id' => 2, 'parent' => 1)
|
||||
),
|
||||
array(1)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerTestGetRootComicCategories
|
||||
*/
|
||||
function testGetRootCategories($categories, $expected_result) {
|
||||
foreach ($categories as $category) {
|
||||
add_category($category['id'], (object)$category);
|
||||
}
|
||||
|
||||
$result_ids = array();
|
||||
foreach ($this->admin->get_root_categories() as $category) {
|
||||
$result_ids[] = $category->term_id;
|
||||
}
|
||||
|
||||
$this->assertEquals($expected_result, $result_ids);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in New Issue
Block a user