aboutsummaryrefslogtreecommitdiff
path: root/tests/SemanticScuttle/ConfigTest.php
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2011-07-21 21:32:48 +0200
committerChristian Weiske <cweiske@cweiske.de>2011-07-21 21:32:48 +0200
commit82ee59779ea9a5d2d9234e622f56cfcc4c22ff3a (patch)
tree8dbaba53a257464942d71c66a559944b949fdb9b /tests/SemanticScuttle/ConfigTest.php
parent846e3a38cf049266a33cb3e553fcacbcbdc0bfa3 (diff)
downloadsemanticscuttle-82ee59779ea9a5d2d9234e622f56cfcc4c22ff3a.tar.gz
semanticscuttle-82ee59779ea9a5d2d9234e622f56cfcc4c22ff3a.tar.bz2
support global and per-host configuration files
Diffstat (limited to 'tests/SemanticScuttle/ConfigTest.php')
-rw-r--r--tests/SemanticScuttle/ConfigTest.php206
1 files changed, 206 insertions, 0 deletions
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 @@
+<?php
+//that's PEAR's Stream_Var package
+require_once 'Stream/Var.php';
+
+class SemanticScuttle_ConfigTest_StreamVar extends Stream_Var {
+ public function url_stat($path, $flags)
+ {
+ $url = parse_url($path);
+
+ $scope = $url['host'];
+ if (isset($url['path'])) {
+ $varpath = substr($url['path'], 1);
+ } else {
+ $varpath = '';
+ }
+
+ if (!$this->_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