process data

This commit is contained in:
John Bintz 2009-11-22 18:11:59 -05:00
parent 95d7498101
commit fe4f6a867b
2 changed files with 48 additions and 0 deletions

View File

@ -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');
}
}

View File

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