more builder options

This commit is contained in:
John Bintz 2010-01-18 00:15:11 -05:00
parent 0c13247018
commit 8fa8b8fe7c
4 changed files with 36 additions and 2 deletions

View File

@ -39,6 +39,8 @@ create a new Issue.
## Example Fixture
### JSON
<pre>
{
"posts": [
@ -55,7 +57,8 @@ create a new Issue.
"lots", "of", "nested", "datatypes"
]
}
}
},
"tags": "tag 1,tag2"
},
{
"post_date": "2010-01-01 10:00am",
@ -73,3 +76,6 @@ create a new Issue.
}
}
</pre>
### PHP

View File

@ -59,6 +59,13 @@ class FixtureBuilder {
return $this;
}
function content($content) {
$this->check_correct_type('post');
$this->current_object['post']['post_content'] = $content;
return $this;
}
function tags($tags) {
$this->check_correct_type('post');
@ -95,6 +102,11 @@ class FixtureBuilder {
return $this;
}
function option($name, $value) {
update_option($name, $value);
return $this;
}
function defer_category($obj) {
$this->deferred_builds['category'] = array_merge($this->deferred_builds['category'], explode(',', $obj['name']));
}

View File

@ -69,6 +69,9 @@ class PostFixtures {
$builder = new FixtureBuilder();
include($file);
$builder->finalize();
$this->messages[] = __("New data set loaded into WordPress.", 'post-fixtures');
break;
}
}

View File

@ -126,6 +126,10 @@ class FixtureBuilderTest extends PHPUnit_Framework_TestCase {
'date',
array('2010-01-01')
),
array(
'content',
array('Post content')
),
array(
'categories',
array('test')
@ -141,6 +145,7 @@ class FixtureBuilderTest extends PHPUnit_Framework_TestCase {
),
(object)array(
'post_title' => 'Post title',
'post_content' => 'Post content',
'post_type' => 'post',
'post_date' => '2010-01-01',
'post_status' => 'publish',
@ -150,6 +155,7 @@ class FixtureBuilderTest extends PHPUnit_Framework_TestCase {
'posts' => array(
1 => (object)array(
'post_title' => 'Post title',
'post_content' => 'Post content',
'post_type' => 'post',
'post_date' => '2010-01-01',
'post_status' => 'publish',
@ -168,7 +174,7 @@ class FixtureBuilderTest extends PHPUnit_Framework_TestCase {
)
)
)
)
),
);
}
@ -228,4 +234,11 @@ class FixtureBuilderTest extends PHPUnit_Framework_TestCase {
$fb->finalize();
}
function testOption() {
$fb = new FixtureBuilder();
$fb->option('test', 'value');
$this->assertEquals('value', get_option('test'));
}
}