category options

This commit is contained in:
John Bintz 2009-07-05 15:15:53 -04:00
parent 1abd155217
commit d8a8a9aa2a
2 changed files with 48 additions and 1 deletions

View File

@ -19,6 +19,29 @@ class ComicPressOptionsAdmin {
} }
return $root_categories; return $root_categories;
} }
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")) {
$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);
}
} }
$comicpress_options_admin = new ComicPressOptionsAdmin(); $comicpress_options_admin = new ComicPressOptionsAdmin();

View File

@ -19,7 +19,8 @@ class OptionsPageTest extends PHPUnit_Framework_TestCase {
$this->assertTrue(($xml = _to_xml($source)) !== false); $this->assertTrue(($xml = _to_xml($source)) !== false);
foreach (array( foreach (array(
'//input[@name="cp[_nonce]" and @value="' . $nonce . '"]' => true '//input[@name="cp[_nonce]" and @value="' . $nonce . '"]' => true,
'//select[@name="cp[comiccat]"]' => true
) as $xpath => $value) { ) as $xpath => $value) {
$this->assertTrue(_xpath_test($xml, $xpath, $value), $xpath); $this->assertTrue(_xpath_test($xml, $xpath, $value), $xpath);
} }
@ -53,6 +54,29 @@ class OptionsPageTest extends PHPUnit_Framework_TestCase {
$this->assertEquals($expected_result, $result_ids); $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);
var_dump($source);
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);
}
}
}
} }
?> ?>