2009-07-04 16:08:02 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once('PHPUnit/Framework.php');
|
2009-10-31 20:04:29 +00:00
|
|
|
require_once('MockPress/mockpress.php');
|
2009-11-07 17:18:53 +00:00
|
|
|
require_once('ComicPressAdmin.inc');
|
2009-07-04 16:08:02 +00:00
|
|
|
|
2009-11-06 02:15:12 +00:00
|
|
|
class ComicPressAdminTest extends PHPUnit_Framework_TestCase {
|
2009-07-04 16:08:02 +00:00
|
|
|
function setUp() {
|
|
|
|
_reset_wp();
|
2009-07-06 03:09:30 +00:00
|
|
|
$_POST = array();
|
2009-11-06 02:15:12 +00:00
|
|
|
$this->admin = new ComicPressAdmin();
|
2009-07-04 16:08:02 +00:00
|
|
|
}
|
2009-07-05 19:46:32 +00:00
|
|
|
|
|
|
|
function testCreateDimensionSelector() {
|
2009-11-06 02:15:12 +00:00
|
|
|
$source = $this->admin->create_dimension_selector("test", "760x340");
|
2009-11-08 03:47:28 +00:00
|
|
|
|
2009-07-05 19:46:32 +00:00
|
|
|
$this->assertTrue(($xml = _to_xml($source, true)) !== false);
|
2009-11-08 03:47:28 +00:00
|
|
|
|
2009-07-05 19:46:32 +00:00
|
|
|
foreach (array(
|
|
|
|
'//input[@name="test[width]" and @value="760"]' => true,
|
|
|
|
'//input[@name="test[height]" and @value="340"]' => true,
|
|
|
|
) as $xpath => $value) {
|
2009-11-08 03:47:28 +00:00
|
|
|
$this->assertTrue(_xpath_test($xml, $xpath, $value), $xpath);
|
|
|
|
}
|
2009-07-05 19:46:32 +00:00
|
|
|
}
|
2009-11-08 03:47:28 +00:00
|
|
|
|
2009-07-06 03:09:30 +00:00
|
|
|
function providerTestHandleUpdate() {
|
|
|
|
return array(
|
2009-07-07 02:19:18 +00:00
|
|
|
array(
|
|
|
|
array('comic_dimensions' => '150x150'),
|
|
|
|
array('cp' => array(
|
|
|
|
'comic_dimensions' => 'test'
|
|
|
|
)),
|
|
|
|
array('comic_dimensions' => '150x150')
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
array('comic_dimensions' => '150x150'),
|
|
|
|
array('cp' => array(
|
|
|
|
'comic_dimensions' => array(
|
|
|
|
'width' => '150',
|
|
|
|
'height' => ''
|
|
|
|
)
|
|
|
|
)),
|
|
|
|
array('comic_dimensions' => '150x')
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
array('comic_dimensions' => '150x150'),
|
|
|
|
array('cp' => array(
|
|
|
|
'comic_dimensions' => array(
|
|
|
|
'width' => '150.1',
|
|
|
|
'height' => ''
|
|
|
|
)
|
|
|
|
)),
|
|
|
|
array('comic_dimensions' => '150x150')
|
|
|
|
),
|
2009-07-06 03:09:30 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerTestHandleUpdate
|
|
|
|
*/
|
|
|
|
function testHandleUpdate($original, $change, $new) {
|
2009-11-06 02:15:12 +00:00
|
|
|
$this->admin->comicpress = $this->getMock('ComicPress', array('save', 'init'));
|
|
|
|
$this->admin->comicpress->comicpress_options = array(
|
2009-07-08 23:51:02 +00:00
|
|
|
'comic_dimensions' => '760x',
|
|
|
|
'rss_dimensions' => '350x',
|
|
|
|
'archive_dimensions' => '125x'
|
|
|
|
);
|
2009-11-06 02:15:12 +00:00
|
|
|
$this->admin->comicpress->comicpress_options = array_merge($this->admin->comicpress->comicpress_options, $original);
|
2009-11-08 03:47:28 +00:00
|
|
|
|
2009-07-06 03:09:30 +00:00
|
|
|
add_category(2, (object)array('name' => 'test'));
|
2009-11-08 03:47:28 +00:00
|
|
|
|
2009-07-06 03:09:30 +00:00
|
|
|
$_POST = $change;
|
|
|
|
|
2009-11-07 15:50:21 +00:00
|
|
|
if (isset($_POST['cp'])) {
|
|
|
|
$this->admin->handle_update_comicpress_options($_POST['cp']);
|
|
|
|
}
|
2009-11-08 03:47:28 +00:00
|
|
|
|
2009-07-06 03:09:30 +00:00
|
|
|
foreach ($new as $key => $value) {
|
2009-11-06 02:15:12 +00:00
|
|
|
$this->assertEquals($value, $this->admin->comicpress->comicpress_options[$key]);
|
2009-07-06 03:09:30 +00:00
|
|
|
}
|
|
|
|
}
|
2009-11-08 03:47:28 +00:00
|
|
|
|
2009-07-21 18:00:23 +00:00
|
|
|
function providerTestUpdateAttachments() {
|
|
|
|
return array(
|
|
|
|
array(
|
|
|
|
array(
|
|
|
|
'post_meta' => array(),
|
|
|
|
),
|
|
|
|
array(
|
2009-11-11 03:09:53 +00:00
|
|
|
'comicpress_management' => "yes"
|
2009-07-21 18:00:23 +00:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'post_meta' => array(
|
2009-11-11 03:09:53 +00:00
|
|
|
'comicpress_management' => true
|
2009-07-21 18:00:23 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
array(
|
|
|
|
'post' => array(
|
|
|
|
'post_parent' => 0
|
|
|
|
),
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'post_parent' => "2"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'post' => array(
|
|
|
|
'post_parent' => 0
|
|
|
|
),
|
|
|
|
),
|
2009-11-08 03:47:28 +00:00
|
|
|
),
|
2009-07-21 18:00:23 +00:00
|
|
|
array(
|
|
|
|
array(
|
|
|
|
'post' => array(
|
|
|
|
'post_parent' => 0
|
|
|
|
),
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'post_parent' => "2",
|
2009-11-11 03:09:53 +00:00
|
|
|
'comicpress_management' => "yes"
|
2009-07-21 18:00:23 +00:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'post' => array(
|
2009-11-11 03:09:53 +00:00
|
|
|
'post_parent' => 2,
|
2009-07-21 18:00:23 +00:00
|
|
|
),
|
2009-11-11 03:09:53 +00:00
|
|
|
'post_meta' => array(
|
|
|
|
'comicpress_management' => true
|
|
|
|
)
|
2009-07-21 18:00:23 +00:00
|
|
|
),
|
|
|
|
)
|
2009-11-08 03:47:28 +00:00
|
|
|
);
|
2009-07-21 18:00:23 +00:00
|
|
|
}
|
2009-11-08 03:47:28 +00:00
|
|
|
|
2009-07-21 18:00:23 +00:00
|
|
|
/**
|
|
|
|
* @dataProvider providerTestUpdateAttachments
|
|
|
|
*/
|
|
|
|
function testUpdateAttachments($original_settings, $changes, $expected_settings) {
|
|
|
|
foreach ($original_settings as $settings_type => $settings) {
|
|
|
|
switch ($settings_type) {
|
|
|
|
case "post_meta":
|
|
|
|
foreach ($settings as $key => $value) {
|
|
|
|
update_post_meta(1, $key, $value);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "post":
|
|
|
|
wp_insert_post((object)array_merge(array(
|
|
|
|
'ID' => 1
|
|
|
|
), $settings));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-11-08 03:47:28 +00:00
|
|
|
|
2009-07-21 18:00:23 +00:00
|
|
|
$_POST = array(
|
|
|
|
'attachments' => array('1' => $changes)
|
|
|
|
);
|
2009-11-08 03:47:28 +00:00
|
|
|
|
2009-11-06 02:15:12 +00:00
|
|
|
$this->admin->handle_update_attachments();
|
2009-11-08 03:47:28 +00:00
|
|
|
|
2009-07-21 18:00:23 +00:00
|
|
|
foreach ($expected_settings as $settings_type => $settings) {
|
|
|
|
switch ($settings_type) {
|
|
|
|
case "post_meta":
|
|
|
|
foreach ($settings as $key => $value) {
|
|
|
|
$this->assertEquals($value, get_post_meta(1, $key, true));
|
|
|
|
}
|
2009-11-08 03:47:28 +00:00
|
|
|
break;
|
2009-07-21 18:00:23 +00:00
|
|
|
case "post":
|
|
|
|
$post = get_post(1);
|
|
|
|
foreach ($settings as $key => $value) {
|
|
|
|
$this->assertEquals($value, $post->{$key});
|
|
|
|
}
|
|
|
|
}
|
2009-07-23 00:55:32 +00:00
|
|
|
}
|
|
|
|
}
|
2009-11-08 03:47:28 +00:00
|
|
|
|
2009-08-06 02:29:54 +00:00
|
|
|
function providerTestHandleUpdateOverridePartial() {
|
|
|
|
return array(
|
|
|
|
array(
|
|
|
|
'hello',
|
|
|
|
'Update partial'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'meow',
|
|
|
|
'Delete override partial'
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2009-07-04 16:08:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|