code coverage
This commit is contained in:
parent
81f6496efe
commit
eb840b1d69
@ -83,9 +83,6 @@ class FixtureBuilder {
|
||||
function metadata($key, $value) {
|
||||
$this->check_correct_type('post');
|
||||
|
||||
if (!isset($this->current_object['post'])) {
|
||||
$this->current_object['post'] = array();
|
||||
}
|
||||
$this->current_object['post']['metadata'][$key] = $value;
|
||||
return $this;
|
||||
}
|
||||
@ -127,6 +124,8 @@ class FixtureBuilder {
|
||||
|
||||
return get_post($post_id);
|
||||
}
|
||||
// @codeCoverageIgnoreStart
|
||||
return false;
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
}
|
||||
|
@ -101,10 +101,51 @@ class PostFixtures {
|
||||
/**
|
||||
* Render the admin page.
|
||||
*/
|
||||
// @codeCoverageIgnoreStart
|
||||
function render_admin() {
|
||||
|
||||
|
||||
include(dirname(__FILE__) . '/partials/admin.inc');
|
||||
}
|
||||
|
||||
function wpcontent_path() { return ABSPATH . '/wp-content'; }
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
function find_fixtures() {
|
||||
$this->fixtures = array();
|
||||
|
||||
$this->_find_fixtures_recurse($this->wpcontent_path());
|
||||
|
||||
return $this->fixtures;
|
||||
}
|
||||
|
||||
function _find_fixtures_recurse($dir) {
|
||||
$queue = array();
|
||||
$dh = opendir($dir);
|
||||
$is_fixture_dir = (basename($dir) === 'fixtures');
|
||||
while ($file = readdir($dh)) {
|
||||
if ($file[0] != '.') {
|
||||
$target = $dir . '/' . $file;
|
||||
if ($is_fixture_dir) {
|
||||
if (is_file($target)) {
|
||||
if (preg_match('#\.(inc|json)$#', $target) > 0) {
|
||||
$this->fixtures[] = $target;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (is_dir($target)) {
|
||||
$queue[] = $target;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($dh);
|
||||
|
||||
foreach ($queue as $dir) {
|
||||
$this->_find_fixtures_recurse($dir);
|
||||
}
|
||||
}
|
||||
|
||||
// data handling
|
||||
|
||||
/**
|
||||
|
@ -47,6 +47,8 @@ class FixtureBuilderTest extends PHPUnit_Framework_TestCase {
|
||||
array('date', array('2010-01-01')),
|
||||
array('categories', array('test,test2')),
|
||||
array('metadata', array('key', array('metadata' => 'value'))),
|
||||
array('post', array('Post title 2')),
|
||||
array('date', array('2010-01-02')),
|
||||
),
|
||||
array(
|
||||
'post' => array(
|
||||
@ -56,10 +58,15 @@ class FixtureBuilderTest extends PHPUnit_Framework_TestCase {
|
||||
'post_date' => '2010-01-01',
|
||||
'categories' => array('test', 'test2'),
|
||||
'metadata' => array('key' => array('metadata' => 'value'))
|
||||
)
|
||||
),
|
||||
array(
|
||||
'post_title' => 'Post title 2',
|
||||
'post_type' => 'post',
|
||||
'post_date' => '2010-01-02',
|
||||
),
|
||||
),
|
||||
array(true, true, true, true)
|
||||
),
|
||||
array(true, true, true, true, true, true)
|
||||
),
|
||||
);
|
||||
}
|
||||
@ -191,4 +198,10 @@ class FixtureBuilderTest extends PHPUnit_Framework_TestCase {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function testBuildEmpty() {
|
||||
$builder = new FixtureBuilder();
|
||||
|
||||
$builder->build();
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
require_once('PHPUnit/Framework.php');
|
||||
require_once('MockPress/mockpress.php');
|
||||
require_once('vfsStream/vfsStream.php');
|
||||
require_once(dirname(__FILE__) . '/../classes/PostFixtures.inc');
|
||||
|
||||
class PostFixturesTest extends PHPUnit_Framework_TestCase {
|
||||
@ -10,6 +11,9 @@ class PostFixturesTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
$this->pf = new PostFixtures();
|
||||
$_POST = array();
|
||||
|
||||
vfsStreamWrapper::register();
|
||||
vfsStreamWrapper::setRoot(new vfsStreamDirectory('root'));
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
@ -330,4 +334,27 @@ class PostFixturesTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
$this->assertTrue(!isset($_POST['pf']));
|
||||
}
|
||||
|
||||
function testRecurseDirectories() {
|
||||
mkdir(vfsStream::url('root/dir/fixtures'), 0666, true);
|
||||
|
||||
foreach (array(
|
||||
'dir/test.json',
|
||||
'dir/test.inc',
|
||||
'dir/fixtures/test',
|
||||
'dir/fixtures/test.json',
|
||||
'dir/fixtures/test.inc',
|
||||
) as $path) {
|
||||
$path = vfsStream::url("root/${path}");
|
||||
file_put_contents($path, $path);
|
||||
}
|
||||
|
||||
$pf = $this->getMock('PostFixtures', array('wpcontent_path'));
|
||||
$pf->expects($this->once())->method('wpcontent_path')->will($this->returnValue(vfsStream::url('root')));
|
||||
|
||||
$this->assertEquals(array(
|
||||
vfsStream::url('root/dir/fixtures/test.json'),
|
||||
vfsStream::url('root/dir/fixtures/test.inc'),
|
||||
), $pf->find_fixtures());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user