From 82ee59779ea9a5d2d9234e622f56cfcc4c22ff3a Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Thu, 21 Jul 2011 21:32:48 +0200 Subject: support global and per-host configuration files --- tests/SemanticScuttle/ConfigTest.php | 206 +++++++++++++++++++++++++++++++++++ 1 file changed, 206 insertions(+) create mode 100644 tests/SemanticScuttle/ConfigTest.php (limited to 'tests/SemanticScuttle/ConfigTest.php') diff --git a/tests/SemanticScuttle/ConfigTest.php b/tests/SemanticScuttle/ConfigTest.php new file mode 100644 index 0000000..670f82a --- /dev/null +++ b/tests/SemanticScuttle/ConfigTest.php @@ -0,0 +1,206 @@ +_setPointer($scope, $varpath)) { + return false; + } + + return parent::url_stat($path, $flags); + } +} + +class SemanticScuttle_ConfigTest extends PHPUnit_Framework_TestCase +{ + /** + * Configuration object to test + */ + protected $cfg; + + + public function setUpWrapper() + { + if (!in_array('unittest', stream_get_wrappers())) { + stream_wrapper_register( + 'unittest', 'SemanticScuttle_ConfigTest_StreamVar' + ); + } + + $this->cfg = $this->getMock( + 'SemanticScuttle_Config', + array('getDataDir') + ); + $this->cfg->expects($this->once()) + ->method('getDataDir') + ->will($this->returnValue('/data-dir/')); + + $this->cfg->filePrefix = 'unittest://GLOBALS/unittest-dir'; + } + + + + public function testFindLocalData() + { + $this->setUpWrapper(); + $GLOBALS['unittest-dir']['data-dir'] = array( + 'config.php' => 'content', + 'config.default.php' => 'content' + ); + $this->assertEquals( + array( + '/data-dir/config.php', + '/data-dir/config.default.php' + ), + $this->cfg->findFiles() + ); + } + + public function testFindHostPreferredOverNonHostConfig() + { + $this->setUpWrapper(); + $_SERVER['HTTP_HOST'] = 'foo.example.org'; + + $GLOBALS['unittest-dir']['data-dir'] = array( + 'config.php' => 'content', + 'config.foo.example.org.php' => 'content', + 'config.default.php' => 'content' + ); + $this->assertEquals( + array( + '/data-dir/config.foo.example.org.php', + '/data-dir/config.default.php' + ), + $this->cfg->findFiles() + ); + } + + public function testFindEtcHostPreferredOverLocalConfigPhp() + { + $this->setUpWrapper(); + $_SERVER['HTTP_HOST'] = 'foo.example.org'; + + $GLOBALS['unittest-dir'] = array( + 'etc' => array( + 'semanticscuttle' => array( + 'config.foo.example.org.php' => 'content', + ) + ), + 'data-dir' => array( + 'config.php' => 'content', + 'config.default.php' => 'content' + ) + ); + + $this->assertEquals( + array( + '/etc/semanticscuttle/config.foo.example.org.php', + '/data-dir/config.default.php' + ), + $this->cfg->findFiles() + ); + } + + public function testFindEtcConfig() + { + $this->setUpWrapper(); + $GLOBALS['unittest-dir'] = array( + 'etc' => array( + 'semanticscuttle' => array( + 'config.php' => 'content' + ) + ), + 'data-dir' => array( + 'config.default.php' => 'content' + ) + ); + $this->assertEquals( + array( + '/etc/semanticscuttle/config.php', + '/data-dir/config.default.php' + ), + $this->cfg->findFiles() + ); + } + + public function testFindEtcDefaultConfig() + { + $this->setUpWrapper(); + $GLOBALS['unittest-dir'] = array( + 'etc' => array( + 'semanticscuttle' => array( + 'config.php' => 'content', + 'config.default.php' => 'content' + ) + ), + ); + $this->assertEquals( + array( + '/etc/semanticscuttle/config.php', + '/etc/semanticscuttle/config.default.php' + ), + $this->cfg->findFiles() + ); + } + + public function testFindLocalDefaultPreferredOverEtcDefault() + { + $this->setUpWrapper(); + $GLOBALS['unittest-dir'] = array( + 'etc' => array( + 'semanticscuttle' => array( + 'config.php' => 'content', + 'config.default.php' => 'content' + ) + ), + 'data-dir' => array( + 'config.php' => 'content', + 'config.default.php' => 'content' + ) + ); + $this->assertEquals( + array( + '/data-dir/config.php', + '/data-dir/config.default.php' + ), + $this->cfg->findFiles() + ); + } + + public function testFindSameDirDefaultPreferred() + { + $this->setUpWrapper(); + $GLOBALS['unittest-dir'] = array( + 'etc' => array( + 'semanticscuttle' => array( + 'config.php' => 'content', + 'config.default.php' => 'content' + ) + ), + 'data-dir' => array( + 'config.default.php' => 'content' + ) + ); + $this->assertEquals( + array( + '/etc/semanticscuttle/config.php', + '/etc/semanticscuttle/config.default.php' + ), + $this->cfg->findFiles() + ); + } + +} + +?> \ No newline at end of file -- cgit v1.2.3