diff options
Diffstat (limited to 'tests/SemanticScuttle')
-rw-r--r-- | tests/SemanticScuttle/ConfigTest.php | 206 | ||||
-rw-r--r-- | tests/SemanticScuttle/EnvironmentTest.php | 95 |
2 files changed, 301 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 diff --git a/tests/SemanticScuttle/EnvironmentTest.php b/tests/SemanticScuttle/EnvironmentTest.php new file mode 100644 index 0000000..a41efa1 --- /dev/null +++ b/tests/SemanticScuttle/EnvironmentTest.php @@ -0,0 +1,95 @@ +<?php + +class SemanticScuttle_EnvironmentTest extends PHPUnit_Framework_TestCase +{ + public function testServerPathInfoModPhp() + { + $_SERVER = array( + 'HTTP_USER_AGENT' => 'Opera/9.80 (X11; Linux x86_64; U; de) Presto/2.9.168 Version/11.50', + 'HTTP_HOST' => 'bm-cgi.bogo', + 'HTTP_ACCEPT' => 'text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/webp, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1', + 'HTTP_ACCEPT_LANGUAGE' => 'de-DE,de;q=0.9,en;q=0.8', + 'HTTP_ACCEPT_ENCODING' => 'gzip, deflate', + 'HTTP_COOKIE' => 'PHPSESSID=ga446jhs0e09hkt60u9bsmp0n0', + 'HTTP_CACHE_CONTROL' => 'no-cache', + 'HTTP_CONNECTION' => 'Keep-Alive', + 'PATH' => '/usr/local/bin:/usr/bin:/bin', + 'SERVER_SIGNATURE' => '<address>Apache/2.2.17 (Ubuntu) Server at bm-cgi.bogo Port 80</address>', + 'SERVER_SOFTWARE' => 'Apache/2.2.17 (Ubuntu)', + 'SERVER_NAME' => 'bm-cgi.bogo', + 'SERVER_ADDR' => '127.0.0.1', + 'SERVER_PORT' => '80', + 'REMOTE_ADDR' => '127.0.0.1', + 'DOCUMENT_ROOT' => '/etc/apache2/htdocs', + 'SERVER_ADMIN' => '[no address given]', + 'SCRIPT_FILENAME' => '/home/cweiske/Dev/html/hosts/bm-cgi.bogo/profile.php', + 'REMOTE_PORT' => '45349', + 'GATEWAY_INTERFACE' => 'CGI/1.1', + 'SERVER_PROTOCOL' => 'HTTP/1.1', + 'REQUEST_METHOD' => 'GET', + 'QUERY_STRING' => '', + 'REQUEST_URI' => '/profile.php/dummy', + 'SCRIPT_NAME' => '/profile.php', + 'PATH_INFO' => '/dummy', + 'PATH_TRANSLATED' => '/home/cweiske/Dev/html/hosts/bm-cgi.bogo/dummy', + 'PHP_SELF' => '/profile.php/dummy', + 'REQUEST_TIME' => 1311422546, + ); + $this->assertEquals( + '/dummy', SemanticScuttle_Environment::getServerPathInfo() + ); + } + + + public function testServerPathInfoFastCgi() + { + $_SERVER = array( + 'PHP_FCGI_MAX_REQUESTS' => '5000', + 'PHPRC' => '/etc/php5/cgi/5.3.6/', + 'PHP_FCGI_CHILDREN' => '3', + 'PWD' => '/var/www/cgi-bin', + 'FCGI_ROLE' => 'RESPONDER', + 'REDIRECT_HANDLER' => 'php-cgi', + 'REDIRECT_STATUS' => '200', + 'HTTP_USER_AGENT' => 'Opera/9.80 (X11; Linux x86_64; U; de) Presto/2.9.168 Version/11.50', + 'HTTP_HOST' => 'bm-cgi.bogo', + 'HTTP_ACCEPT' => 'text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/webp, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1', + 'HTTP_ACCEPT_LANGUAGE' => 'de-DE,de;q=0.9,en;q=0.8', + 'HTTP_ACCEPT_ENCODING' => 'gzip, deflate', + 'HTTP_COOKIE' => 'PHPSESSID=ga446jhs0e09hkt60u9bsmp0n0', + 'HTTP_CONNECTION' => 'Keep-Alive', + 'PATH' => '/usr/local/bin:/usr/bin:/bin', + 'SERVER_SIGNATURE' => '<address>Apache/2.2.17 (Ubuntu) Server at bm-cgi.bogo Port 80</address>', + 'SERVER_SOFTWARE' => 'Apache/2.2.17 (Ubuntu)', + 'SERVER_NAME' => 'bm-cgi.bogo', + 'SERVER_ADDR' => '127.0.0.1', + 'SERVER_PORT' => '80', + 'REMOTE_ADDR' => '127.0.0.1', + 'DOCUMENT_ROOT' => '/etc/apache2/htdocs', + 'SERVER_ADMIN' => '[no address given]', + 'SCRIPT_FILENAME' => '/home/cweiske/Dev/html/hosts/bm-cgi.bogo/profile.php', + 'REMOTE_PORT' => '45342', + 'REDIRECT_URL' => '/profile.php/dummy', + 'GATEWAY_INTERFACE' => 'CGI/1.1', + 'SERVER_PROTOCOL' => 'HTTP/1.1', + 'REQUEST_METHOD' => 'GET', + 'QUERY_STRING' => '', + 'REQUEST_URI' => '/profile.php/dummy', + 'SCRIPT_NAME' => '/profile.php', + 'PATH_INFO' => '/dummy', + 'PATH_TRANSLATED' => '/etc/apache2/htdocs/dummy', + 'ORIG_PATH_INFO' => '/profile.php/dummy', + 'ORIG_SCRIPT_NAME' => '/cgi-bin-php/php-cgi-5.3.6', + 'ORIG_SCRIPT_FILENAME' => '/var/www/cgi-bin/php-cgi-5.3.6', + 'ORIG_PATH_TRANSLATED' => '/home/cweiske/Dev/html/hosts/bm-cgi.bogo/profile.php/dummy', + 'PHP_SELF' => '/profile.php/dummy', + 'REQUEST_TIME' => 1311422521, + ); + $this->assertEquals( + '/dummy', SemanticScuttle_Environment::getServerPathInfo() + ); + } + +} + +?>
\ No newline at end of file |