comicpress-core/test/backends/ComicPressBackendFilesystem...

63 lines
2.0 KiB
PHP
Raw Normal View History

2009-11-24 12:52:53 +00:00
<?php
require_once('PHPUnit/Framework.php');
require_once('MockPress/mockpress.php');
require_once('backends/ComicPressBackendFilesystem.inc');
require_once('vfsStream/vfsStream.php');
class ComicPressBackendFilesystemTest extends PHPUnit_Framework_TestCase {
function setUp() {
_reset_wp();
$this->fs = new ComicPressBackendFilesystem();
}
function providerTestProcessSearchString() {
return array(
array('/comic/*.jpg', array('/comic/*.jpg')),
array('%wordpress%/comic/*.jpg', array('/wordpress/comic/*.jpg')),
2009-11-24 23:49:32 +00:00
array('%test%/comic/*.jpg', array('/comic/*.jpg')),
2009-11-24 12:52:53 +00:00
array('%wordpress%/%type%/*.jpg', array('/wordpress/comic/*.jpg')),
array('%wordpress%/comic/%y-m-d%*.jpg', array('/wordpress/comic/2009-01-01*.jpg')),
array('%wordpress%/comic/%year%/%y-m-d%*.jpg', array('/wordpress/comic/2009/2009-01-01*.jpg')),
array(
'%wordpress%/comic/%categories%/%y-m-d%*.jpg',
array(
'/wordpress/comic/parent/child/2009-01-01*.jpg',
'/wordpress/comic/parent/2009-01-01*.jpg',
)
),
2009-11-24 23:49:32 +00:00
array(
'%wordpress%/comic/%categories%/%y-m-d%*.jpg',
array(
'/wordpress/comic//2009-01-01*.jpg',
),
2
),
2009-11-24 12:52:53 +00:00
);
}
/**
* @dataProvider providerTestProcessSearchString
*/
2009-11-24 23:49:32 +00:00
function testProcessSearchString($string, $expected_searches, $post_id_to_use = 1) {
2009-11-24 12:52:53 +00:00
$fs = $this->getMock('ComicPressBackendFilesystem', array('_replace_wordpress'));
$fs->expects($this->any())->method('_replace_wordpress')->will($this->returnValue('/wordpress'));
2009-11-24 23:49:32 +00:00
$posts = array(
1 => (object)array('ID' => 1, 'post_date' => '2009-01-01'),
2 => (object)array('ID' => 2, 'post_date' => '2009-01-01'),
);
2009-11-24 12:52:53 +00:00
add_category(1, (object)array('slug' => 'parent', 'parent' => 0));
add_category(2, (object)array('slug' => 'child', 'parent' => 1));
2009-11-24 23:49:32 +00:00
add_category(4, (object)array('slug' => 'bad', 'parent' => 3));
2009-11-24 12:52:53 +00:00
wp_set_post_categories(1, array(2));
2009-11-24 23:49:32 +00:00
wp_set_post_categories(2, array(4));
2009-11-24 12:52:53 +00:00
$fs->search_string = $string;
2009-11-24 23:49:32 +00:00
$this->assertEquals($expected_searches, $fs->process_search_string($posts[$post_id_to_use], 'comic'));
2009-11-24 12:52:53 +00:00
}
}