save post for admin

This commit is contained in:
John Bintz 2010-02-12 16:55:11 -05:00
parent 195ac26b8a
commit feeceaf1fa
2 changed files with 112 additions and 12 deletions

View File

@ -376,9 +376,12 @@ class ComicPressBackendFilesystemAdmin {
function save_post($post_id) { function save_post($post_id) {
if (isset($_POST['cp'])) { if (isset($_POST['cp'])) {
$info = $_POST['cp']; $info = $_POST['cp'];
if (is_array($info)) {
if (isset($info['attachments'])) { if (isset($info['attachments'])) {
if (is_array($info['attachments'])) {
$image_meta_updates = array(); $image_meta_updates = array();
foreach ($info['attachments'] as $id => $properties) { foreach ($info['attachments'] as $id => $properties) {
if (is_array($properties)) {
if ($backend = ComicPressBackend::generate_from_id($id)) { if ($backend = ComicPressBackend::generate_from_id($id)) {
if (is_a($backend, 'ComicPressBackendFilesystem')) { if (is_a($backend, 'ComicPressBackendFilesystem')) {
$image_meta_updates[$backend->root] = array(); $image_meta_updates[$backend->root] = array();
@ -392,10 +395,13 @@ class ComicPressBackendFilesystemAdmin {
} }
} }
} }
}
update_post_meta($post_id, 'backend_filesystem_image_meta', $image_meta_updates); update_post_meta($post_id, 'backend_filesystem_image_meta', $image_meta_updates);
} }
} }
} }
}
}
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart

View File

@ -0,0 +1,94 @@
<?php
require_once('PHPUnit/Framework.php');
require_once('MockPress/mockpress.php');
require_once('backends/ComicPressBackendFilesystem.inc');
require_once('ComicPress.inc');
class ComicPressBackendFilesystemAdminTest extends PHPUnit_Framework_TestCase {
function providerTestSavePost() {
return array(
array(
array(), array()
),
array(
array('cp' => 'test'), array()
),
array(
array('cp' => array(
'attachments' => 'test'
)), array()
),
array(
array('cp' => array(
'attachments' => array(
'bad' => 'bad'
)
)), array()
),
array(
array('cp' => array(
'attachments' => array(
'filesystem' => 'bad'
)
)), array()
),
array(
array('cp' => array(
'attachments' => array(
'filesystem' => array(
'bad' => 'bad'
)
)
)), array(
'root' => array(
'alt_text' => '',
'title_text' => ''
)
)
),
array(
array('cp' => array(
'attachments' => array(
'filesystem' => array(
'alt_text' => 'alt'
)
)
)), array(
'root' => array(
'alt_text' => 'alt',
'title_text' => ''
)
)
),
);
}
/**
* @dataProvider providerTestSavePost
*/
function testSavePost($post, $expected_post_meta) {
$filesystem = $this->getMock('ComicPressBackendFilesystem');
$filesystem->root = 'root';
$faulty = (object)array('not a' => 'backend');
$factory = $this->getMock('ComicPressSavePostBackend', array('generate_from_id'));
$factory->expects($this->any())
->method('generate_from_id')
->will($this->returnCallback(function($id) use ($filesystem, $faulty) {
return ($id == 'filesystem') ? $filesystem : $faulty;
}));
$comicpress = ComicPress::get_instance(true);
$comicpress->backends = array($factory);
$_POST = $post;
update_post_meta(1, 'backend_filesystem_image_meta', array());
ComicPressBackendFilesystemAdmin::save_post(1);
$this->assertEquals($expected_post_meta, get_post_meta(1, 'backend_filesystem_image_meta', true));
}
}