blog options with category injection
This commit is contained in:
parent
b41a580502
commit
78b5325a0e
@ -192,4 +192,31 @@ class PostFixtures {
|
||||
$this->remove_all_posts();
|
||||
$this->remove_all_categories();
|
||||
}
|
||||
|
||||
function process_blog_options($options, $categories) {
|
||||
$this->_category = $categories;
|
||||
foreach ($options as $option => $value) {
|
||||
$value = preg_replace_callback('#\$\{([^\}]+)\}#', array(&$this, '_process_blog_options_callback'), $value);
|
||||
update_option($option, $value);
|
||||
}
|
||||
unset($this->_category);
|
||||
}
|
||||
|
||||
function _process_blog_options_callback($matches) {
|
||||
$value = $matches[0];
|
||||
$parts = explode(':', $matches[1]);
|
||||
if (count($parts) > 1) {
|
||||
$source = array_shift($parts);
|
||||
if (count($parts) == 1) {
|
||||
$index = reset($parts);
|
||||
if (isset($this->{"_${source}"})) {
|
||||
if (isset($this->{"_${source}"}[$index])) {
|
||||
$value = $this->{"_${source}"}[$index];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
@ -74,12 +74,14 @@ class PostFixturesTest extends PHPUnit_Framework_TestCase {
|
||||
return array(
|
||||
array(
|
||||
array(
|
||||
array(
|
||||
'title' => 'test',
|
||||
'categories' => array('test1', 'test2'),
|
||||
'date' => '2009-01-01',
|
||||
'metadata' => array(
|
||||
'test' => 'test2'
|
||||
'posts' => array(
|
||||
array(
|
||||
'title' => 'test',
|
||||
'categories' => array('test1', 'test2'),
|
||||
'date' => '2009-01-01',
|
||||
'metadata' => array(
|
||||
'test' => 'test2'
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
@ -218,4 +220,38 @@ class PostFixturesTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
$pf->remove();
|
||||
}
|
||||
|
||||
function providerTestProcessBlogOptions() {
|
||||
return array(
|
||||
array(
|
||||
array(),
|
||||
array('test' => 'test')
|
||||
),
|
||||
array(
|
||||
array('test2' => 'test2'),
|
||||
array('test' => 'test', 'test2' => 'test2')
|
||||
),
|
||||
array(
|
||||
array('test' => false),
|
||||
array('test' => false)
|
||||
),
|
||||
array(
|
||||
array('test' => '${category:category}'),
|
||||
array('test' => '1')
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerTestProcessBlogOptions
|
||||
*/
|
||||
function testProcessBlogOptions($data, $expected_fields) {
|
||||
update_option('test', 'test');
|
||||
|
||||
$this->pf->process_blog_options($data, array('category' => 1));
|
||||
|
||||
foreach ($expected_fields as $name => $value) {
|
||||
$this->assertEquals($value, get_option($name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user