From fe4f6a867b3890cc27cf4dbbb814687b5daa3aff Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sun, 22 Nov 2009 18:11:59 -0500 Subject: [PATCH] process data --- classes/PostFixtures.inc | 11 +++++++++++ test/PostFixturesTest.php | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/classes/PostFixtures.inc b/classes/PostFixtures.inc index cdb3233..0c5a486 100644 --- a/classes/PostFixtures.inc +++ b/classes/PostFixtures.inc @@ -21,4 +21,15 @@ class PostFixtures { wp_delete_category($id); } } + + function process_data($data) { + $posts = $data; + $categories = array(); + foreach ($data as $post) { + if (isset($post['categories'])) { + $categories = array_merge($categories, $post['categories']); + } + } + return compact('posts', 'categories'); + } } diff --git a/test/PostFixturesTest.php b/test/PostFixturesTest.php index 3cb8788..69f9b6a 100644 --- a/test/PostFixturesTest.php +++ b/test/PostFixturesTest.php @@ -69,4 +69,41 @@ class PostFixturesTest extends PHPUnit_Framework_TestCase { $result = get_category(0); $this->assertTrue(isset($result->term_id)); } + + function providerTestProcessData() { + return array( + array( + array( + array( + 'title' => 'test', + 'categories' => array('test1', 'test2'), + 'date' => '2009-01-01', + 'metadata' => array( + 'test' => 'test2' + ) + ) + ), + array( + 'posts' => array( + array( + 'title' => 'test', + 'categories' => array('test1', 'test2'), + 'date' => '2009-01-01', + 'metadata' => array( + 'test' => 'test2' + ) + ) + ), + 'categories' => array('test1', 'test2') + ) + ), + ); + } + + /** + * @dataProvider providerTestProcessData + */ + function testProcessData($data, $expected_output) { + $this->assertEquals($expected_output, $this->pf->process_data($data)); + } }