From 66f5083e3b110d373a9750c0a126f6b65ac9f5f9 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Thu, 3 Dec 2009 07:12:14 -0500 Subject: [PATCH 1/7] basic metadata support --- classes/ComicPressMediaHandling.inc | 60 +++++++++++++++++++++++++++- test/ComicPressMediaHandlingTest.php | 43 ++++++++++++++++++++ 2 files changed, 101 insertions(+), 2 deletions(-) diff --git a/classes/ComicPressMediaHandling.inc b/classes/ComicPressMediaHandling.inc index 887c1aa..31f7e7d 100644 --- a/classes/ComicPressMediaHandling.inc +++ b/classes/ComicPressMediaHandling.inc @@ -80,8 +80,10 @@ class ComicPressMediaHandling { break; default: if (preg_match('#^date-(.*)$#', $matches[1], $date_matches) > 0) { - $value = date($date_matches[1], strtotime($this->post_to_use->post_date)); - break; + if (isset($this->post_to_use)) { + $value = date($date_matches[1], strtotime($this->post_to_use->post_date)); + break; + } } $value = $matches[0]; break; @@ -110,6 +112,54 @@ 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)) { + if (is_string($result)) { + parse_str($result, $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. @@ -122,6 +172,12 @@ class ComicPressMediaHandling { global $post; $post_to_use = !is_null($override_post) ? $override_post : $post; + if ($uri = $this->_check_post_meta($post_to_use, $type)) { + if ($result = $this->_ensure_valid_url($uri, $type)) { + return $result; + } + } + $filter = $this->_get_filter($filter); $globals = $this->_bundle_global_variables(); diff --git a/test/ComicPressMediaHandlingTest.php b/test/ComicPressMediaHandlingTest.php index 03ab451..d36181e 100644 --- a/test/ComicPressMediaHandlingTest.php +++ b/test/ComicPressMediaHandlingTest.php @@ -175,4 +175,47 @@ 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_images' => 'test=/test'), false), + array('comic', array('backend_url_images' => 'comic=/test'), '/test'), + array('comic', array('backend_url' => '/test'), '/test'), + ); + } + + /** + * @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')); + } } From ab3af9244a49d98d5673d458c83e2e0f94da06ac Mon Sep 17 00:00:00 2001 From: John Bintz Date: Thu, 3 Dec 2009 18:40:21 -0500 Subject: [PATCH 2/7] translate backslashes into forward slashes, fixes dirname() issue on windows --- classes/ComicPressMediaHandling.inc | 1 + test/ComicPressMediaHandlingTest.php | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/classes/ComicPressMediaHandling.inc b/classes/ComicPressMediaHandling.inc index 31f7e7d..e38edeb 100644 --- a/classes/ComicPressMediaHandling.inc +++ b/classes/ComicPressMediaHandling.inc @@ -60,6 +60,7 @@ class ComicPressMediaHandling { function _resolve_regex_path($input) { $input = str_replace('\.', '.', $input); + $input = str_replace('\\', '/', $input); return $input; } diff --git a/test/ComicPressMediaHandlingTest.php b/test/ComicPressMediaHandlingTest.php index d36181e..c519fc4 100644 --- a/test/ComicPressMediaHandlingTest.php +++ b/test/ComicPressMediaHandlingTest.php @@ -144,7 +144,8 @@ class ComicPressMediaHandlingTest extends PHPUnit_Framework_TestCase { function providerTestResolveRegexPath() { return array( array('test', 'test'), - array('te\.st', 'te.st') + array('te\.st', 'te.st'), + array('te\st', 'te/st'), ); } From cae60abc4fb68838655f02905a33f198aee89485 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Thu, 3 Dec 2009 18:43:07 -0500 Subject: [PATCH 3/7] support for arrays in backend_url_image in prep for meta box --- classes/ComicPressMediaHandling.inc | 6 ++++++ test/ComicPressMediaHandlingTest.php | 1 + 2 files changed, 7 insertions(+) diff --git a/classes/ComicPressMediaHandling.inc b/classes/ComicPressMediaHandling.inc index e38edeb..1f4b3c8 100644 --- a/classes/ComicPressMediaHandling.inc +++ b/classes/ComicPressMediaHandling.inc @@ -121,8 +121,14 @@ class ComicPressMediaHandling { } 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]; } diff --git a/test/ComicPressMediaHandlingTest.php b/test/ComicPressMediaHandlingTest.php index c519fc4..b716f8b 100644 --- a/test/ComicPressMediaHandlingTest.php +++ b/test/ComicPressMediaHandlingTest.php @@ -183,6 +183,7 @@ class ComicPressMediaHandlingTest extends PHPUnit_Framework_TestCase { array('comic', array('backend_url_comic' => '/test'), '/test'), 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'), ); } From 509c9a09e4664177aafd3ef6bbc8b0777655001c Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 1 Dec 2009 07:06:35 -0500 Subject: [PATCH 4/7] remove core classes from coverage --- phpunit.xml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/phpunit.xml b/phpunit.xml index b448d08..b9d6b4a 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -2,4 +2,11 @@ + + + classes/ComicPressDBInterface.inc + classes/ComicPressNavigation.inc + classes/ComicPressStoryline.inc + + From 8ba8561ac5b31a2cdd2bbb3ef0f162382c9ace3a Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sat, 28 Nov 2009 11:29:05 -0500 Subject: [PATCH 5/7] makefile --- Makefile | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8ee6751 --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +.PHONY : test-coverage + +test-coverage : + phpunit --syntax-check --coverage-html coverage test From f311986e5e2be1b6e78fd78a4fd0ccf479f09d2d Mon Sep 17 00:00:00 2001 From: John Bintz Date: Thu, 3 Dec 2009 18:52:26 -0500 Subject: [PATCH 6/7] code coverage --- test/ComicPressMediaHandlingTest.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/ComicPressMediaHandlingTest.php b/test/ComicPressMediaHandlingTest.php index b716f8b..8e8f3fe 100644 --- a/test/ComicPressMediaHandlingTest.php +++ b/test/ComicPressMediaHandlingTest.php @@ -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'), @@ -181,10 +185,12 @@ class ComicPressMediaHandlingTest extends PHPUnit_Framework_TestCase { 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), ); } @@ -220,4 +226,13 @@ class ComicPressMediaHandlingTest extends PHPUnit_Framework_TestCase { $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')); + } } From 94487ac423f0f53eea92a9259f31beba366912b4 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Thu, 3 Dec 2009 19:12:34 -0500 Subject: [PATCH 7/7] fix integration bug --- classes/ComicPressMediaHandling.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/ComicPressMediaHandling.inc b/classes/ComicPressMediaHandling.inc index 1f4b3c8..28dbe4c 100644 --- a/classes/ComicPressMediaHandling.inc +++ b/classes/ComicPressMediaHandling.inc @@ -179,7 +179,7 @@ class ComicPressMediaHandling { global $post; $post_to_use = !is_null($override_post) ? $override_post : $post; - if ($uri = $this->_check_post_meta($post_to_use, $type)) { + if ($uri = $this->_check_post_meta_data($post_to_use, $type)) { if ($result = $this->_ensure_valid_url($uri, $type)) { return $result; }