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)); + } }