Merge commit '94487ac423f0f53eea92a9259f31beba366912b4'

This commit is contained in:
John Bintz 2009-12-03 19:14:00 -05:00
commit 7a25cca894
2 changed files with 123 additions and 2 deletions

View File

@ -81,9 +81,11 @@ class ComicPressMediaHandling {
break;
default:
if (preg_match('#^date-(.*)$#', $matches[1], $date_matches) > 0) {
if (isset($this->post_to_use)) {
$value = date($date_matches[1], strtotime($this->post_to_use->post_date));
break;
}
}
$value = $matches[0];
break;
}
@ -111,6 +113,60 @@ class ComicPressMediaHandling {
return $results;
}
function _check_post_meta_data($post_to_use, $type) {
if ($result = get_post_meta($post_to_use->ID, "backend_url_${type}", true)) {
if (is_string($result)) {
return $result;
}
}
if ($result = get_post_meta($post_to_use->ID, "backend_url_images", true)) {
$types = false;
if (is_string($result)) {
parse_str($result, $types);
}
if (is_array($result)) {
$types = $result;
}
if (is_array($types)) {
if (isset($types[$type])) {
return $types[$type];
}
}
}
if ($result = get_post_meta($post_to_use->ID, "backend_url", true)) {
if (is_string($result)) {
return $result;
}
}
return false;
}
function _ensure_valid_uri($uri, $type) {
if (!empty($uri)) {
if (substr($uri, 0, 1) == '/') {
return $uri;
} else {
if (preg_match('#^[a-z]+://#', $uri) > 0) {
return $uri;
} else {
$bundle = $this->_bundle_global_variables();
if (isset($bundle[$type])) {
$this->type_folder = $bundle[$type];
} else {
$this->type_folder = '';
}
$uri = preg_replace_callback('#%([a-z0-9-]+)%#i', array(&$this, '_expand_filter_callback'), $uri);
return trailingslashit(get_bloginfo('url')) . $uri;
}
}
}
return false;
}
/**
* Get the comic path.
* @param string $type The type to retrieve.
@ -123,6 +179,12 @@ class ComicPressMediaHandling {
global $post;
$post_to_use = !is_null($override_post) ? $override_post : $post;
if ($uri = $this->_check_post_meta_data($post_to_use, $type)) {
if ($result = $this->_ensure_valid_url($uri, $type)) {
return $result;
}
}
$filter = $this->_get_filter($filter);
$globals = $this->_bundle_global_variables();

View File

@ -99,6 +99,10 @@ class ComicPressMediaHandlingTest extends PHPUnit_Framework_TestCase {
$this->assertEquals($expected_result, $cpmh->_expand_filter($filter, 'comic', (object)array('ID' => 1, 'post_date' => '2009-01-01 15:00:00')));
}
function testExpandFilterNoPostDateRequested() {
$this->assertEquals('%date-Y%', $this->cpmh->_expand_filter('%date-Y%', 'comic', null));
}
function providerTestExpandFilterWPMUCallback() {
return array(
array('', '', 'original'),
@ -176,4 +180,59 @@ class ComicPressMediaHandlingTest extends PHPUnit_Framework_TestCase {
$this->assertEquals($expected_result, _comicpress_pre_handle_comic_path_results(false, array('one/one', 'two/two', 'three/three'), 'comic', (object)array('ID' => 1)));
}
function providerTestCheckPostMetaData() {
return array(
array('comic', array(), false),
array('comic', array('backend_url_comic' => '/test'), '/test'),
array('comic', array('backend_url_comic' => array('test')), false),
array('comic', array('backend_url_images' => 'test=/test'), false),
array('comic', array('backend_url_images' => 'comic=/test'), '/test'),
array('comic', array('backend_url_images' => array('comic' => '/test')), '/test'),
array('comic', array('backend_url' => '/test'), '/test'),
array('comic', array('backend_url' => array('test')), false),
);
}
/**
* @dataProvider providerTestCheckPostMetaData
*/
function testCheckPostMetaData($type, $metadata, $expected_result) {
foreach ($metadata as $key => $value) {
update_post_meta(1, $key, $value);
}
$this->assertEquals($expected_result, $this->cpmh->_check_post_meta_data((object)array('ID' => 1), $type));
}
function providerTestEnsureValidURI() {
return array(
array('', false),
array('test', 'wordpress/test'),
array('%type-folder%/test', 'wordpress/comic-dir/test'),
array('/test', '/test'),
array('http://file', 'http://file'),
);
}
/**
* @dataProvider providerTestEnsureValidURI
*/
function testEnsureValidURI($uri, $expected_result) {
_set_bloginfo('url', 'wordpress');
$cpmh = $this->getMock('ComicPressMediaHandling', array('_bundle_global_variables'));
$cpmh->expects($this->any())->method('_bundle_global_variables')->will($this->returnValue(array('comic' => 'comic-dir')));
$this->assertEquals($expected_result, $cpmh->_ensure_valid_uri($uri, 'comic'));
}
function testEnsureValidURIInvalidType() {
_set_bloginfo('url', 'wordpress');
$cpmh = $this->getMock('ComicPressMediaHandling', array('_bundle_global_variables'));
$cpmh->expects($this->any())->method('_bundle_global_variables')->will($this->returnValue(array('comic' => 'comic-dir')));
$this->assertEquals('wordpress/', $cpmh->_ensure_valid_uri('%type-folder%', 'test'));
}
}