gut more stuff

This commit is contained in:
John Bintz 2009-11-07 22:47:28 -05:00
parent cab85e5f60
commit ead478fcec
3 changed files with 39 additions and 185 deletions

View File

@ -143,7 +143,6 @@ class ComicPressAdmin {
*/ */
function render_admin() { function render_admin() {
$nonce = wp_create_nonce('comicpress'); $nonce = wp_create_nonce('comicpress');
$root_categories = $this->get_root_categories();
$storyline = new ComicPressStoryline(); $storyline = new ComicPressStoryline();
$storyline->normalize(); $storyline->normalize();
$storyline->read_from_options(); $storyline->read_from_options();
@ -202,52 +201,6 @@ class ComicPressAdmin {
} }
} }
/**
* Get all categories with a parent ID of 0.
* @return array All root categories.
*/
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;
}
/**
* Create <option> elements for each of the provided categories.
* @param array $categories The categories to display as either IDs or category objects.
* @param int $selected_id The category to mark as selected.
* @return string The category options as HTML.
*/
function create_category_options($categories, $selected_id) {
$output = array();
if (is_array($categories)) {
$final_categories = array();
foreach ($categories as $category) {
if (is_numeric($category)) {
$result = get_category($category);
if (!(is_a($result, "WP_Error") || empty($result))) {
$final_categories[] = $result;
}
}
if (is_object($category)) {
$final_categories[] = $category;
}
}
foreach ($final_categories as $category) {
$output[] = '<option value="' . $category->term_id . '"' . (($category->term_id == $selected_id) ? ' selected="selected"' : '') . '>' . $category->name . '</option>';
}
}
return implode("\n", $output);
}
/** /**
* Create a dimension selector. * Create a dimension selector.
* @param string $root The field name root. * @param string $root The field name root.
@ -303,14 +256,6 @@ class ComicPressAdmin {
foreach ($this->comicpress->comicpress_options as $option => $value) { foreach ($this->comicpress->comicpress_options as $option => $value) {
if (isset($info[$option])) { if (isset($info[$option])) {
switch ($option) { switch ($option) {
case 'comic_category_id':
if (is_numeric($info[$option])) {
$result = get_category($info[$option]);
if (!(is_a($result, 'WP_Error') || empty($result))) {
$this->comicpress->comicpress_options[$option] = $info[$option];
}
}
break;
case 'comic_dimensions': case 'comic_dimensions':
case 'rss_dimensions': case 'rss_dimensions':
case 'archive_dimensions': case 'archive_dimensions':
@ -336,14 +281,6 @@ class ComicPressAdmin {
} }
} }
break; break;
case 'blogpost_count':
$this->comicpress->comicpress_options[$option] = (int)$info[$option];
break;
case 'comic_space':
case 'category_usage':
case 'layout';
$this->comicpress->comicpress_options[$option] = $info[$option];
break;
case 'helpers': case 'helpers':
case 'addons': case 'addons':
foreach ($info[$option] as $type => $set) { foreach ($info[$option] as $type => $set) {

View File

@ -30,12 +30,6 @@
</td> </td>
</tr> </tr>
<?php } ?> <?php } ?>
<tr>
<th scope="row" valign="top"><?php _e("Number of blog posts on home page", 'comicpress') ?></th>
<td>
<input type="text" name="cp[blogpost_count]" value="<?php echo $this->comicpress->comicpress_options['blogpost_count'] ?>" size="3" />
</td>
</tr>
</table> </table>
<h3><?php _e('Admin Options', 'comicpress') ?></h3> <h3><?php _e('Admin Options', 'comicpress') ?></h3>
<table class="widefat fixed"> <table class="widefat fixed">

View File

@ -11,56 +11,6 @@ class ComicPressAdminTest extends PHPUnit_Framework_TestCase {
$this->admin = new ComicPressAdmin(); $this->admin = new ComicPressAdmin();
} }
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);
}
function testCreateCategoryOptions() {
add_category(1, (object)array('name' => 'test-one'));
add_category(2, (object)array('name' => 'test-two'));
foreach(array(
array(1,2),
array(get_category(1), get_category(2))
) as $category_test) {
$source = $this->admin->create_category_options($category_test, 1);
$this->assertTrue(($xml = _to_xml($source, true)) !== false);
foreach (array(
'//option[@value="1" and @selected="selected"]' => "test-one",
'//option[@value="2"]' => "test-two",
) as $xpath => $value) {
$this->assertTrue(_xpath_test($xml, $xpath, $value), $xpath);
}
}
}
function testCreateDimensionSelector() { function testCreateDimensionSelector() {
$source = $this->admin->create_dimension_selector("test", "760x340"); $source = $this->admin->create_dimension_selector("test", "760x340");
@ -76,32 +26,6 @@ class ComicPressAdminTest extends PHPUnit_Framework_TestCase {
function providerTestHandleUpdate() { function providerTestHandleUpdate() {
return array( return array(
array(
array('comic_category_id' => 1),
array('comic_category_id' => 2),
array('comic_category_id' => 1)
),
array(
array('comic_category_id' => 1),
array('cp' => array(
'comic_category_id' => 2),
),
array('comic_category_id' => 2)
),
array(
array('comic_category_id' => 1),
array('cp' => array(
'comic_category_id' => "cat"),
),
array('comic_category_id' => 1)
),
array(
array('comic_category_id' => 1),
array('cp' => array(
'comic_category_id' => 3
)),
array('comic_category_id' => 1)
),
array( array(
array('comic_dimensions' => '150x150'), array('comic_dimensions' => '150x150'),
array('cp' => array( array('cp' => array(
@ -138,7 +62,6 @@ class ComicPressAdminTest extends PHPUnit_Framework_TestCase {
function testHandleUpdate($original, $change, $new) { function testHandleUpdate($original, $change, $new) {
$this->admin->comicpress = $this->getMock('ComicPress', array('save', 'init')); $this->admin->comicpress = $this->getMock('ComicPress', array('save', 'init'));
$this->admin->comicpress->comicpress_options = array( $this->admin->comicpress->comicpress_options = array(
'comic_category_id' => 1,
'comic_dimensions' => '760x', 'comic_dimensions' => '760x',
'rss_dimensions' => '350x', 'rss_dimensions' => '350x',
'archive_dimensions' => '125x' 'archive_dimensions' => '125x'