get layout choices
This commit is contained in:
parent
472581132c
commit
10fed1f385
@ -442,6 +442,20 @@ class ComicPressAddonCore extends ComicPressAddon {
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -385,6 +385,52 @@ class CoreTest extends PHPUnit_Framework_TestCase {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
Loading…
Reference in New Issue
Block a user