tags support
This commit is contained in:
parent
9258e1f4e7
commit
0c13247018
@ -59,6 +59,13 @@ class FixtureBuilder {
|
||||
return $this;
|
||||
}
|
||||
|
||||
function tags($tags) {
|
||||
$this->check_correct_type('post');
|
||||
|
||||
$this->current_object['post']['tags'] = explode(',', $tags);
|
||||
return $this;
|
||||
}
|
||||
|
||||
function defer() {
|
||||
if (!empty($this->current_object)) {
|
||||
$this->ensure_type($this->current_object['type']);
|
||||
@ -102,7 +109,7 @@ class FixtureBuilder {
|
||||
|
||||
function build_post($obj) {
|
||||
$post_obj = $obj['post'];
|
||||
foreach (array('categories', 'metadata') as $field) {
|
||||
foreach (array('categories', 'metadata', 'tags') as $field) {
|
||||
unset($post_obj[$field]);
|
||||
}
|
||||
$post_id = PostFixtures::create_post($post_obj);
|
||||
@ -124,6 +131,10 @@ class FixtureBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($obj['post']['tags'])) {
|
||||
PostFixtures::create_post_tags($post_id, $obj['post']['tags']);
|
||||
}
|
||||
|
||||
return get_post($post_id);
|
||||
}
|
||||
// @codeCoverageIgnoreStart
|
||||
|
@ -293,6 +293,10 @@ class PostFixtures {
|
||||
$this->create_post_metadata($id, $key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($post['tags'])) {
|
||||
$this->create_post_tags($id, $post['tags']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -311,6 +315,10 @@ class PostFixtures {
|
||||
update_post_meta($post_id, $key, $value);
|
||||
}
|
||||
|
||||
function create_post_tags($post_id, $tags) {
|
||||
wp_set_post_tags($post_id, $tags);
|
||||
}
|
||||
|
||||
function set_post_categories($post_id, $categories) {
|
||||
wp_set_post_categories($post_id, $categories);
|
||||
}
|
||||
|
@ -133,6 +133,10 @@ class FixtureBuilderTest extends PHPUnit_Framework_TestCase {
|
||||
array(
|
||||
'metadata',
|
||||
array('test', 'test2')
|
||||
),
|
||||
array(
|
||||
'tags',
|
||||
array('tag1,tag2')
|
||||
)
|
||||
),
|
||||
(object)array(
|
||||
@ -140,7 +144,7 @@ class FixtureBuilderTest extends PHPUnit_Framework_TestCase {
|
||||
'post_type' => 'post',
|
||||
'post_date' => '2010-01-01',
|
||||
'post_status' => 'publish',
|
||||
'ID' => 1
|
||||
'ID' => 1
|
||||
),
|
||||
array(
|
||||
'posts' => array(
|
||||
@ -155,6 +159,9 @@ class FixtureBuilderTest extends PHPUnit_Framework_TestCase {
|
||||
'categories' => array(
|
||||
1 => 'test'
|
||||
),
|
||||
'tags' => array(
|
||||
1 => array('tag1', 'tag2')
|
||||
),
|
||||
'post_meta' => array(
|
||||
1 => array(
|
||||
'test' => 'test2'
|
||||
|
@ -163,7 +163,11 @@ class PostFixturesTest extends PHPUnit_Framework_TestCase {
|
||||
)
|
||||
),
|
||||
array(1),
|
||||
array(1 => array(1))
|
||||
array(
|
||||
'categories' => array(
|
||||
1 => array(1)
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
array(
|
||||
@ -173,7 +177,11 @@ class PostFixturesTest extends PHPUnit_Framework_TestCase {
|
||||
)
|
||||
),
|
||||
array(1),
|
||||
array(1 => array(2))
|
||||
array(
|
||||
'categories' => array(
|
||||
1 => array(2)
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
array(
|
||||
@ -182,14 +190,24 @@ class PostFixturesTest extends PHPUnit_Framework_TestCase {
|
||||
'categories' => array('test2'),
|
||||
'metadata' => array(
|
||||
'test' => 'test2'
|
||||
),
|
||||
'tags' => array(
|
||||
'tag1', 'tag2'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(1),
|
||||
array(1 => array(2)),
|
||||
array(1 => array(
|
||||
'test' => 'test2'
|
||||
))
|
||||
array(
|
||||
'categories' => array(
|
||||
1 => array(2)
|
||||
),
|
||||
'metadata' => array(
|
||||
1 => array('test' => 'test2')
|
||||
),
|
||||
'tags' => array(
|
||||
1 => array('tag1', 'tag2')
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
array(
|
||||
@ -199,7 +217,11 @@ class PostFixturesTest extends PHPUnit_Framework_TestCase {
|
||||
)
|
||||
),
|
||||
array(1),
|
||||
array(1 => array(1,3))
|
||||
array(
|
||||
'categories' => array(
|
||||
1 => array(1,3)
|
||||
)
|
||||
)
|
||||
),
|
||||
);
|
||||
}
|
||||
@ -207,22 +229,45 @@ class PostFixturesTest extends PHPUnit_Framework_TestCase {
|
||||
/**
|
||||
* @dataProvider providerTestCreatePosts
|
||||
*/
|
||||
function testCreatePosts($posts, $expected_post_ids, $expected_post_categories = false, $expected_metadata = false) {
|
||||
function testCreatePosts($posts, $expected_post_ids, $expected_additional_info = false) {
|
||||
global $wp_test_expectations;
|
||||
|
||||
update_option('default_category', 1);
|
||||
wp_insert_category(array('slug' => 'test'));
|
||||
|
||||
$this->assertEquals($expected_post_ids, $this->pf->create_posts($posts, array('test' => 1, 'test2' => 2, 'test2/test3' => 3)));
|
||||
|
||||
if (is_array($expected_post_categories)) {
|
||||
foreach ($expected_post_categories as $post_id => $categories) {
|
||||
$this->assertEquals($categories, wp_get_post_categories($post_id));
|
||||
}
|
||||
}
|
||||
if (is_array($expected_additional_info)) {
|
||||
extract($expected_additional_info);
|
||||
|
||||
if (is_array($expected_metadata)) {
|
||||
foreach ($expected_metadata as $post_id => $metadata_info) {
|
||||
foreach ($metadata_info as $key => $value) {
|
||||
$this->assertEquals($value, get_post_meta($post_id, $key, true));
|
||||
if (isset($categories)) {
|
||||
if (is_array($categories)) {
|
||||
foreach ($categories as $post_id => $cats) {
|
||||
$this->assertEquals($cats, wp_get_post_categories($post_id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($metadata)) {
|
||||
if (is_array($metadata)) {
|
||||
foreach ($metadata as $post_id => $metadata_info) {
|
||||
foreach ($metadata_info as $key => $value) {
|
||||
$this->assertEquals($value, get_post_meta($post_id, $key, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($tags)) {
|
||||
if (is_array($tags)) {
|
||||
foreach ($tags as $post_id => $expected_tags) {
|
||||
$post_tags = wp_get_post_tags($post_id);
|
||||
foreach ($post_tags as &$tag) {
|
||||
$tag = $tag->slug;
|
||||
}
|
||||
|
||||
$this->assertEquals($post_tags, $expected_tags);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user