From faacafcaf1c6021f58f1d14082b8563afa0a736c Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sat, 14 Nov 2009 12:46:30 -0500 Subject: [PATCH] allow for skipping normalize checks and return raw metadata --- classes/ComicPressComicPost.inc | 8 ++++++-- test/ComicPressComicPostTest.php | 12 ++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/classes/ComicPressComicPost.inc b/classes/ComicPressComicPost.inc index 0cb76ce..4c203dc 100644 --- a/classes/ComicPressComicPost.inc +++ b/classes/ComicPressComicPost.inc @@ -24,13 +24,17 @@ class ComicPressComicPost { /** * Normalize the ordering of attachments in this post. * If images have beed added or removed, intelligently update the metadata. - * TODO Allow skipping of normalization if performance is needed + * @param boolean $skip_checks If true, only return the post metadata, assuming that everything is correct. Do not use anywhere in the admin interface! + * @return array The normalized data, which is also written to the post's metadata if $skip_checks is false. */ - function normalize_ordering() { + function normalize_ordering($skip_checks = false) { $attachments = $this->get_attachments(); if (is_array($attachments)) { $new_ordering = array(); $current_ordering = get_post_meta($this->post->ID, 'image-ordering', true); + + if ($skip_checks) { return $current_ordering; } + if (!is_array($current_ordering)) { $current_ordering = array(); } $all_current_ids = array(); diff --git a/test/ComicPressComicPostTest.php b/test/ComicPressComicPostTest.php index 85905ec..d455aec 100644 --- a/test/ComicPressComicPostTest.php +++ b/test/ComicPressComicPostTest.php @@ -75,6 +75,18 @@ class ComicPressComicPostTest extends PHPUnit_Framework_TestCase { } } + function testNormalizeOrderingSkipChecks() { + $p = $this->getMock('ComicPressComicPost', array('get_attachments')); + + $p->expects($this->once())->method('get_attachments')->will($this->returnValue(array('test', 'test2'))); + + $p->post = (object)array('ID' => 1); + update_post_meta(1, 'image-ordering', array('test' => array('enabled' => true))); + + $this->assertEquals(array('test' => array('enabled' => true)), $p->normalize_ordering(true)); + $this->assertEquals(array('test' => array('enabled' => true)), get_post_meta(1, 'image-ordering', true)); + } + function providerTestUpdatePostMediaData() { return array( array(