get layout choices

This commit is contained in:
John Bintz 2009-07-22 17:55:32 -07:00
parent 472581132c
commit 10fed1f385
2 changed files with 61 additions and 1 deletions

View File

@ -442,6 +442,20 @@ class ComicPressAddonCore extends ComicPressAddon {
$this->comicpress->init(); $this->comicpress->init();
} }
} }
function _glob($pattern) { return glob($pattern); }
function _file_get_contents($file) { return file_get_contents($file); }
function get_layout_choices() {
$layouts = array();
foreach ($this->_glob(get_template_directory() . '/layouts/*') as $file) {
$content = $this->_file_get_contents($file);
if (preg_match('#/\*.*Layout Name: ([^\n]+).*\*/#s', $content, $matches) > 0) {
$layouts[pathinfo($file, PATHINFO_BASENAME)] = $matches[1];
}
}
return $layouts;
}
} }
?> ?>

View File

@ -383,7 +383,53 @@ class CoreTest extends PHPUnit_Framework_TestCase {
$this->assertEquals($value, $post->{$key}); $this->assertEquals($value, $post->{$key});
} }
} }
} }
}
function providerTestGetLayoutChoices() {
return array(
array(
array(),
array()
),
array(
array(
'layout.php' => <<<FILE
Test
FILE
),
array()
),
array(
array(
'layout.php' => <<<FILE
/*
Layout Name: Test
*/
FILE
),
array('layout.php' => 'Test')
),
);
}
/**
* @dataProvider providerTestGetLayoutChoices
*/
function testGetLayoutChoices($files, $expected_results) {
$core = $this->getMock('ComicPressAddonCore', array('_glob', '_file_get_contents'));
_set_template_directory('/test');
$file_names = array();
foreach (array_keys($files) as $file) { $file_names[] = '/test/layouts/' . $file; }
$core->expects($this->once())->method('_glob')->with('/test/layouts/*')->will($this->returnValue($file_names));
foreach ($files as $file => $contents) {
$core->expects($this->once())->method('_file_get_contents')->with('/test/layouts/' . $file)->will($this->returnValue($contents));
}
$this->assertEquals($expected_results, $core->get_layout_choices());
} }
} }