save post for admin
This commit is contained in:
parent
195ac26b8a
commit
feeceaf1fa
@ -376,23 +376,29 @@ class ComicPressBackendFilesystemAdmin {
|
||||
function save_post($post_id) {
|
||||
if (isset($_POST['cp'])) {
|
||||
$info = $_POST['cp'];
|
||||
if (isset($info['attachments'])) {
|
||||
$image_meta_updates = array();
|
||||
foreach ($info['attachments'] as $id => $properties) {
|
||||
if ($backend = ComicPressBackend::generate_from_id($id)) {
|
||||
if (is_a($backend, 'ComicPressBackendFilesystem')) {
|
||||
$image_meta_updates[$backend->root] = array();
|
||||
foreach (array('alt_text', 'title_text') as $field) {
|
||||
if (isset($properties[$field])) {
|
||||
$image_meta_updates[$backend->root][$field] = strip_tags($properties[$field]);
|
||||
} else {
|
||||
$image_meta_updates[$backend->root][$field] = '';
|
||||
if (is_array($info)) {
|
||||
if (isset($info['attachments'])) {
|
||||
if (is_array($info['attachments'])) {
|
||||
$image_meta_updates = array();
|
||||
foreach ($info['attachments'] as $id => $properties) {
|
||||
if (is_array($properties)) {
|
||||
if ($backend = ComicPressBackend::generate_from_id($id)) {
|
||||
if (is_a($backend, 'ComicPressBackendFilesystem')) {
|
||||
$image_meta_updates[$backend->root] = array();
|
||||
foreach (array('alt_text', 'title_text') as $field) {
|
||||
if (isset($properties[$field])) {
|
||||
$image_meta_updates[$backend->root][$field] = strip_tags($properties[$field]);
|
||||
} else {
|
||||
$image_meta_updates[$backend->root][$field] = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
update_post_meta($post_id, 'backend_filesystem_image_meta', $image_meta_updates);
|
||||
}
|
||||
}
|
||||
update_post_meta($post_id, 'backend_filesystem_image_meta', $image_meta_updates);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
94
test/backends/ComicPressBackendFilesystemAdminTest.php
Normal file
94
test/backends/ComicPressBackendFilesystemAdminTest.php
Normal 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));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user