From d55cc95d6b4d9fa7a6b2f4575d2f7f864774abd8 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 21 Jul 2009 11:00:23 -0700 Subject: [PATCH] clean up attachments testing --- addons/Core/test/OptionsPageTest.php | 90 ++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/addons/Core/test/OptionsPageTest.php b/addons/Core/test/OptionsPageTest.php index e500aa7..259d751 100644 --- a/addons/Core/test/OptionsPageTest.php +++ b/addons/Core/test/OptionsPageTest.php @@ -295,6 +295,96 @@ class CoreTest extends PHPUnit_Framework_TestCase { $this->assertEquals($new_order, $this->core->comicpress->comicpress_options['category_order']); } + + function providerTestUpdateAttachments() { + return array( + array( + array( + 'post_meta' => array(), + ), + array( + 'comic_image_type' => "test" + ), + array( + 'post_meta' => array( + 'comic_image_type' => "test" + ), + ), + ), + array( + array( + 'post' => array( + 'post_parent' => 0 + ), + ), + array( + 'post_parent' => "2" + ), + array( + 'post' => array( + 'post_parent' => 0 + ), + ), + ), + array( + array( + 'post' => array( + 'post_parent' => 0 + ), + ), + array( + 'post_parent' => "2", + 'auto_attach' => 1 + ), + array( + 'post' => array( + 'post_parent' => 2 + ), + ), + ) + ); + } + + /** + * @dataProvider providerTestUpdateAttachments + */ + function testUpdateAttachments($original_settings, $changes, $expected_settings) { + foreach ($original_settings as $settings_type => $settings) { + switch ($settings_type) { + case "post_meta": + foreach ($settings as $key => $value) { + update_post_meta(1, $key, $value); + } + break; + case "post": + wp_insert_post((object)array_merge(array( + 'ID' => 1 + ), $settings)); + break; + } + } + + $_POST = array( + 'attachments' => array('1' => $changes) + ); + + $this->core->handle_update_attachments(); + + foreach ($expected_settings as $settings_type => $settings) { + switch ($settings_type) { + case "post_meta": + foreach ($settings as $key => $value) { + $this->assertEquals($value, get_post_meta(1, $key, true)); + } + break; + case "post": + $post = get_post(1); + foreach ($settings as $key => $value) { + $this->assertEquals($value, $post->{$key}); + } + } + } + } } ?>