update options

This commit is contained in:
John Bintz 2010-02-12 18:08:17 -05:00
parent feeceaf1fa
commit e4651dfc5b
2 changed files with 83 additions and 18 deletions

View File

@ -348,7 +348,9 @@ class ComicPressBackendFilesystemAdmin {
// @codeCoverageIgnoreEnd
function handle_update_comicpress_options($info) {
if (is_array($info)) {
if (isset($info['backend_options']['filesystem'])) {
if (is_array($info['backend_options']['filesystem'])) {
$info = $info['backend_options']['filesystem'];
$comicpress = ComicPress::get_instance();
@ -360,6 +362,7 @@ class ComicPressBackendFilesystemAdmin {
}
foreach (array('folders', 'search_pattern', 'url_pattern') as $valid_field) {
if (isset($info[$valid_field])) {
if (is_array($info[$valid_field])) {
$comicpress->comicpress_options['backend_options']['filesystem'][$valid_field] = array();
foreach ($info[$valid_field] as $field => $value) {
@ -369,9 +372,12 @@ class ComicPressBackendFilesystemAdmin {
$comicpress->comicpress_options['backend_options']['filesystem'][$valid_field] = strip_tags($info[$valid_field]);
}
}
}
$comicpress->save();
}
}
}
}
function save_post($post_id) {
if (isset($_POST['cp'])) {

View File

@ -90,5 +90,64 @@ class ComicPressBackendFilesystemAdminTest extends PHPUnit_Framework_TestCase {
ComicPressBackendFilesystemAdmin::save_post(1);
$this->assertEquals($expected_post_meta, get_post_meta(1, 'backend_filesystem_image_meta', true));
$comicpress = ComicPress::get_instance(true);
}
function providerTestUpdateComicPressOptions() {
return array(
array(false, array()),
array(array(), array()),
array(
array('backend_options' => array(
'filesystem' => 'test'
)),
array()
),
array(
array('backend_options' => array(
'filesystem' => array()
)),
array(
'backend_options' => array('filesystem' => array())
)
),
array(
array('backend_options' => array(
'filesystem' => array(
'search_pattern' => '<b>value</b>',
'url_pattern' => '<b>value</b>',
'folders' => array(
'one' => '<b>value</b>',
'two' => '<b>value</b>',
),
)
)),
array(
'backend_options' => array('filesystem' => array(
'search_pattern' => 'value',
'url_pattern' => 'value',
'folders' => array(
'one' => 'value',
'two' => 'value'
)
))
)
),
);
}
/**
* @dataProvider providerTestUpdateComicPressOptions
*/
function testUpdateComicPressOptions($info, $expected_comicpress_options) {
$comicpress = ComicPress::get_instance(true);
$comicpress->comicpress_options = array();
ComicPressBackendFilesystemAdmin::handle_update_comicpress_options($info);
$this->assertEquals($expected_comicpress_options, $comicpress->comicpress_options);
$comicpress = ComicPress::get_instance(true);
}
}