From c5500420e9d3200a3473b83ea8680408d7105f73 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Wed, 20 Jan 2010 06:14:28 -0500 Subject: [PATCH 1/8] add upload-path media option --- classes/ComicPressMediaHandling.inc | 3 +++ test/ComicPressMediaHandlingTest.php | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/classes/ComicPressMediaHandling.inc b/classes/ComicPressMediaHandling.inc index 9f24ab1..658ad83 100644 --- a/classes/ComicPressMediaHandling.inc +++ b/classes/ComicPressMediaHandling.inc @@ -96,6 +96,9 @@ class ComicPressMediaHandling { case 'type-folder': $value = $this->type_folder; break; + case 'upload-path': + $value = get_option('upload_path'); + break; default: if (preg_match('#^date-(.*)$#', $matches[1], $date_matches) > 0) { if (isset($this->post_to_use)) { diff --git a/test/ComicPressMediaHandlingTest.php b/test/ComicPressMediaHandlingTest.php index 899d550..5d56470 100644 --- a/test/ComicPressMediaHandlingTest.php +++ b/test/ComicPressMediaHandlingTest.php @@ -95,7 +95,8 @@ 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%*.*', vfsStream::url('root') . '/comic/2009-01-01.*\..*'), + array('%wordpress%/%upload-path%/%type-folder%/%date-Y-m-d%*.*', vfsStream::url('root') . '/1/files/comic/2009-01-01.*\..*') ); } @@ -106,6 +107,8 @@ class ComicPressMediaHandlingTest extends PHPUnit_Framework_TestCase { $cpmh = $this->getMock('ComicPressMediaHandling', array('_abspath')); $cpmh->expects($this->any())->method('_abspath')->will($this->returnValue(vfsStream::url('root'))); + update_option('upload_path', '1/files'); + $this->assertEquals($expected_result, $cpmh->_expand_filter($filter, 'comic', (object)array('ID' => 1, 'post_date' => '2009-01-01 15:00:00'))); } From e8800de4fdf09f65cab13f06a7b5b0c440a3156a Mon Sep 17 00:00:00 2001 From: John Bintz Date: Wed, 20 Jan 2010 06:16:59 -0500 Subject: [PATCH 2/8] fix related posts test --- test/ComicPressRelatedPostsTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/ComicPressRelatedPostsTest.php b/test/ComicPressRelatedPostsTest.php index 9291b85..e739117 100644 --- a/test/ComicPressRelatedPostsTest.php +++ b/test/ComicPressRelatedPostsTest.php @@ -11,7 +11,6 @@ class ComicPressRelatedPostsTest extends PHPUnit_Framework_TestCase { } function testBuildPostTable() { - $this->markTestIncomplete(); $posts = array( (object)array('ID' => 1, 'post_date' => '2009-01-01', 'post_title' => 'Post 1', 'guid' => 'post-1'), (object)array('ID' => 2, 'post_date' => '2009-01-02', 'post_title' => 'Post 2', 'guid' => 'post-2'), @@ -32,7 +31,7 @@ class ComicPressRelatedPostsTest extends PHPUnit_Framework_TestCase { wp_set_post_categories($id, $cats); } - $output = ''; + $output = ''; $this->rp->related_categories = array(2); From a335a334682838ab2f6ec68705d91abe7c7bf993 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Wed, 20 Jan 2010 06:22:51 -0500 Subject: [PATCH 3/8] capitalization change --- options/configoptions.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/options/configoptions.php b/options/configoptions.php index dc24c9d..381cdb3 100644 --- a/options/configoptions.php +++ b/options/configoptions.php @@ -135,7 +135,7 @@ - + @@ -147,14 +147,14 @@ - + - + From 84e2381f02c074b075f9ee79754a7129f03175d7 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Wed, 20 Jan 2010 06:31:46 -0500 Subject: [PATCH 4/8] capitalization change --- options/configoptions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/options/configoptions.php b/options/configoptions.php index 381cdb3..a14486d 100644 --- a/options/configoptions.php +++ b/options/configoptions.php @@ -112,7 +112,7 @@ - + From ee7a1cdf1c5c9d201e31397fe27ec13bf4e7a0b7 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Wed, 20 Jan 2010 07:10:42 -0500 Subject: [PATCH 5/8] start work on ui for editing filters --- functions.php | 3 +- options/configoptions.php | 70 ++++++++++++++++++++ options/options.css | 17 +++++ test/selenium/TestComicFilenameFilters.html | 72 +++++++++++++++++++++ 4 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 test/selenium/TestComicFilenameFilters.html diff --git a/functions.php b/functions.php index 32fbae7..74e7fd0 100644 --- a/functions.php +++ b/functions.php @@ -206,7 +206,8 @@ function comicpress_load_options() { 'enable_comment_count_in_rss' => false, 'enable_scroll_to_top' => false, - 'enable_page_load_info' => false + 'enable_page_load_info' => false, + 'comic_filename_filters' => array() ) as $field => $value) { $comicpress_options[$field] = $value; diff --git a/options/configoptions.php b/options/configoptions.php index a14486d..4ea27c0 100644 --- a/options/configoptions.php +++ b/options/configoptions.php @@ -160,6 +160,76 @@ + default_filter; + } + ?> + + + + +

+ For advanced users. Specify the filters used to find the filename. +

+
+
+ + +

+ Available parameters: +

+
    +
  • %wordpress%: The WordPress root folder
  • +
  • %type-folder%: The folder for the requested filetype (comic, rss, archive, or mini)
  • +
  • %date-(format)%: The formatting to use for the requested date as per the date() function (ex: %date-Ymd% is )
  • +
  • %upload-path%: The value of the upload_path option, which is the destination upload directory for WPMU installs.
  • +
+ + + diff --git a/options/options.css b/options/options.css index f7621fa..11c8287 100644 --- a/options/options.css +++ b/options/options.css @@ -221,3 +221,20 @@ div.show .cpadmin-footer img{ min-width: 80px; text-align: center; } + +/** Comic Filters **/ + +#comicpress-comic-filename-filters-holder div { + border: solid #ddd 1px; + padding: 3px; + overflow: hidden; +} + +#comicpress-comic-filename-filters-holder label { + float: left; + display: inline; +} + +#comicpress-comic-filename-filters-holder input { + margin: 0 10px; +} diff --git a/test/selenium/TestComicFilenameFilters.html b/test/selenium/TestComicFilenameFilters.html new file mode 100644 index 0000000..9e21a46 --- /dev/null +++ b/test/selenium/TestComicFilenameFilters.html @@ -0,0 +1,72 @@ + + + + + + +TestComicFilenameFilters + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TestComicFilenameFilters
clickAndWaitlink=ComicPress Options
click//div[@id='comicpress-tab-config']/span
storeXpathCount//div[@id="comicpress-comic-filename-filters-holder"]/divfilter_count
echo${filter_count}
clickadd-new-filter
storeXpathCount//div[@id="comicpress-comic-filename-filters-holder"]/divnew_filter_count
assertEval(${new_filter_count}) == (${filter_count} + 1)true
click//div[@id='comicpress-comic-filename-filters-holder']/div[2]/a
assertConfirmationAre you sure?
storeXpathCount//div[@id="comicpress-comic-filename-filters-holder"]/divnew_filter_count
assertEval(${new_filter_count}) == (${filter_count})true
+ + From 001f51fe6519ac76acc2d13c05bfbdc2a0a1776a Mon Sep 17 00:00:00 2001 From: John Bintz Date: Wed, 20 Jan 2010 07:35:17 -0500 Subject: [PATCH 6/8] add new filter filtering option and associated test --- comicpress-options.php | 17 ++++++++++++ test/ComicPressOptionsAdminTest.php | 43 +++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 test/ComicPressOptionsAdminTest.php diff --git a/comicpress-options.php b/comicpress-options.php index 1fe86d8..3f8247e 100644 --- a/comicpress-options.php +++ b/comicpress-options.php @@ -19,6 +19,23 @@ function comicpress_admin_print_styles() { wp_enqueue_style('comicpress-options', get_template_directory_uri() . '/options/options.css'); } +function comicpress_save_options_comic_filename_filters($incoming) { + $filters = array(); + + foreach (array_values($incoming) as $filter) { + $filters[wp_filter_nohtml_kses($filter['name'])] = wp_filter_nohtml_kses($filter['filter']); + } + + if (!empty($filters)) { + if (!isset($filters['default'])) { + $cpmh = new ComicPressMediaHandling(); + $filters['default'] = $cpmh->default_filter; + } + } + + return $filters; +} + function comicpress_admin_page_head() { ?> array( + 'name' => 'test', 'filter' => 'myfilter' + )), + array( + 'default' => $cpmh->default_filter, + 'test' => 'myfilter' + ) + ), + array( + array(1 => array( + 'name' => 'default', 'filter' => 'test' + )), + array( + 'default' => 'test' + ) + ) + ); + } + + /** + * @dataProvider providerTestSaveComicFilenameFilters + */ + function testSaveComicFilenameFilters($incoming, $expected) { + $this->assertEquals($expected, comicpress_save_options_comic_filename_filters($incoming)); + } +} From 85c46dbc3a585b2cfef2a45f554544fe127d3815 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Wed, 20 Jan 2010 07:43:30 -0500 Subject: [PATCH 7/8] finish filename filters admin and associated selenium test --- comicpress-options.php | 7 ++ options/configoptions.php | 4 +- test/selenium/TestComicFilenameFilters.html | 82 +++++++++++++++++++++ 3 files changed, 90 insertions(+), 3 deletions(-) diff --git a/comicpress-options.php b/comicpress-options.php index 3f8247e..8a207ef 100644 --- a/comicpress-options.php +++ b/comicpress-options.php @@ -207,6 +207,13 @@ function comicpress_admin() { ) as $key) { $comicpress_options['comicpress_config'][$key] = wp_filter_nohtml_kses($_REQUEST[$key]); } + + if (isset($_REQUEST['comic_filename_filters'])) { + $comicpress_options['comic_filename_filters'] = comicpress_save_options_comic_filename_filters($_REQUEST['comic_filename_filters']); + } else { + $comicpress_options['comic_filename_filters'] = array(); + } + $tab = 'config'; update_option('comicpress_options',$comicpress_options); } diff --git a/options/configoptions.php b/options/configoptions.php index 4ea27c0..8a1ab90 100644 --- a/options/configoptions.php +++ b/options/configoptions.php @@ -159,7 +159,6 @@ - default_filter; } ?> - @@ -194,7 +192,7 @@ \ \ Remove\ '); diff --git a/test/selenium/TestComicFilenameFilters.html b/test/selenium/TestComicFilenameFilters.html index 9e21a46..74b3686 100644 --- a/test/selenium/TestComicFilenameFilters.html +++ b/test/selenium/TestComicFilenameFilters.html @@ -21,6 +21,43 @@ //div[@id='comicpress-tab-config']/span + + + storeXpathCount + //div[@id="comicpress-comic-filename-filters-holder"]/div + filter_count + + + while + ${filter_count} > 0 + + + + click + //div[@id='comicpress-comic-filename-filters-holder']/div[1]/a + + + + assertConfirmation + Are you sure? + + + + storeXpathCount + //div[@id="comicpress-comic-filename-filters-holder"]/div + filter_count + + + endWhile + + + + + clickAndWait + comicpress_save_config + + + storeXpathCount //div[@id="comicpress-comic-filename-filters-holder"]/div @@ -46,6 +83,26 @@ (${new_filter_count}) == (${filter_count} + 1) true + + clickAndWait + comicpress_save_config + + + + assertTextPresent + ComicPress Settings SAVED! + + + + storeXpathCount + //div[@id="comicpress-comic-filename-filters-holder"]/div + new_filter_count + + + assertEval + (${new_filter_count}) == (${filter_count} + 1) + true + click //div[@id='comicpress-comic-filename-filters-holder']/div[2]/a @@ -66,6 +123,31 @@ (${new_filter_count}) == (${filter_count}) true + + clickAndWait + comicpress_save_config + + + + assertTextPresent + ComicPress Settings SAVED! + + + + storeXpathCount + //div[@id="comicpress-comic-filename-filters-holder"]/div + new_filter_count + + + assertEval + (${new_filter_count}) == (${filter_count}) + true + + + assertTextPresent + ComicPress Settings SAVED! + + From 9a3dba75dcc24bb2e5f612cfee3cd805f79f4e74 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Wed, 20 Jan 2010 07:46:40 -0500 Subject: [PATCH 8/8] add support for filters from options --- classes/ComicPressMediaHandling.inc | 4 ++++ test/ComicPressMediaHandlingTest.php | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/classes/ComicPressMediaHandling.inc b/classes/ComicPressMediaHandling.inc index 658ad83..76c1307 100644 --- a/classes/ComicPressMediaHandling.inc +++ b/classes/ComicPressMediaHandling.inc @@ -30,6 +30,10 @@ class ComicPressMediaHandling { if (isset($comic_filename_filters[$filter_to_use])) { return $this->_convert_to_percent_filter($comic_filename_filters[$filter_to_use]); } + $options = get_option('comicpress_options'); + if (isset($options['comic_filename_filters'][$filter_to_use])) { + return $this->_convert_to_percent_filter($options['comic_filename_filters'][$filter_to_use]); + } } } diff --git a/test/ComicPressMediaHandlingTest.php b/test/ComicPressMediaHandlingTest.php index 5d56470..d79578a 100644 --- a/test/ComicPressMediaHandlingTest.php +++ b/test/ComicPressMediaHandlingTest.php @@ -41,7 +41,8 @@ class ComicPressMediaHandlingTest extends PHPUnit_Framework_TestCase { array(null, $default), array('fail', $default), array(array(), $default), - array('test', 'test') + array('test', 'test'), + array('test-from-option', 'test-from-option'), ); } @@ -53,6 +54,12 @@ class ComicPressMediaHandlingTest extends PHPUnit_Framework_TestCase { $comic_filename_filters['test'] = 'test'; + update_option('comicpress_options', array( + 'comic_filename_filters' => array( + 'test-from-option' => 'test-from-option' + ) + )); + $default = str_replace('{date}', $this->cpmh->default_filename_filter, $this->cpmh->default_filter); $cpmh = $this->getMock('ComicPressMediaHandling', array('_convert_to_percent_filter'));