category normalization

This commit is contained in:
John Bintz 2009-11-23 21:22:15 -05:00
parent c205f9f81b
commit f279ed8904
2 changed files with 45 additions and 3 deletions

View File

@ -320,6 +320,8 @@ class ComicPressStoryline {
} }
$all_categories_flattened = $this->get_category_flattened(); $all_categories_flattened = $this->get_category_flattened();
$this->normalize_category_groupings();
$result = $this->normalize_flattened_storyline($flattened_storyline, $all_categories_flattened); $result = $this->normalize_flattened_storyline($flattened_storyline, $all_categories_flattened);
if ($set) { if ($set) {
$this->set_flattened_storyline($result); $this->set_flattened_storyline($result);
@ -328,11 +330,21 @@ class ComicPressStoryline {
} }
/** /**
* TODO finish this method
* @return unknown_type * @return unknown_type
*/ */
function normalize_category_groupings() { function normalize_category_groupings() {
$comicpress = ComicPress::get_instance(); $comicpress = ComicPress::get_instance();
$valid_ids = get_all_category_ids();
foreach ($comicpress->comicpress_options['category_groupings'] as $group_id => $category_ids) {
$comicpress->comicpress_options['category_groupings'][$group_id] = array_intersect($category_ids, $valid_ids);
if (empty($comicpress->comicpress_options['category_groupings'][$group_id])) {
unset($comicpress->comicpress_options['category_groupings'][$group_id]);
}
}
$comicpress->save();
} }
/** /**

View File

@ -639,6 +639,9 @@ class ComicPressStorylineTest extends PHPUnit_Framework_TestCase {
* @dataProvider providerTestNormalize * @dataProvider providerTestNormalize
*/ */
function testNormalize($flattened_storyline, $do_set) { function testNormalize($flattened_storyline, $do_set) {
$comicpress = ComicPress::get_instance();
$comicpress->comicpress_options['category_groupings'] = array();
$css = $this->getMock('ComicPressStoryline', array('get_flattened_storyline', 'get_category_flattened', 'normalize_flattened_storyline', 'set_flattened_storyline')); $css = $this->getMock('ComicPressStoryline', array('get_flattened_storyline', 'get_category_flattened', 'normalize_flattened_storyline', 'set_flattened_storyline'));
$css->expects(is_null($flattened_storyline) ? $this->once() : $this->never())->method('get_flattened_storyline'); $css->expects(is_null($flattened_storyline) ? $this->once() : $this->never())->method('get_flattened_storyline');
$css->expects($do_set ? $this->once() : $this->never())->method('set_flattened_storyline'); $css->expects($do_set ? $this->once() : $this->never())->method('set_flattened_storyline');
@ -698,8 +701,35 @@ class ComicPressStorylineTest extends PHPUnit_Framework_TestCase {
$this->assertEquals($expected_id, $this->css->_ensure_category_ids($string)); $this->assertEquals($expected_id, $this->css->_ensure_category_ids($string));
} }
function testNormalizeCategoryGroupings() { function providerTestNormalizeCategoryGroupings() {
$this->markTestIncomplete(); return array(
array(
array('test' => array(1,2)),
array(1,2),
array('test' => array(1,2))
),
array(
array('test' => array(1,2)),
array(1),
array('test' => array(1))
),
);
}
/**
* @dataProvider providerTestNormalizeCategoryGroupings
*/
function testNormalizeCategoryGroupings($grouping, $valid_categories, $expected_grouping) {
$comicpress = ComicPress::get_instance();
$comicpress->comicpress_options['category_groupings'] = $grouping;
foreach ($valid_categories as $category_id) {
add_category($category_id, (object)array('slug' => "test-${category_id}"));
}
$this->css->normalize_category_groupings();
$this->assertEquals($expected_grouping, $comicpress->comicpress_options['category_groupings']);
} }
} }