From 3b0b3a1471151cf6d3ff6c17009155a225c7d37a Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 1 Dec 2009 22:13:21 -0500 Subject: [PATCH] wpmu-specific stuff --- classes/ComicPressMediaHandling.inc | 14 ++++++--- test/ComicPressMediaHandlingTest.php | 46 +++++++++++++++++++++++----- 2 files changed, 48 insertions(+), 12 deletions(-) diff --git a/classes/ComicPressMediaHandling.inc b/classes/ComicPressMediaHandling.inc index 926d827..3665d09 100644 --- a/classes/ComicPressMediaHandling.inc +++ b/classes/ComicPressMediaHandling.inc @@ -58,19 +58,17 @@ class ComicPressMediaHandling { return $result; } + // @codeCoverageIgnoreStart function _abspath() { return ABSPATH; } + // @codeCoverageIgnoreEnd function _expand_filter_callback($matches) { $value = ''; switch (strtolower($matches[1])) { case 'wordpress': - if ($path = get_option('upload_path')) { - $value = $path; - } else { - $value = $this->_abspath(); - } + $value = $this->_abspath(); break; case 'type-folder': $value = $this->type_folder; @@ -115,6 +113,12 @@ class ComicPressMediaHandling { if (isset($globals[$type])) { $filter = $this->_expand_filter($filter, $globals[$type], $post_to_use); + + if (is_array($results = $this->_read_directory($filter))) { + if (($pre_handle = apply_filters('comicpress_pre_handle_comic_path_results', false, $results, $type, $post_to_use)) !== false) { + return $pre_handle; + } + } } } } diff --git a/test/ComicPressMediaHandlingTest.php b/test/ComicPressMediaHandlingTest.php index 2e30ae4..e03c591 100644 --- a/test/ComicPressMediaHandlingTest.php +++ b/test/ComicPressMediaHandlingTest.php @@ -4,6 +4,7 @@ require_once('PHPUnit/Framework.php'); require_once('MockPress/mockpress.php'); require_once('vfsStream/vfsStream.php'); require_once(dirname(__FILE__) . '/../classes/ComicPressMediaHandling.inc'); +require_once(dirname(__FILE__) . '/../functions/wpmu.php'); class ComicPressMediaHandlingTest extends PHPUnit_Framework_TestCase { function setUp() { @@ -84,25 +85,35 @@ class ComicPressMediaHandlingTest extends PHPUnit_Framework_TestCase { array('%test test%', '%test test%'), array('%wordpress%/%type-folder%', vfsStream::url('root') . '/comic'), array('%date-Y%', '2009'), - array('%wordpress%/%type-folder%/%date-Y-m-d%*.*', vfsStream::url('root') . '/comic/2009-01-01.*\..*'), - array('%wordpress%/%type-folder%/%date-Y-m-d%*.*', '/wpmupath/comic/2009-01-01.*\..*', '/wpmupath'), + array('%wordpress%/%type-folder%/%date-Y-m-d%*.*', vfsStream::url('root') . '/comic/2009-01-01.*\..*') ); } /** * @dataProvider providerTestExpandFilter */ - function testExpandFilter($filter, $expected_result, $use_option_path = false) { + function testExpandFilter($filter, $expected_result) { $cpmh = $this->getMock('ComicPressMediaHandling', array('_abspath')); $cpmh->expects($this->any())->method('_abspath')->will($this->returnValue(vfsStream::url('root'))); - if ($use_option_path !== false) { - update_option('upload_path', $use_option_path); - } - $this->assertEquals($expected_result, $cpmh->_expand_filter($filter, 'comic', (object)array('ID' => 1, 'post_date' => '2009-01-01 15:00:00'))); } + function providerTestExpandFilterWPMUCallback() { + return array( + array('', 'original'), + array('new', 'new') + ); + } + + /** + * @dataProvider providerTestExpandFilterWPMUCallback + */ + function testExpandFilterWPMUCallback($option_value, $expected_result) { + update_option('upload_path', $option_value); + $this->assertEquals($expected_result, _comicpress_expand_filter_callback('original', array())); + } + function providerTestReadDirectory() { return array( array(vfsStream::url('root2/.*'), false), @@ -125,4 +136,25 @@ class ComicPressMediaHandlingTest extends PHPUnit_Framework_TestCase { } $this->assertEquals($expected_results, $this->cpmh->_read_directory($pattern)); } + + function providerTestPreHandleComicPathResults() { + return array( + array('', '', false), + array('1', '', 'comic/one'), + array('1', 'comic', 'files/one'), + ); + } + + /** + * @dataProvider providerTestPreHandleComicPathResults + */ + function testPreHandleComicPathResults($_wpmu_version, $upload_path, $expected_result) { + global $wpmu_version, $comic_folder; + $wpmu_version = $_wpmu_version; + $comic_folder = 'comic'; + + update_option('upload_path', $upload_path); + + $this->assertEquals($expected_result, _comicpress_pre_handle_comic_path_results(false, array('one/one', 'two/two', 'three/three'), 'comic', (object)array('ID' => 1))); + } }