diff --git a/options.php b/options.php index 91b210a..1699aaf 100644 --- a/options.php +++ b/options.php @@ -19,6 +19,29 @@ class ComicPressOptionsAdmin { } 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[] = ''; + } + } + return implode("\n", $output); + } } $comicpress_options_admin = new ComicPressOptionsAdmin(); diff --git a/test/OptionsPageTest.php b/test/OptionsPageTest.php index e6fafef..76e1eb6 100644 --- a/test/OptionsPageTest.php +++ b/test/OptionsPageTest.php @@ -19,7 +19,8 @@ class OptionsPageTest extends PHPUnit_Framework_TestCase { $this->assertTrue(($xml = _to_xml($source)) !== false); 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) { $this->assertTrue(_xpath_test($xml, $xpath, $value), $xpath); } @@ -53,6 +54,29 @@ class OptionsPageTest extends PHPUnit_Framework_TestCase { $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); + } + } + } } ?>