Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 6 commits
  • 19 files changed
  • 0 commit comments
  • 1 contributor
Commits on Feb 12, 2014
@dchill42 dchill42 Moved Config test
Signed-off-by: Darren Hill <dchill42@gmail.com>
112d2c9
Commits on Feb 18, 2014
@dchill42 dchill42 Moved exceptions to individual files for autoloading
Signed-off-by: Darren Hill <dchill42@gmail.com>
e4f35dd
@dchill42 dchill42 Restructured Travis test suites
Signed-off-by: Darren Hill <dchill42@gmail.com>
4011a89
@dchill42 dchill42 Converted XylophoneTest to use getMock()
Signed-off-by: Darren Hill <dchill42@gmail.com>
c611643
@dchill42 dchill42 Converted exit to exception, removed systemUrl(), and did test-based …
…cleanup

Signed-off-by: Darren Hill <dchill42@gmail.com>
6027865
@dchill42 dchill42 Added ConfigTest
Signed-off-by: Darren Hill <dchill42@gmail.com>
8df6d9b
View
22 .travis.yml
@@ -5,23 +5,25 @@ php:
- 5.4
- 5.5
-#env:
-# - DB=mysql
-# - DB=mysqli
-# - DB=pgsql
-# - DB=sqlite
-# - DB=pdo/mysql
-# - DB=pdo/pgsql
-# - DB=pdo/sqlite
+env:
+ - SUITE=core
+# - SUITE=libraries
+# - SUITE=database/mysql
+# - SUITE=database/mysqli
+# - SUITE=database/pgsql
+# - SUITE=database/sqlite
+# - SUITE=database/pdo/mysql
+# - SUITE=database/pdo/pgsql
+# - SUITE=database/pdo/sqlite
before_script:
- composer install --dev --no-progress
# - sh -c "if [ '$DB' = 'pgsql' ] || [ '$DB' = 'pdo/pgsql' ]; then psql -c 'DROP DATABASE IF EXISTS ci_test;' -U postgres; fi"
# - sh -c "if [ '$DB' = 'pgsql' ] || [ '$DB' = 'pdo/pgsql' ]; then psql -c 'create database ci_test;' -U postgres; fi"
# - sh -c "if [ '$DB' = 'mysql' ] || [ '$DB' = 'mysqli' ] || [ '$DB' = 'pdo/mysql' ]; then mysql -e 'create database IF NOT EXISTS ci_test;'; fi"
-#script: phpunit --coverage-text --configuration tests/travis/$DB.phpunit.xml
-script: phpunit --coverage-text --configuration tests/phpunit.xml
+script: phpunit --coverage-text --configuration tests/travis/$SUITE/phpunit.xml
+#script: phpunit --coverage-text --configuration tests/phpunit.xml
branches:
only:
View
49 system/core/AlFineException.php
@@ -0,0 +1,49 @@
+<?php
+/**
+ * Xylophone
+ *
+ * An open source HMVC application development framework for PHP 5.3 or newer
+ * Derived from CodeIgniter, Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/)
+ *
+ * NOTICE OF LICENSE
+ *
+ * Licensed under the Open Software License version 3.0
+ *
+ * This source file is subject to the Open Software License (OSL 3.0) that is
+ * bundled with this package in the files license.txt / license.rst. It is
+ * also available through the world wide web at this URL:
+ * http://opensource.org/licenses/OSL-3.0
+ * If you did not receive a copy of the license and are unable to obtain it
+ * through the world wide web, please send an email to licensing@xylophone.io
+ * so we can send you a copy immediately.
+ *
+ * @package Xylophone
+ * @author Xylophone Dev Team, EllisLab Dev Team
+ * @copyright Copyright (c) 2014, Xylophone Team (http://xylophone.io/)
+ * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
+ * @link http://xylophone.io
+ * @since Version 1.0
+ * @filesource
+ */
+namespace Xylophone\core;
+
+defined('BASEPATH') OR exit('No direct script access allowed');
+
+/**
+ * Al Fine Exception
+ *
+ * This exception may be thrown when the application has completed its output
+ * (early) and needs to skip to the end (al fine) of processing and exit cleanly.
+ * It is particularly useful when a module takes over the request and generates
+ * output in place of the normal controller output (such as a login prompt).
+ *
+ * @codeCoverageIgnore
+ *
+ * @package Xylophone
+ * @subpackage core
+ */
+class AlFineException extends \Exception
+{
+ // Nothing to see here - just a name
+}
+
View
49 system/core/AutoloadException.php
@@ -0,0 +1,49 @@
+<?php
+/**
+ * Xylophone
+ *
+ * An open source HMVC application development framework for PHP 5.3 or newer
+ * Derived from CodeIgniter, Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/)
+ *
+ * NOTICE OF LICENSE
+ *
+ * Licensed under the Open Software License version 3.0
+ *
+ * This source file is subject to the Open Software License (OSL 3.0) that is
+ * bundled with this package in the files license.txt / license.rst. It is
+ * also available through the world wide web at this URL:
+ * http://opensource.org/licenses/OSL-3.0
+ * If you did not receive a copy of the license and are unable to obtain it
+ * through the world wide web, please send an email to licensing@xylophone.io
+ * so we can send you a copy immediately.
+ *
+ * @package Xylophone
+ * @author Xylophone Dev Team, EllisLab Dev Team
+ * @copyright Copyright (c) 2014, Xylophone Team (http://xylophone.io/)
+ * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
+ * @link http://xylophone.io
+ * @since Version 1.0
+ * @filesource
+ */
+namespace Xylophone\core;
+
+defined('BASEPATH') OR exit('No direct script access allowed');
+
+/**
+ * Autoloader Exception
+ *
+ * This exception is thrown by the autoloader when a class file cannot be found.
+ * Doing so bypasses the fatal class-not-found PHP error and lets the framework
+ * catch the exception and try another namespace, generating its own error if
+ * none are found.
+ *
+ * @codeCoverageIgnore
+ *
+ * @package Xylophone
+ * @subpackage core
+ */
+class AutoloadException extends \Exception
+{
+ // Nothing to see here - just a name
+}
+
View
72 system/core/Config.php
@@ -61,10 +61,9 @@ public function __construct()
// Read the config file
$this->config = $this->get('config.php', 'config');
if (!is_array($this->config)) {
- header('HTTP/1.1 503 Service Unavailable.', true, 503);
- echo $this->config === false ? 'The configuration file does not exist.' :
+ $msg = ($this->config === false) ? 'The configuration file does not exist.' :
'The configuration file is invalid.';
- exit(EXIT_CONFIG);
+ throw new ExitException($msg);
}
// Set the base_url automatically if none was provided
@@ -110,24 +109,24 @@ public function load($file = '', $sections = false, $graceful = false)
if ($graceful) {
return false;
}
- $XY->showError('The configuration file '.$name.'.php does not exist.');
+ return $XY->showError('The configuration file '.$name.'.php does not exist.');
}
else if (is_string($config)) {
if ($graceful) {
return false;
}
- $XY->showError('Your '.$name.'.php file does not appear to contain a valid configuration array.');
+ return $XY->showError('Your '.$name.'.php file does not appear to contain a valid configuration array.');
}
// Check for sections
if ($sections === true) {
// Merge or set section
$this->config[$name] = isset($this->config[$name]) ?
- array_merge_recursive($this->config[$name], $config) : $this->config[$name] = $config;
+ array_replace_recursive($this->config[$name], $config) : $this->config[$name] = $config;
}
else {
// Merge config
- $this->config = array_merge_recursive($this->config, $config);
+ $this->config = array_replace_recursive($this->config, $config);
}
// Mark file as loaded
@@ -193,7 +192,8 @@ public function getExtra($_file, $_name, &$_extras)
if ($_extras !== false) {
// Get associative array of public vars
foreach (get_defined_vars() as $_key => $_var) {
- $_key[0] !== '_' && $_key !== $_name && $_extras[$_key] = $_var;
+ $_key[0] !== '_' && $_key !== $_name && $_key !== 'this' && $_key != 'XY' &&
+ $_extras[$_key] = $_var;
}
}
@@ -235,7 +235,7 @@ public function item($item, $index = '')
if ($index === '') {
return isset($this->config[$item]) ? $this->config[$item] : null;
}
- return isset($this->config[$index], $this->config[$index][$item]) ? $this->config[$index][$item] : null;
+ return isset($this->config[$index][$item]) ? $this->config[$index][$item] : null;
}
/**
@@ -269,34 +269,37 @@ public function slashItem($item)
*/
public function siteUrl($uri = '', $protocol = null)
{
+ // Get base URL and replace protocol if specified
$base_url = $this->slashItem('base_url');
isset($protocol) && $base_url = $protocol.substr($base_url, strpos($base_url, '://'));
+ // Check for URI
if (empty($uri)) {
+ // Done here
return $base_url.$this->item('index_page');
}
+ // Clean URI string and check for query strings
$uri = $this->uriString($uri);
+ if ($this->item('enable_query_strings')) {
+ // Assemble base URL with URI string
+ return $base_url.$this->item('index_page').$uri;
+ }
- if ($this->item('enable_query_strings') === false) {
- $suffix = isset($this->config['url_suffix']) ? $this->config['url_suffix'] : '';
-
- if ($suffix !== '') {
- if (($offset = strpos($uri, '?')) !== false) {
- $uri = substr($uri, 0, $offset).$suffix.substr($uri, $offset);
- }
- else {
- $uri .= $suffix;
- }
+ // Check for URL suffix
+ $suffix = isset($this->config['url_suffix']) ? $this->config['url_suffix'] : '';
+ if ($suffix !== '') {
+ // Add suffix before any query string
+ if (($offset = strpos($uri, '?')) === false) {
+ $uri .= $suffix;
+ }
+ else {
+ $uri = substr($uri, 0, $offset).$suffix.substr($uri, $offset);
}
-
- return $base_url.$this->slashItem('index_page').$uri;
- }
- elseif (strpos($uri, '?') === false) {
- $uri = '?'.$uri;
}
- return $base_url.$this->item('index_page').$uri;
+ // Return base URL with URI string
+ return $base_url.$this->slashItem('index_page').$uri;
}
/**
@@ -328,30 +331,19 @@ public function baseUrl($uri = '', $protocol = null)
*/
protected function uriString($uri)
{
- if ($this->item('enable_query_strings') === false) {
+ if (!$this->item('enable_query_strings')) {
is_array($uri) && $uri = implode('/', $uri);
return trim($uri, '/');
}
elseif (is_array($uri)) {
- return http_build_query($uri);
+ $uri = http_build_query($uri);
}
+ strpos($uri, '?') === false && $uri = '?'.$uri;
return $uri;
}
/**
- * System URL
- *
- * @return string System URL
- */
- public function systemUrl()
- {
- global $XY;
- $x = explode('/', preg_replace('|/*(.+?)/*$|', '\\1', $XY->system_path));
- return $this->slashItem('base_url').end($x).'/';
- }
-
- /**
* Set a config file item
*
* @param mixed $item Config item key or array of config items
@@ -363,7 +355,7 @@ public function setItem($item, $value = '')
// Check for multiple items
if (is_array($item)) {
// Merge into config
- $this->config = array_merge_recursive($this->config, $item);
+ $this->config = array_replace_recursive($this->config, $item);
}
else {
// Set single item
View
47 system/core/ExitException.php
@@ -0,0 +1,47 @@
+<?php
+/**
+ * Xylophone
+ *
+ * An open source HMVC application development framework for PHP 5.3 or newer
+ * Derived from CodeIgniter, Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/)
+ *
+ * NOTICE OF LICENSE
+ *
+ * Licensed under the Open Software License version 3.0
+ *
+ * This source file is subject to the Open Software License (OSL 3.0) that is
+ * bundled with this package in the files license.txt / license.rst. It is
+ * also available through the world wide web at this URL:
+ * http://opensource.org/licenses/OSL-3.0
+ * If you did not receive a copy of the license and are unable to obtain it
+ * through the world wide web, please send an email to licensing@xylophone.io
+ * so we can send you a copy immediately.
+ *
+ * @package Xylophone
+ * @author Xylophone Dev Team, EllisLab Dev Team
+ * @copyright Copyright (c) 2014, Xylophone Team (http://xylophone.io/)
+ * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
+ * @link http://xylophone.io
+ * @since Version 1.0
+ * @filesource
+ */
+namespace Xylophone\core;
+
+defined('BASEPATH') OR exit('No direct script access allowed');
+
+/**
+ * Exit Exception
+ *
+ * This exception may be thrown anywhere the application needs to exit with
+ * a message and an error code.
+ *
+ * @codeCoverageIgnore
+ *
+ * @package Xylophone
+ * @subpackage core
+ */
+class ExitException extends \Exception
+{
+ // Nothing to see here - just a name
+}
+
View
54 system/core/Xylophone.php
@@ -30,49 +30,6 @@
defined('BASEPATH') OR exit('No direct script access allowed');
/**
- * Al Fine Exception
- *
- * This exception may be thrown when the application has completed its output
- * (early) and needs to skip to the end (al fine) of processing and exit cleanly.
- * It is particularly useful when a module takes over the request and generates
- * output in place of the normal controller output (such as a login prompt).
- *
- * @codeCoverageIgnore
- *
- * @package Xylophone
- * @subpackage core
- */
-class AlFineException extends \Exception { }
-
-/**
- * Exit Exception
- *
- * This exception may be thrown anywhere the application needs to exit with
- * a message and an error code.
- *
- * @codeCoverageIgnore
- *
- * @package Xylophone
- * @subpackage core
- */
-class ExitException extends \Exception { }
-
-/**
- * Autoloader Exception
- *
- * This exception is thrown by the autoloader when a class file cannot be found.
- * Doing so bypasses the fatal class-not-found PHP error and lets the framework
- * catch the exception and try another namespace, generating its own error if
- * none are found.
- *
- * @codeCoverageIgnore
- *
- * @package Xylophone
- * @subpackage core
- */
-class AutoloadException extends \Exception { }
-
-/**
* Xylophone Framework Class
*
* @package Xylophone
@@ -188,6 +145,7 @@ public static function instance($init = null)
// Check namespaces after application
if (!$app && !$ns) {
// Fail out
+ include_once('ExitException.php');
$msg = 'The global namespace is reserved for application classes. '.
'Please specify a namespace for your additional path in the following file: '.
basename($_SERVER['PHP_SELF']);
@@ -207,6 +165,7 @@ public static function instance($init = null)
}
if (!$resolved) {
// Fail out
+ include_once('ExitException.php');
$msg = ($app ? 'Your application folder path does not appear to be set correctly.' :
'The "'.$ns.'" namespace path does not appear to be set correctly.').
' Please fix it in the following file: '.basename($_SERVER['PHP_SELF']);
@@ -479,7 +438,7 @@ protected function playVerse($benchmark)
try {
$this->callController($this->router->route) || $this->show404($class.'/'.$method);
} catch (AlFineException $ex) {
- // Finished early - nothing to do herek
+ // Finished early - nothing to do here but carry on to the end
}
// Mark end time, display output unless overridden, and call post_system
@@ -638,7 +597,7 @@ public function loadClass($name, $hint, $param = null, $param2 = null)
* @param string $path Path to source files
* @return bool TRUE on success, otherwise FALSE
*/
- public function addNamespace($namespace, $path)
+ public function addNamespace($namespace, $path = '')
{
// Convert to array
is_array($namespace) || $namespace = array($namespace => $path);
@@ -966,7 +925,10 @@ public function autoloader($class)
}
}
- // File not found - throw exception
+ // File not found - throw exception (unless it WAS the exception)
+ if (trim($class, '\\') == 'Xylophone\core\AutoloadException') {
+ return;
+ }
throw new AutoloadException('Could not find class "'.$class.'"');
}
View
231 tests/Mocks/core/Xylophone.php
@@ -37,29 +37,11 @@ class Xylophone extends \Xylophone\core\Xylophone
/** @var array Relative path resolution bases (made public) */
public $resolve_bases = array();
- /** @var array PHP version comparison results (made public) */
- public $is_php = array();
-
/** @var string Autoloader hint (made public) */
public $loader_hint = '';
- /** @var array Pre-loaded classes to return from loadClass() */
- public $load_class = array();
-
- /** @var bool Return value for callController() */
- public $call_controller = null;
-
- /** @var array Test arguments for play() */
- public $play_args = array();
-
- /** @var array Arguments passed to show404() */
- public $show_404 = null;
-
- /** @var bool Skip initialize() flag */
- public static $skip_init = false;
-
- /** @var bool Skip setHandlers() flag */
- public static $skip_handlers = false;
+ /** @var bool Skip tune() flag */
+ public static $skip_tune = false;
/**
* Initialize framework
@@ -69,215 +51,10 @@ class Xylophone extends \Xylophone\core\Xylophone
* @param array $init Initialization parameters
* @return void
*/
- public function initialize($init)
+ public function tune($init)
{
// Call the real method unless we're skipping
- self::$skip_init || parent::initialize($init);
- }
-
- /**
- * Load a class
- *
- * This overalod allows us to return mock objects instead of running the real method.
- *
- * @param string $name Class name with optional namespace
- * @param string $hint Namespace hint (if namespace not provided) - forward slashes
- * @param mixed $param Optional constructor parameter
- * @param mixed $param2 Optional second constructor parameter
- * @return object Class object on success, otherwise NULL
- */
- public function loadClass($name, $hint, $param = null, $param2 = null)
- {
- // Intercept pre-loaded classes
- $class = $hint.'\\'.$name;
- if (isset($this->load_class[$class])) {
- return $this->load_class[$class];
- }
-
- // Otherwise call the real method
- return parent::loadClass($name, $hint, $param, $param2);
- }
-
- /**
- * Call a controller method
- *
- * This overload allows us to conditionally run the real callController method.
- *
- * @param mixed $class Class name string or route stack array
- * @param string $method Method name (unless $class is stack)
- * @param array $args Arguments array (unless $class is stack)
- * @param string $name Optional object name
- * @param bool $return Whether to return output
- * @return mixed Output if $return, TRUE on success, otherwise FALSE
- */
- public function callController($class, $method = '', array $args = array(), $name = '', $return = false)
- {
- // Check for return value
- if ($this->call_controller !== null) {
- // Check for exception to throw
- if (is_string($this->call_controller)) {
- throw new $this->call_controller();
- }
-
- // Swap return value with $class arg and return
- $ret = $this->call_controller;
- $this->call_controller = $class;
- return $ret;
- }
-
- // Otherwise call the real method
- return parent::callController($class, $method, $args, $name, $return);
- }
-
- /**
- * Play Introduction
- *
- * This overload allows us to conditionally run the real playIntro method.
- *
- * @param mixed $benchmark Initial benchmark time or FALSE
- * @param array $config Reference to bootstrap config items
- * @return array Reference to autoload config array
- */
- public function &playIntro($benchmark, &$config)
- {
- // Check for test args
- if (isset($this->play_args['intro_atl'])) {
- $this->play_args['intro_bmk'] = $benchmark;
- $this->play_args['intro_cfg'] =& $config;
- return $this->play_args['intro_atl'];
- }
-
- // Otherwise call the real method
- return parent::playIntro($benchmark, $config);
- }
-
- /**
- * Play Bridge
- *
- * This overload allows us to conditionally run the real playBridge method.
- *
- * @param array $routing Routing overrides
- * @return void
- */
- public function playBridge(&$routing)
- {
- // Check for test args
- if (!empty($this->play_args)) {
- $this->play_args['bridge_rtg'] =& $routing;
- return;
- }
-
- // Otherwise call the real method
- return parent::playBridge($routing);
- }
-
- /**
- * Play Coda
- *
- * This overload allows us to conditionally run the real playCoda method.
- *
- * @return bool TRUE if cache output, otherwise FALSE
- */
- public function playCoda()
- {
- // Check for test args
- if (isset($this->play_args['coda_ret'])) {
- return $this->play_args['coda_ret'];
- }
-
- // Otherwise call the real method
- return parent::playCoda();
- }
-
- /**
- * Play Chorus
- *
- * This overload allows us to conditionally run the real playChorus method.
- *
- * @param mixed $benchmark Benchmark flag
- * @param array $autoload Reference to autoload config array
- * @return void
- */
- public function playChorus($benchmark, &$autoload)
- {
- // Check for test args
- if (!empty($this->play_args)) {
- $this->play_args['chorus_bmk'] = $benchmark;
- $this->play_args['chorus_atl'] =& $autoload;
- return;
- }
-
- // Otherwise call the real method
- return parent::playChorus($benchmark, $autoload);
- }
-
- /**
- * Play Verse
- *
- * This overload allows us to conditionally run the real playVerse method.
- *
- * @param mixed $benchmark Benchmark flag
- * @return void
- */
- public function playVerse($benchmark)
- {
- // Check for test args
- if (!empty($this->play_args)) {
- $this->play_args['verse_bmk'] = $benchmark;
- return;
- }
-
- // Otherwise call the real method
- return parent::playVerse($benchmark);
- }
-
- /**
- * Show 404 error to user
- *
- * This function is similar to showError() above, but it displays a 404 error.
- *
- * @param string $page Page URL
- * @param bool $log_error Whether to log the error
- * @return void
- */
- public function show404($page = '', $log_error = true)
- {
- // Check for arguments array
- if (is_array($this->show_404)) {
- // Add page argument to array
- $this->show_404[] = $page;
- return;
- }
-
- // Otherwise call the real method
- return parent::show404($page, $log_error);
- }
-
- /**
- * Register autoloader, error, and shutdown handlers
- *
- * This overload allows us to conditionally run the real registerHandlers method.
- *
- * @return void
- */
- public function registerHandlers()
- {
- // Call the real method unless we're skipping
- self::$skip_handlers || parent::registerHandlers();
- }
-
- /**
- * Get real path
- *
- * This abstraction of the realpath call allows overriding for unit testing
- *
- * @param string $path Path to resolve
- * @return string Real path
- */
- protected function realpath($path)
- {
- // Just trim trailing slash since realpath() fails on VFS urls
- return rtrim($path, '\/');
+ self::$skip_tune || parent::tune($init);
}
}
View
801 tests/Xylophone/core/ConfigTest.php
@@ -0,0 +1,801 @@
+<?php
+/**
+ * Xylophone
+ *
+ * An open source HMVC application development framework for PHP 5.3 or newer
+ * Derived from CodeIgniter, Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/)
+ *
+ * NOTICE OF LICENSE
+ *
+ * Licensed under the Open Software License version 3.0
+ *
+ * This source file is subject to the Open Software License (OSL 3.0) that is
+ * bundled with this package in the files license.txt / license.rst. It is
+ * also available through the world wide web at this URL:
+ * http://opensource.org/licenses/OSL-3.0
+ * If you did not receive a copy of the license and are unable to obtain it
+ * through the world wide web, please send an email to licensing@xylophone.io
+ * so we can send you a copy immediately.
+ *
+ * @package Xylophone
+ * @author Xylophone Dev Team, EllisLab Dev Team
+ * @copyright Copyright (c) 2014, Xylophone Team (http://xylophone.io/)
+ * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
+ * @link http://xylophone.io
+ * @since Version 1.0
+ * @filesource
+ */
+
+/**
+ * Config Unit Test
+ *
+ * @package Xylophone
+ */
+class ConfigTest extends XyTestCase
+{
+ /**
+ * Test __construct()
+ */
+ public function testConstruct()
+ {
+ // Mock Config and set up call
+ $config = $this->getMock('Xylophone\core\Config', array('get'), array(), '', false);
+ $cfg = array('base_url' => 'http://example.com/');
+ $config->expects($this->once())->method('get')->
+ with($this->equalTo('config.php'), $this->equalTo('config'))->
+ will($this->returnValue($cfg));
+
+ // Verify config and is_loaded are empty
+ $this->assertEmpty($config->config);
+ $this->assertEmpty($config->is_loaded);
+
+ // Call __construct() (yes, after instantiation) and confirm base config
+ $config->__construct();
+ $this->assertEquals($cfg, $config->config);
+ }
+
+ /**
+ * Test __construct() with no config
+ */
+ public function testConstructNoConfig()
+ {
+ // Mock Config and set up call
+ $config = $this->getMock('Xylophone\core\Config', array('get'), array(), '', false);
+ $config->expects($this->once())->method('get')->will($this->returnValue(false));
+
+ // Call __construct() (yes, again) and confirm exception
+ $this->setExpectedException('Xylophone\core\ExitException', 'The configuration file does not exist.');
+ $config->__construct();
+ }
+
+ /**
+ * Test __construct() with a bad config
+ */
+ public function testConstructBadConfig()
+ {
+ // Mock Config and set up call
+ $config = $this->getMock('Xylophone\core\Config', array('get'), array(), '', false);
+ $config->expects($this->once())->method('get')->will($this->returnValue('/some/bad/path'));
+
+ // Call __construct() (some more) and confirm exception
+ $this->setExpectedException('Xylophone\core\ExitException', 'The configuration file is invalid.');
+ $config->__construct();
+ }
+
+ /**
+ * Test __construct() with no base_url
+ */
+ public function testConstructNoBase()
+ {
+ global $XY;
+
+ // Set up args
+ $path = '/test/path/';
+ $host = 'testhost.com';
+ $url = 'http://'.$host.$path;
+
+ // Mock Xylophone and Config and set up calls
+ $XY = $this->getMock('Xylophone\core\Xylophone', array(), array(), '', false);
+ $config = $this->getMock('Xylophone\core\Config', array('get', 'setItem'), array(), '', false);
+ $config->expects($this->once())->method('get')->will($this->returnValue(array()));
+ $config->expects($this->once())->method('setItem')->
+ with($this->equalTo('base_url'), $this->equalTo($url));
+ $XY->expects($this->once())->method('isHttps')->will($this->returnValue(false));
+
+ // Set server vars
+ $http = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null;
+ $_SERVER['HTTP_HOST'] = $host;
+ $script = isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] : null;
+ $_SERVER['SCRIPT_NAME'] = $path.'file';
+
+ // Call __construct() (ad nauseum)
+ $config->__construct();
+
+ // Clean up
+ if ($script === null) {
+ unset($_SERVER['SCRIPT_NAME']);
+ }
+ else {
+ $_SERVER['SCRIPT_NAME'] = $script;
+ }
+ if ($http === null) {
+ unset($_SERVER['HTTP_HOST']);
+ }
+ else {
+ $_SERVER['HTTP_HOST'] = $http;
+ }
+ }
+
+ /**
+ * Test __construct() with no base_url and no host
+ */
+ public function testConstructNoBaseHost()
+ {
+ // Mock Config and set up calls
+ $config = $this->getMock('Xylophone\core\Config', array('get', 'setItem'), array(), '', false);
+ $config->expects($this->once())->method('get')->will($this->returnValue(array()));
+ $config->expects($this->once())->method('setItem')->
+ with($this->equalTo('base_url'), $this->equalTo('http://localhost/'));
+
+ // Set server vars
+ $http = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null;
+ unset($_SERVER['HTTP_HOST']);
+
+ // Call __construct() (one last time)
+ $config->__construct();
+
+ // Clean up
+ $http === null || $_SERVER['HTTP_HOST'] = $http;
+ }
+
+ /**
+ * Test load()
+ */
+ public function testLoad()
+ {
+ global $XY;
+
+ // Set up args
+ $name = 'testcfg';
+ $file = $name.'.php';
+ $cfg = array('one' => '1', 'two' => '2', 'three' => '3');
+
+ // Mock Xylophone and Config and Logger and set up calls
+ $XY = new stdClass();
+ $config = $this->getMock('Xylophone\core\Config', array('get'), array(), '', false);
+ $config->expects($this->once())->method('get')->with($this->equalTo($file), $this->equalTo('config'))->
+ will($this->returnValue($cfg));
+ $XY->logger = $this->getMock('Xylophone\core\Logger', array('debug'), array(), '', false);
+ $XY->logger->expects($this->once())->method('debug')->
+ with($this->equalTo('Config file loaded: '.$name.'.php'));
+
+ // Call load() and verify results
+ $this->assertTrue($config->load($file));
+ $this->assertEquals($cfg, $config->config);
+ $this->assertEquals(array($name), $config->is_loaded);
+ }
+
+ /**
+ * Test load() with sections
+ */
+ public function testLoadSections()
+ {
+ global $XY;
+
+ // Set up args
+ $name = 'sectcfg';
+ $file = $name.'.php';
+ $cfg = array('red' => 'apple', 'blue' => 'berry');
+
+ // Mock Xylophone and Config and Logger and set up calls
+ $XY = new stdClass();
+ $config = $this->getMock('Xylophone\core\Config', array('get'), array(), '', false);
+ $config->expects($this->once())->method('get')->with($this->equalTo($file), $this->equalTo('config'))->
+ will($this->returnValue($cfg));
+ $XY->logger = $this->getMock('Xylophone\core\Logger', array('debug'), array(), '', false);
+ $XY->logger->expects($this->once())->method('debug')->
+ with($this->equalTo('Config file loaded: '.$name.'.php'));
+
+ // Call load() and verify results
+ $this->assertTrue($config->load($file, true));
+ $this->assertArrayHasKey($name, $config->config);
+ $this->assertEquals($cfg, $config->config[$name]);
+ $this->assertEquals(array($name), $config->is_loaded);
+ }
+
+ /**
+ * Test load() with non-existent file
+ */
+ public function testLoadNone()
+ {
+ global $XY;
+
+ // Set up args
+ $name = 'figment';
+
+ // Mock Xylophone and Config and set up calls
+ $XY = $this->getMock('Xylophone\core\Xylophone', array(), array(), '', false);
+ $config = $this->getMock('Xylophone\core\Config', array('get'), array(), '', false);
+ $config->expects($this->once())->method('get')->
+ with($this->equalTo($name.'.php'), $this->equalTo('config'))->
+ will($this->returnValue(false));
+ $XY->expects($this->once())->method('showError')->
+ with($this->equalTo('The configuration file '.$name.'.php does not exist.'))->
+ will($this->throwException(new InvalidArgumentException));
+
+ // Call load()
+ $this->setExpectedException('InvalidArgumentException');
+ $config->load($name);
+ }
+
+ /**
+ * Test load() with graceful non-existent file
+ */
+ public function testLoadNoneGraceful()
+ {
+ // Set up args
+ $name1 = 'exists';
+ $name2 = 'graceful';
+
+ // Mock Config and set up calls
+ $config = $this->getMock('Xylophone\core\Config', array('get'), array(), '', false);
+ $config->expects($this->once())->method('get')->
+ with($this->equalTo($name2.'.php'), $this->equalTo('config'))->
+ will($this->returnValue(false));
+
+ // Set first file as loaded
+ $config->is_loaded[] = $name1;
+
+ // Call load() and verify results
+ $this->assertFalse($config->load(array($name1, $name2), false, true));
+ $this->assertEquals(array($name1), $config->is_loaded);
+ }
+
+ /**
+ * Test load() with bad file
+ */
+ public function testLoadBad()
+ {
+ global $XY;
+
+ // Set up args
+ $name = 'badcfg';
+
+ // Mock Xylophone and Config and set up calls
+ $XY = $this->getMock('Xylophone\core\Xylophone', array(), array(), '', false);
+ $config = $this->getMock('Xylophone\core\Config', array('get'), array(), '', false);
+ $config->expects($this->once())->method('get')->
+ with($this->equalTo($name.'.php'), $this->equalTo('config'))->
+ will($this->returnValue('/some/bad/path'));
+ $XY->expects($this->once())->method('showError')->
+ with($this->equalTo('Your '.$name.'.php file does not appear to contain a valid configuration array.'))->
+ will($this->throwException(new InvalidArgumentException));
+
+ // Call load()
+ $this->setExpectedException('InvalidArgumentException');
+ $config->load($name);
+ }
+
+ /**
+ * Test load() with graceful bad file
+ */
+ public function testLoadBadGraceful()
+ {
+ // Set up args
+ $name = 'badgrace';
+
+ // Mock Config and set up calls
+ $config = $this->getMock('Xylophone\core\Config', array('get'), array(), '', false);
+ $config->expects($this->once())->method('get')->with($this->equalTo($name.'.php'), $this->equalTo('config'))->
+ will($this->returnValue('/bad/file/path'));
+
+ // Call load() and verify results
+ $this->assertFalse($config->load($name, false, true));
+ }
+
+ /**
+ * Test get()
+ */
+ public function testGet()
+ {
+ // Set up args
+ $file = 'somecfg.php';
+ $name = 'config';
+ $retval = array('key' => 'val');
+
+ // Mock Config and set up call
+ $config = $this->getMock('Xylophone\core\Config', array('getExtra'), array(), '', false);
+ $config->expects($this->once())->method('getExtra')->
+ with($this->equalTo($file), $this->equalTo($name), $this->isFalse())->
+ will($this->returnValue($retval));
+
+ // Call get()
+ $config->get($file, $name);
+ }
+
+ /**
+ * Test getExtra() with no file
+ */
+ public function testGetExtraNone()
+ {
+ global $XY;
+
+ // Set up VFS
+ $this->vfsInit();
+
+ // Mock Xylophone and Config
+ $XY = new stdClass();
+ $config = $this->getMock('Xylophone\core\Config', null, array(), '', false);
+
+ // Set empty environment and config paths
+ $XY->environment = '';
+ $XY->config_paths = array($this->vfs_app_path.'/');
+
+ // Call getExtra() with non-existent file and confirm failure
+ $extras = false;
+ $this->assertFalse($config->getExtra('dummy', 'config', $extras));
+ }
+
+ /**
+ * Test getExtra() with no array
+ */
+ public function testGetExtraEmpty()
+ {
+ global $XY;
+
+ // Set up args
+ $file = 'empty.php';
+ $extras = false;
+
+ // Set up VFS and make file
+ $this->vfsInit();
+ $this->vfsCreate('config/'.$file, '<?php $foo = \'bar\';', $this->vfs_app_dir);
+
+ // Mock Xylophone and Config
+ $XY = new stdClass();
+ $config = $this->getMock('Xylophone\core\Config', null, array(), '', false);
+
+ // Set empty environment and config path
+ $XY->environment = '';
+ $XY->config_paths = array($this->vfs_app_path.'/');
+
+ // Call getExtra() and confirm result
+ $this->assertEquals($this->vfs_app_path.'/config/'.$file, $config->getExtra($file, 'config', $extras));
+ }
+
+ /**
+ * Test getExtra() with no name
+ */
+ public function testGetExtraNoName()
+ {
+ global $XY;
+
+ // Set up args
+ $file = 'global';
+ $key = 'warming';
+ $val = 'trend';
+ $extras = false;
+
+ // Set up VFS and make file
+ $this->vfsInit();
+ $this->vfsCreate('config/'.$file.'.php', '<?php $GLOBALS[\''.$key.'\'] = \''.$val.'\';', $this->vfs_app_dir);
+
+ // Mock Xylophone and Config
+ $XY = new stdClass();
+ $config = $this->getMock('Xylophone\core\Config', null, array(), '', false);
+
+ // Set empty environment and config path
+ $XY->environment = '';
+ $XY->config_paths = array($this->vfs_app_path.'/');
+
+ // Call getExtra() and confirm result
+ $this->assertTrue($config->getExtra($file, '', $extras));
+ $this->assertArrayHasKey($key, $GLOBALS);
+ $this->assertEquals($val, $GLOBALS[$key]);
+ }
+
+ /**
+ * Test getExtra()
+ */
+ public function testGetExtra()
+ {
+ global $XY;
+
+ // Set up args
+ $file = 'vars.php';
+ $cfg1 = array('one' => '1', 'two' => '3');
+ $cfg2 = array('two' => '2');
+ $result = array('one' => '1', 'two' => '2');
+ $key1 = 'pickme';
+ $key2 = 'andme';
+ $nokey = '_notme';
+ $val1 = 'first';
+ $val2 = 'second';
+ $noval = 'ignore';
+ $extras = array();
+
+ // Make file contents
+ $content1 = '<?php $config = '.var_export($cfg1, true).'; $'.$key1.' = \''.$val1.'\';';
+ $content2 = '<?php $config = '.var_export($cfg2, true).'; $'.$key2.' = \''.$val2.'\'; '.
+ '$'.$nokey.' = \''.$noval.'\';';
+
+ // Set up VFS and make files
+ $this->vfsInit();
+ $tp_dir = $this->vfsMkdir('third-party', $this->vfs_base_dir);
+ $this->vfsCreate('config/'.$file, $content1, $tp_dir);
+ $this->vfsCreate('config/'.$file, $content2, $this->vfs_app_dir);
+
+ // Mock Xylophone and Config
+ $XY = new stdClass();
+ $config = $this->getMock('Xylophone\core\Config', null, array(), '', false);
+
+ // Set empty environment and config paths
+ $XY->environment = '';
+ $XY->config_paths = array($tp_dir->url().'/', $this->vfs_app_path.'/');
+
+ // Call getExtra() and confirm result
+ $this->assertEquals($result, $config->getExtra($file, 'config', $extras));
+ $this->assertEquals(array($key1 => $val1, $key2 => $val2), $extras);
+ }
+
+ /**
+ * Test item() fail
+ */
+ public function testItemFail()
+ {
+ // Mock Config
+ $config = $this->getMock('Xylophone\core\Config', null, array(), '', false);
+
+ // Call item() and confirm missing item fail
+ $this->assertNull($config->item('missing'));
+ }
+
+ /**
+ * Test item()
+ */
+ public function testItem()
+ {
+ // Set args
+ $key = 'findme';
+ $val = 'yay';
+
+ // Mock Config and set item
+ $config = $this->getMock('Xylophone\core\Config', null, array(), '', false);
+ $config->config[$key] = $val;
+
+ // Call item() and confirm result
+ $this->assertEquals($val, $config->item($key));
+ }
+
+ /**
+ * Test item() fail with index
+ */
+ public function testItemIndexFail()
+ {
+ // Set arg
+ $key = 'empty';
+
+ // Mock Config and set item
+ $config = $this->getMock('Xylophone\core\Config', null, array(), '', false);
+ $config->config[$key] = array();
+
+ // Call item() and confirm missing item index fail
+ $this->assertNull($config->item($key, 'nothere'));
+ }
+
+ /**
+ * Test item() with index
+ */
+ public function testItemIndex()
+ {
+ // Set args
+ $key1 = 'group';
+ $key2 = 'member';
+ $val = 'ship';
+
+ // Mock Config and set item
+ $config = $this->getMock('Xylophone\core\Config', null, array(), '', false);
+ $config->config[$key1] = array($key2 => $val);
+
+ // Call item() and confirm item index
+ $this->assertEquals($val, $config->item($key2, $key1));
+ }
+
+ /**
+ * Test setItem()
+ */
+ public function testSetItem()
+ {
+ // Set up args
+ $key1 = 'single';
+ $val1 = 'value';
+ $key2 = 'multi';
+ $val2 = array($key2 => array('gets' => 'newval', 'newkey' => 'added'));
+ $pre2 = array('stays' => 'same', 'gets' => 'replaced');
+ $result = array('stays' => 'same', 'gets' => 'newval', 'newkey' => 'added');
+
+ // Mock Config and set previous value
+ $config = $this->getMock('Xylophone\core\Config', null, array(), '', false);
+ $config[$key2] = $pre2;
+
+ // Call setItem() and confirm results
+ $config->setItem($key1, $val1);
+ $this->assertArrayHasKey($key1, $config->config);
+ $this->assertEquals($val1, $config->config[$key1]);
+ $config->setItem($val2);
+ $this->assertEquals($result, $config->config[$key2]);
+ }
+
+ /**
+ * Test slashItem() fail
+ */
+ public function testSlashItemFail()
+ {
+ // Mock Config
+ $config = $this->getMock('Xylophone\core\Config', null, array(), '', false);
+
+ // Call slashItem() and confirm missing item fail
+ $this->assertNull($config->slashItem('missing'));
+ }
+
+ /**
+ * Test slashItem() with empty value
+ */
+ public function testSlashItemEmpty()
+ {
+ // Set arg
+ $key = 'blank';
+
+ // Mock Config and set item
+ $config = $this->getMock('Xylophone\core\Config', null, array(), '', false);
+ $config->config[$key] = ' ';
+
+ // Call slashItem() and confirm result
+ $this->assertEmpty($config->slashItem($key));
+ }
+
+ /**
+ * Test slashItem()
+ */
+ public function testSlashItem()
+ {
+ // Set args
+ $key = 'path';
+ $val = '/fake/dir';
+
+ // Mock Config and set item
+ $config = $this->getMock('Xylophone\core\Config', null, array(), '', false);
+ $config->config[$key] = $val;
+
+ // Call slashItem() and confirm results
+ $this->assertEquals($val.'/', $config->slashItem($key));
+ $config->config[$key] = $val.'/';
+ $this->assertEquals($val.'/', $config->slashItem($key));
+ }
+
+ /**
+ * Test siteUrl()
+ */
+ public function testSiteUrl()
+ {
+ // Set up args
+ $base = 'http://testserver.net/testapp/';
+ $index = 'main';
+
+ // Mock Config and set up calls
+ $config = $this->getMock('Xylophone\core\Config', array('slashitem', 'item'), array(), '', false);
+ $config->expects($this->once())->method('slashItem')->with($this->equalTo('base_url'))->
+ will($this->returnValue($base));
+ $config->expects($this->once())->method('item')->with($this->equalTo('index_page'))->
+ will($this->returnValue($index));
+
+ // Call siteUrl() and verify result
+ $this->assertEquals($base.$index, $config->siteUrl());
+ }
+
+ /**
+ * Test siteUrl() with a URI string and a URL suffix
+ */
+ public function testSiteUrlUriSuffix()
+ {
+ // Set up args
+ $base = 'http://myserver.com/someapp/';
+ $index = 'home';
+ $uri = 'some/args';
+ $suffix = 'ctlr';
+
+ // Mock Config and set up calls
+ $config = $this->getMock('Xylophone\core\Config', array('slashitem', 'item', 'uriString'),
+ array(), '', false);
+ $config->expects($this->at(0))->method('slashItem')->with($this->equalTo('base_url'))->
+ will($this->returnValue($base));
+ $config->expects($this->at(1))->method('uriString')->with($this->equalTo($uri))->
+ will($this->returnArgument(0));
+ $config->expects($this->at(2))->method('item')->with($this->equalTo('enable_query_strings'))->
+ will($this->returnValue(false));
+ $config->expects($this->at(3))->method('slashItem')->with($this->equalTo('index_page'))->
+ will($this->returnValue($index));
+ $config->config['url_suffix'] = $suffix;
+
+ // Call siteUrl() and verify result
+ $this->assertEquals($base.$index.$uri.$suffix, $config->siteUrl($uri));
+ }
+
+ /**
+ * Test siteUrl() with a split URI string and a URL suffix
+ */
+ public function testSiteUrlSuffixUri()
+ {
+ // Set up args
+ $base = 'http://test.org/myapp/';
+ $index = 'index/';
+ $dir = 'sub';
+ $query = '?arg';
+ $uri = $dir.$query;
+ $suffix = '.php';
+
+ // Mock Config and set up calls
+ $config = $this->getMock('Xylophone\core\Config', array('slashitem', 'item', 'uriString'),
+ array(), '', false);
+ $config->expects($this->at(0))->method('slashItem')->with($this->equalTo('base_url'))->
+ will($this->returnValue($base));
+ $config->expects($this->at(1))->method('uriString')->with($this->equalTo($uri))->
+ will($this->returnArgument(0));
+ $config->expects($this->at(2))->method('item')->with($this->equalTo('enable_query_strings'))->
+ will($this->returnValue(false));
+ $config->expects($this->at(3))->method('slashItem')->with($this->equalTo('index_page'))->
+ will($this->returnValue($index));
+ $config->config['url_suffix'] = $suffix;
+
+ // Call siteUrl() and verify result
+ $this->assertEquals($base.$index.$dir.$suffix.$query, $config->siteUrl($uri));
+ }
+
+ /**
+ * Test siteUrl() with a URI string, a protocol, and query strings
+ */
+ public function testSiteUrlProtoQuery()
+ {
+ // Set up args
+ $proto1 = 'http';
+ $proto2 = 'https';
+ $base = '://testing.us/somemore/';
+ $index = 'with';
+ $uri = '?this&that';
+
+ // Mock Config and set up calls
+ $config = $this->getMock('Xylophone\core\Config', array('slashitem', 'item', 'uriString'),
+ array(), '', false);
+ $config->expects($this->at(0))->method('slashItem')->with($this->equalTo('base_url'))->
+ will($this->returnValue($proto1.$base));
+ $config->expects($this->at(1))->method('uriString')->with($this->equalTo($uri))->
+ will($this->returnArgument(0));
+ $config->expects($this->at(2))->method('item')->with($this->equalTo('enable_query_strings'))->
+ will($this->returnValue(true));
+ $config->expects($this->at(3))->method('item')->with($this->equalTo('index_page'))->
+ will($this->returnValue($index));
+
+ // Call siteUrl() and verify result
+ $this->assertEquals($proto2.$base.$index.$uri, $config->siteUrl($uri, $proto2));
+ }
+
+ /**
+ * Test baseUrl()
+ */
+ public function testBaseUrl()
+ {
+ // Set up args
+ $proto1 = 'https';
+ $proto2 = 'http';
+ $base = '://localhost/localtest/';
+ $uri = 'foo/bar';
+
+ // Mock Config and set up calls
+ $config = $this->getMock('Xylophone\core\Config', array('slashItem', 'item'), array(), '', false);
+ $config->expects($this->once())->method('slashItem')->with($this->equalTo('base_url'))->
+ will($this->returnValue($proto1.$base));
+ $config->expects($this->once())->method('item')->with($this->equalTo('enable_query_strings'))->
+ will($this->returnValue(false));
+
+ // Call baseUrl() and verify reult
+ $this->assertEquals($proto2.$base.$uri, $config->baseUrl('/'.$uri.'/', $proto2));
+ }
+
+ /**
+ * Test baseUrl() with query strings
+ */
+ public function testBaseUrlQuery()
+ {
+ // Set up args
+ $base = 'http://localhost/querytest/';
+ $key1 = 'first';
+ $val1 = 'arg';
+ $key2 = 'second';
+ $val2 = 'param';
+ $uri = array($key1 => $val1, $key2 => $val2);
+
+ // Mock Config and set up calls
+ $config = $this->getMock('Xylophone\core\Config', array('slashItem', 'item'), array(), '', false);
+ $config->expects($this->once())->method('slashItem')->with($this->equalTo('base_url'))->
+ will($this->returnValue($base));
+ $config->expects($this->once())->method('item')->with($this->equalTo('enable_query_strings'))->
+ will($this->returnValue(true));
+
+ // Call baseUrl() and verify reult
+ $this->assertEquals($base.'?'.$key1.'='.$val1.'&'.$key2.'='.$val2, $config->baseUrl($uri));
+ }
+
+ /**
+ * Test offsetExists()
+ */
+ public function testOffsetExists()
+ {
+ // Set args
+ $key = 'good';
+
+ // Mock Config and set item
+ $config = $this->getMock('Xylophone\core\Config', null, array(), '', false);
+ $config->config[$key] = true;
+
+ // Test via array access
+ $this->assertTrue(isset($config[$key]));
+ $this->assertFalse(isset($config['bad']));
+ }
+
+ /**
+ * Test offsetGet()
+ */
+ public function testOffsetGet()
+ {
+ // Set args
+ $key = 'real';
+ $val = 'value';
+
+ // Mock Config and set item
+ $config = $this->getMock('Xylophone\core\Config', null, array(), '', false);
+ $config->config[$key] = $val;
+
+ // Test via array access
+ $this->assertEquals($val, $config[$key]);
+ $this->assertNull($config['figment']);
+ }
+
+ /**
+ * Test offsetSet()
+ */
+ public function testOffsetSet()
+ {
+ // Set args
+ $number = 0;
+ $key = 'foo';
+ $val = 'bar';
+
+ // Mock Config
+ $config = $this->getMock('Xylophone\core\Config', null, array(), '', false);
+
+ // Test via array access
+ $config[$number] = 'nothing';
+ $this->assertArrayNotHasKey($number, $config->config);
+ $config[$key] = $val;
+ $this->assertArrayHasKey($key, $config->config);
+ $this->assertEquals($val, $config->config[$key]);
+ }
+
+ /**
+ * Test offsetUnset()
+ */
+ public function testOffsetUnset()
+ {
+ // Set arg
+ $key = 'nowyouseeme';
+
+ // Mock Config and set item
+ $config = $this->getMock('Xylophone\core\Config', null, array(), '', false);
+ $config->config[$key] = 'nowyoudont';
+
+ // Test via array access
+ unset($config[$key]);
+ $this->assertArrayNotHasKey($key, $config->config);
+ }
+}
+
View
915 tests/Xylophone/core/XylophoneTest.php
458 additions, 457 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
233 tests/codeigniter/core/Config_test.php
@@ -1,233 +0,0 @@
-<?php
-
-class Config_test extends CI_TestCase {
-
- public function set_up()
- {
- $cls =& $this->ci_core_class('cfg');
-
- // set predictable config values
- $this->cfg = array(
- 'index_page' => 'index.php',
- 'base_url' => 'http://example.com/',
- 'subclass_prefix' => 'MY_'
- );
- $this->ci_set_config($this->cfg);
-
- $this->config = new $cls;
- }
-
- // --------------------------------------------------------------------
-
- public function test_item()
- {
- $this->assertEquals($this->cfg['base_url'], $this->config->item('base_url'));
-
- // Bad Config value
- $this->assertNull($this->config->item('no_good_item'));
-
- // Index
- $this->assertNull($this->config->item('no_good_item', 'bad_index'));
- $this->assertNull($this->config->item('no_good_item', 'default'));
- }
-
- // --------------------------------------------------------------------
-
- public function test_set_item()
- {
- $this->assertNull($this->config->item('not_yet_set'));
-
- $this->config->set_item('not_yet_set', 'is set');
- $this->assertEquals('is set', $this->config->item('not_yet_set'));
- }
-
- // --------------------------------------------------------------------
-
- public function test_slash_item()
- {
- // Bad Config value
- $this->assertNull($this->config->slash_item('no_good_item'));
-
- $this->assertEquals($this->cfg['base_url'], $this->config->slash_item('base_url'));
- $this->assertEquals($this->cfg['subclass_prefix'].'/', $this->config->slash_item('subclass_prefix'));
- }
-
- // --------------------------------------------------------------------
-
- public function test_base_url()
- {
- // Test regular base URL
- $base_url = $this->cfg['base_url'];
- $this->assertEquals($base_url, $this->config->base_url());
-
- // Test with URI
- $uri = 'test';
- $this->assertEquals($base_url.$uri, $this->config->base_url($uri));
-
- // Clear base_url
- $this->ci_set_config('base_url', '');
-
- // Rerun constructor
- $cls =& $this->ci_core_class('cfg');
- $this->config = new $cls;
-
- // Test default base
- $this->assertEquals('http://localhost/', $this->config->base_url());
-
- // Capture server vars
- $old_host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : NULL;
- $old_script = isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] : NULL;
- $old_https = isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : NULL;
-
- // Setup server vars for detection
- $host = 'test.com';
- $path = '/path/';
- $script = 'base_test.php';
- $_SERVER['HTTP_HOST'] = $host;
- $_SERVER['SCRIPT_NAME'] = $path.$script;
-
- // Rerun constructor
- $this->config = new $cls;
-
- // Test plain detected
- $this->assertEquals('http://'.$host.$path, $this->config->base_url());
-
- // Rerun constructor
- $_SERVER['HTTPS'] = 'on';
- $this->config = new $cls;
-
- // Test secure detected
- $this->assertEquals('https://'.$host.$path, $this->config->base_url());
-
- // Restore server vars
- if ($old_host === NULL) unset($_SERVER['HTTP_HOST']);
- else $_SERVER['HTTP_HOST'] = $old_host;
- if ($old_script === NULL) unset($_SERVER['SCRIPT_NAME']);
- else $_SERVER['SCRIPT_NAME'] = $old_script;
- if ($old_https === NULL) unset($_SERVER['HTTPS']);
- else $_SERVER['HTTPS'] = $old_https;
- }
-
- // --------------------------------------------------------------------
-
- public function test_site_url()
- {
- $base_url = $this->cfg['base_url'];
- $index_page = $this->cfg['index_page'];
- $this->assertEquals($base_url.$index_page, $this->config->site_url());
-
- $old_base = $this->config->item('base_url');
- $this->config->set_item('base_url', '');
-
- $q_string = $this->config->item('enable_query_strings');
- $this->config->set_item('enable_query_strings', FALSE);
-
- $uri = 'test';
- $uri2 = '1';
- $this->assertEquals($index_page.'/'.$uri, $this->config->site_url($uri));
- $this->assertEquals($index_page.'/'.$uri.'/'.$uri2, $this->config->site_url(array($uri, $uri2)));
-
- $suffix = 'ing';
- $this->config->set_item('url_suffix', $suffix);
-
- $arg = 'pass';
- $this->assertEquals($index_page.'/'.$uri.$suffix, $this->config->site_url($uri));
- $this->assertEquals($index_page.'/'.$uri.$suffix.'?'.$arg, $this->config->site_url($uri.'?'.$arg));
-
- $this->config->set_item('url_suffix', FALSE);
- $this->config->set_item('enable_query_strings', TRUE);
-
- $this->assertEquals($index_page.'?'.$uri, $this->config->site_url($uri));
- $this->assertEquals($index_page.'?0='.$uri.'&1='.$uri2, $this->config->site_url(array($uri, $uri2)));
-
- $this->config->set_item('base_url', $old_base);
-
- $this->assertEquals($base_url.$index_page.'?'.$uri, $this->config->site_url($uri));
-
- // back to home base
- $this->config->set_item('enable_query_strings', $q_string);
- }
-
- // --------------------------------------------------------------------
-
- public function test_system_url()
- {
- $this->assertEquals($this->cfg['base_url'].'system/', $this->config->system_url());
- }
-
- // --------------------------------------------------------------------
-
- public function test_load()
- {
- // Test regular load
- $file = 'test.php';
- $key = 'testconfig';
- $val = 'my_value';
- $cfg = array($key => $val);
- $this->ci_vfs_create($file, '<?php $config = '.var_export($cfg, TRUE).';', $this->ci_app_root, 'config');
- $this->assertTrue($this->config->load($file));
- $this->assertEquals($val, $this->config->item($key));
-
- // Test reload - value should not change
- $val2 = 'new_value';
- $cfg = array($key => $val2);
- $this->ci_vfs_create($file, '<?php $config = '.var_export($cfg, TRUE).';', $this->ci_app_root, 'config');
- $this->assertTrue($this->config->load($file));
- $this->assertEquals($val, $this->config->item($key));
-
- // Test section load
- $file = 'secttest';
- $cfg = array(
- 'one' => 'prime',
- 'two' => 2,
- 'three' => true
- );
- $this->ci_vfs_create($file.'.php', '<?php $config = '.var_export($cfg, TRUE).';', $this->ci_app_root, 'config');
- $this->assertTrue($this->config->load($file, TRUE));
- $this->assertEquals($cfg, $this->config->item($file));
-
- // Test section merge
- $cfg2 = array(
- 'three' => 'tres',
- 'number' => 42,
- 'letter' => 'Z'
- );
- $pkg_dir = 'package';
- $this->ci_vfs_create($file.'.php', '<?php $config = '.var_export($cfg2, TRUE).';', $this->ci_app_root,
- array($pkg_dir, 'config'));
- $this->config->_config_paths[] = $this->ci_vfs_path($pkg_dir.'/', APPPATH);
- $this->assertTrue($this->config->load($file, TRUE));
- $this->assertEquals(array_merge($cfg, $cfg2), $this->config->item($file));
- array_pop($this->config->_config_paths);
-
- // Test graceful fail of invalid file
- $file = 'badfile';
- $this->ci_vfs_create($file, '', $this->ci_app_root, 'config');
- $this->assertFalse($this->config->load($file, FALSE, TRUE));
-
- // Test regular fail of invalid file
- $this->setExpectedException(
- 'RuntimeException',
- 'CI Error: Your '.$this->ci_vfs_path('config/'.$file.'.php', APPPATH).
- ' file does not appear to contain a valid configuration array.'
- );
- $this->assertNull($this->config->load($file));
- }
-
- // --------------------------------------------------------------------
-
- public function test_load_nonexistent()
- {
- // Test graceful fail of nonexistent file
- $this->assertFalse($this->config->load('not_config_file', FALSE, TRUE));
-
- // Test regular fail
- $file = 'absentia';
- $this->setExpectedException(
- 'RuntimeException',
- 'CI Error: The configuration file '.$file.'.php does not exist.'
- );
- $this->assertNull($this->config->load($file));
- }
-
-}
View
9 tests/travis/pdo/pgsql.phpunit.xml → tests/travis/core/phpunit.xml
@@ -9,17 +9,14 @@
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false">
- <php>
- <const name="DB_DRIVER" value="pdo/pgsql"/>
- </php>
<testsuites>
- <testsuite name="Xylophone Test Suite">
+ <testsuite name="Xylophone Core Test Suite">
<directory suffix="Test.php">../../Xylophone/core</directory>
</testsuite>
</testsuites>
<filter>
- <whitelist addUncoveredFilesFromWhitelist="false">
- <directory suffix=".php">../../../system</directory>
+ <whitelist processUncoveredFilesFromWhitelist="true">
+ <directory suffix=".php">../../../system/core</directory>
</whitelist>
</filter>
</phpunit>
View
10 tests/travis/mysql.phpunit.xml → tests/travis/database/mysql/phpunit.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
- bootstrap="../Bootstrap.php"
+ bootstrap="../../../Bootstrap.php"
colors="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
@@ -13,13 +13,13 @@
<const name="DB_DRIVER" value="mysql"/>
</php>
<testsuites>
- <testsuite name="Xylophone Test Suite">
- <directory suffix="Test.php">../Xylophone/core</directory>
+ <testsuite name="Xylophone Database Test Suite">
+ <directory suffix="Test.php">../../../Xylophone/database</directory>
</testsuite>
</testsuites>
<filter>
- <whitelist addUncoveredFilesFromWhitelist="false">
- <directory suffix=".php">../../system</directory>
+ <whitelist processUncoveredFilesFromWhitelist="false">
+ <directory suffix=".php">../../../../system/libraries/Database</directory>
</whitelist>
</filter>
</phpunit>
View
10 tests/travis/mysqli.phpunit.xml → tests/travis/database/mysqli/phpunit.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
- bootstrap="../Bootstrap.php"
+ bootstrap="../../../Bootstrap.php"
colors="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
@@ -13,13 +13,13 @@
<const name="DB_DRIVER" value="mysqli"/>
</php>
<testsuites>
- <testsuite name="Xylophone Test Suite">
- <directory suffix="Test.php">../Xylophone/core</directory>
+ <testsuite name="Xylophone Database Test Suite">
+ <directory suffix="Test.php">../../../Xylophone/database</directory>
</testsuite>
</testsuites>
<filter>
- <whitelist addUncoveredFilesFromWhitelist="false">
- <directory suffix=".php">../../system</directory>
+ <whitelist processUncoveredFilesFromWhitelist="false">
+ <directory suffix=".php">../../../../system/libraries/Database</directory>
</whitelist>
</filter>
</phpunit>
View
10 tests/travis/pdo/mysql.phpunit.xml → tests/travis/database/pdo/mysql/phpunit.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
- bootstrap="../../Bootstrap.php"
+ bootstrap="../../../../Bootstrap.php"
colors="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
@@ -13,13 +13,13 @@
<const name="DB_DRIVER" value="pdo/mysql"/>
</php>
<testsuites>
- <testsuite name="Xylophone Test Suite">
- <directory suffix="Test.php">../../Xylophone/core</directory>
+ <testsuite name="Xylophone Database Test Suite">
+ <directory suffix="Test.php">../../../../Xylophone/database</directory>
</testsuite>
</testsuites>
<filter>
- <whitelist addUncoveredFilesFromWhitelist="false">
- <directory suffix=".php">../../../system</directory>
+ <whitelist processUncoveredFilesFromWhitelist="false">
+ <directory suffix=".php">../../../../../system/libraries/Database</directory>
</whitelist>
</filter>
</phpunit>
View
25 tests/travis/database/pdo/pgsql/phpunit.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<phpunit
+ bootstrap="../../../../Bootstrap.php"
+ colors="true"
+ convertNoticesToExceptions="true"
+ convertWarningsToExceptions="true"
+ stopOnError="false"
+ stopOnFailure="false"
+ stopOnIncomplete="false"
+ stopOnSkipped="false">
+ <php>
+ <const name="DB_DRIVER" value="pdo/pgsql"/>
+ </php>
+ <testsuites>
+ <testsuite name="Xylophone Database Test Suite">
+ <directory suffix="Test.php">../../../../Xylophone/database</directory>
+ </testsuite>
+ </testsuites>
+ <filter>
+ <whitelist processUncoveredFilesFromWhitelist="false">
+ <directory suffix=".php">../../../../../system/libraries/Database</directory>
+ </whitelist>
+ </filter>
+</phpunit>
View
10 tests/travis/pdo/sqlite.phpunit.xml → tests/travis/database/pdo/sqlite/phpunit.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
- bootstrap="../../Bootstrap.php"
+ bootstrap="../../../../Bootstrap.php"
colors="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
@@ -13,13 +13,13 @@
<const name="DB_DRIVER" value="pdo/sqlite"/>
</php>
<testsuites>
- <testsuite name="Xylophone Test Suite">
- <directory suffix="Test.php">../../Xylophone/core</directory>
+ <testsuite name="Xylophone Database Test Suite">
+ <directory suffix="Test.php">../../../../Xylophone/database</directory>
</testsuite>
</testsuites>
<filter>
- <whitelist addUncoveredFilesFromWhitelist="false">
- <directory suffix=".php">../../../system</directory>
+ <whitelist processUncoveredFilesFromWhitelist="false">
+ <directory suffix=".php">../../../../../system/libraries/Database</directory>
</whitelist>
</filter>
</phpunit>
View
10 tests/travis/pgsql.phpunit.xml → tests/travis/database/pgsql/phpunit.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
- bootstrap="../Bootstrap.php"
+ bootstrap="../../../Bootstrap.php"
colors="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
@@ -13,13 +13,13 @@
<const name="DB_DRIVER" value="pgsql"/>
</php>
<testsuites>
- <testsuite name="Xylophone Test Suite">
- <directory suffix="Test.php">../Xylophone/core</directory>
+ <testsuite name="Xylophone Database Test Suite">
+ <directory suffix="Test.php">../../../Xylophone/database</directory>
</testsuite>
</testsuites>
<filter>
- <whitelist addUncoveredFilesFromWhitelist="false">
- <directory suffix=".php">../../system</directory>
+ <whitelist processUncoveredFilesFromWhitelist="false">
+ <directory suffix=".php">../../../../system/libraries/Database</directory>
</whitelist>
</filter>
</phpunit>
View