Skip to content

Commit

Permalink
Merge remote-tracking branch 'joomla/master' into jgrid
Browse files Browse the repository at this point in the history
  • Loading branch information
chdemko committed Oct 20, 2011
2 parents 5d1253d + a34b024 commit d9d43f6
Show file tree
Hide file tree
Showing 19 changed files with 351 additions and 146 deletions.
2 changes: 1 addition & 1 deletion libraries/joomla/application/application.php
Expand Up @@ -978,7 +978,7 @@ protected function _createConfiguration($file)
{
jimport('joomla.registry.registry');

include_once $file;
JLoader::register('JConfig', $file);

// Create the JConfig object.
$config = new JConfig;
Expand Down
42 changes: 23 additions & 19 deletions libraries/joomla/application/cli.php
Expand Up @@ -334,38 +334,42 @@ public function set($key, $value = null)
* will extend this method in child classes to provide configuration data from whatever data source is relevant
* for your specific application.
*
* @param string $fileName The name of the configuration file (default is 'configuration').
* Note that .php is appended to this name
* @param string $file The path and filename of the configuration file. If not provided, configuration.php
* in JPATH_BASE will be used.
* @param string $class The class name to instantiate.
*
* @return mixed Either an array or object to be loaded into the configuration object.
* @return mixed Either an array or object to be loaded into the configuration object.
*
* @since 11.1
*/
protected function fetchConfigurationData($fileName = 'configuration')
protected function fetchConfigurationData($file = '', $class = 'JConfig')
{
// Instantiate variables.
$config = array();

if (empty($fileName))
if (empty($file) && defined('JPATH_BASE'))
{
$fileName = 'configuration';
$file = JPATH_BASE . '/configuration.php';

// Applications can choose not to have any configuration data
// by not implementing this method and not having a config file.
if (!file_exists($file))
{
$file = '';
}
}

// Handle the convention-based default case for configuration file.
if (defined('JPATH_BASE'))
if (!empty($file))
{
// Set the configuration file name and check to see if it exists.
$file = JPATH_BASE . '/' . preg_replace('#[^A-Z0-9-_.]#i', '', $fileName) . '.php';
if (is_file($file))
JLoader::register($class, $file);

if (class_exists($class))
{
$config = new $class;
}
else
{
// Import the configuration file.
include_once $file;

// Instantiate the configuration object if it exists.
if (class_exists('JConfig'))
{
$config = new JConfig;
}
throw new Exception('Configuration class does not exist.');
}
}

Expand Down
6 changes: 3 additions & 3 deletions libraries/joomla/application/cli/daemon.php
Expand Up @@ -139,7 +139,7 @@ public function __construct(JInputCli $input = null, JRegistry $config = null, J
/**
* Method to handle POSIX signals.
*
* @param integer $signal The recieved POSIX signal.
* @param integer $signal The received POSIX signal.
*
* @return void
*
Expand All @@ -158,8 +158,8 @@ public static function signal($signal)
throw new ApplicationException;
}

// Fire the onRecieveSignal event.
static::$instance->triggerEvent('onRecieveSignal', array($signal));
// Fire the onReceiveSignal event.
static::$instance->triggerEvent('onReceiveSignal', array($signal));

switch ($signal)
{
Expand Down
5 changes: 1 addition & 4 deletions libraries/joomla/application/component/controller.php
Expand Up @@ -663,7 +663,7 @@ public function display($cachable = false, $urlparams = false)
$viewName = JRequest::getCmd('view', $this->default_view);
$viewLayout = JRequest::getCmd('layout', 'default');

$view = $this->getView($viewName, $viewType, '', array('base_path' => $this->basePath));
$view = $this->getView($viewName, $viewType, '', array('base_path' => $this->basePath, 'layout' => $viewLayout));

// Get/Create the model
if ($model = $this->getModel($viewName))
Expand All @@ -672,9 +672,6 @@ public function display($cachable = false, $urlparams = false)
$view->setModel($model, true);
}

// Set the layout
$view->setLayout($viewLayout);

$view->assignRef('document', $document);

$conf = JFactory::getConfig();
Expand Down
42 changes: 23 additions & 19 deletions libraries/joomla/application/web.php
Expand Up @@ -977,38 +977,42 @@ protected function detectRequestUri()
* will extend this method in child classes to provide configuration data from whatever data source is relevant
* for your specific application.
*
* @param string $fileName The name of the configuration file (default is 'configuration').
* Note that .php is appended to this name
* @param string $file The path and filename of the configuration file. If not provided, configuration.php
* in JPATH_BASE will be used.
* @param string $class The class name to instantiate.
*
* @return mixed Either an array or object to be loaded into the configuration object.
* @return mixed Either an array or object to be loaded into the configuration object.
*
* @since 11.3
*/
protected function fetchConfigurationData($fileName = 'configuration')
protected function fetchConfigurationData($file = '', $class = 'JConfig')
{
// Instantiate variables.
$config = array();

if (empty($fileName))
if (empty($file) && defined('JPATH_BASE'))
{
$fileName = 'configuration';
$file = JPATH_BASE . '/configuration.php';

// Applications can choose not to have any configuration data
// by not implementing this method and not having a config file.
if (!file_exists($file))
{
$file = '';
}
}

// Handle the convention-based default case for configuration file.
if (defined('JPATH_BASE'))
if (!empty($file))
{
// Set the configuration file name and check to see if it exists.
$file = JPATH_BASE . '/' . preg_replace('#[^A-Z0-9-_.]#i', '', $fileName) . '.php';
if (is_file($file))
{
// Import the configuration file.
include_once $file;
JLoader::register($class, $file);

// Instantiate the configuration object if it exists.
if (class_exists('JConfig'))
{
$config = new JConfig;
}
if (class_exists($class))
{
$config = new $class;
}
else
{
throw new Exception('Configuration class does not exist.');
}
}

Expand Down
3 changes: 2 additions & 1 deletion libraries/joomla/html/html/number.php
Expand Up @@ -35,7 +35,8 @@ abstract class JHtmlNumber
*/
public static function bytes($bytes, $unit = 'auto', $precision = 2)
{
$bytes = (int) $bytes;
// No explicit casting $bytes to integer here, since it might overflow
// on 32-bit systems
$precision = (int) $precision;

if (empty($bytes))
Expand Down
63 changes: 42 additions & 21 deletions tests/suite/joomla/application/JCliTest.php
Expand Up @@ -28,24 +28,6 @@ class JCliTest extends JoomlaTestCase
*/
protected $inspector;

/**
* Data for fetchConfigurationData method.
*
* @return array
*
* @since 11.3
*/
public function getFetchConfigurationData()
{
return array(
// fileName, expectsClass, (expected result array)
'Default configuration class' => array(null, true, array('foo' => 'bar')),
'Custom file with array' => array('config.jweb-array', false, array('foo' => 'bar')),
// 'Custom file, invalid class' => array('config.JCli-wrongclass', false, array()),
'Custom file, snooping' => array('../test_application/config.jcli-snoopy', false, array()),
);
}

/**
* Setup for testing.
*
Expand Down Expand Up @@ -231,10 +213,27 @@ public function testExecute()
);
}

/**
* Data for fetchConfigurationData method.
*
* @return array
*
* @since 11.3
*/
public function getFetchConfigurationData()
{
return array(
// file, class, expectsClass, (expected result array), whether there should be an exception
'Default configuration class' => array(null, null, 'JConfig', 'ConfigEval'),
'Custom file, invalid class' => array(JPATH_BASE . '/config.JCli-wrongclass.php', 'noclass', false, array(), true),
);
}

/**
* Tests the JCli::fetchConfigurationData method.
*
* @param string $fileName The name of the configuration file.
* @param string $fileName The name of the configuration file.
* @param boolean $expectsClass The result is expected to be a class.
* @param array $expects The expected result as an array.
*
Expand All @@ -243,14 +242,36 @@ public function testExecute()
* @dataProvider getFetchConfigurationData
* @since 11.3
*/
public function testFetchConfigurationData($fileName, $expectsClass, $expects)
public function testFetchConfigurationData($file, $class, $expectsClass, $expects, $expectedException = false)
{
$config = $this->inspector->fetchConfigurationData($fileName);
if ($expectedException)
{
$this->setExpectedException('Exception');
}

if (is_null($file) && is_null($class))
{
$config = $this->inspector->fetchConfigurationData();
}
elseif (is_null($class))
{
$config = $this->inspector->fetchConfigurationData($file);
}
else
{
$config = $this->inspector->fetchConfigurationData($file, $class);
}

if ($expects == 'ConfigEval')
{
$expects = new JConfig;
$expects = (array)$expects;
}

if ($expectsClass)
{
$this->assertInstanceOf(
'JConfig',
$expectsClass,
$config,
'Checks the configuration object is the appropriate class.'
);
Expand Down
65 changes: 43 additions & 22 deletions tests/suite/joomla/application/JWebTest.php
Expand Up @@ -62,24 +62,6 @@ public function getDetectRequestUriData()
);
}

/**
* Data for fetchConfigurationData method.
*
* @return array
*
* @since 11.3
*/
public function getFetchConfigurationData()
{
return array(
// fileName, expectsClass, (expected result array)
'Default configuration class' => array(null, true, array('foo' => 'bar')),
'Custom file with array' => array('config.jweb-array', false, array('foo' => 'bar')),
// 'Custom file, invalid class' => array('config.jweb-wrongclass', false, array()),
'Custom file, snooping' => array('../test_application/config.jweb-snoopy', false, array()),
);
}

/**
* Data for fetchConfigurationData method.
*
Expand Down Expand Up @@ -742,8 +724,25 @@ public function testExecuteWithDocument()
}

/**
* Tests the JWeb::fetchConfigurationData method.
* Data for fetchConfigurationData method.
*
* @return array
*
* @since 11.3
*/
public function getFetchConfigurationData()
{
return array(
// file, class, expectsClass, (expected result array), whether there should be an exception
'Default configuration class' => array(null, null, 'JConfig', 'ConfigEval'),
'Custom file, invalid class' => array(JPATH_BASE . '/config.JCli-wrongclass.php', 'noclass', false, array(), true),
);
}

/**
* Tests the JCli::fetchConfigurationData method.
*
* @param string $fileName The name of the configuration file.
* @param string $fileName The name of the configuration file.
* @param boolean $expectsClass The result is expected to be a class.
* @param array $expects The expected result as an array.
Expand All @@ -753,14 +752,36 @@ public function testExecuteWithDocument()
* @dataProvider getFetchConfigurationData
* @since 11.3
*/
public function testFetchConfigurationData($fileName, $expectsClass, $expects)
public function testFetchConfigurationData($file, $class, $expectsClass, $expects, $expectedException = false)
{
$config = $this->inspector->fetchConfigurationData($fileName);
if ($expectedException)
{
$this->setExpectedException('Exception');
}

if (is_null($file) && is_null($class))
{
$config = $this->inspector->fetchConfigurationData();
}
elseif (is_null($class))
{
$config = $this->inspector->fetchConfigurationData($file);
}
else
{
$config = $this->inspector->fetchConfigurationData($file, $class);
}

if ($expects == 'ConfigEval')
{
$expects = new JConfig;
$expects = (array)$expects;
}

if ($expectsClass)
{
$this->assertInstanceOf(
'JConfig',
$expectsClass,
$config,
'Checks the configuration object is the appropriate class.'
);
Expand Down
4 changes: 2 additions & 2 deletions tests/suite/joomla/application/stubs/JCliInspector.php
Expand Up @@ -105,9 +105,9 @@ public function setClassProperty($name, $value)
*
* @since 11.3
*/
public function fetchConfigurationData($fileName = null)
public function fetchConfigurationData($file = '', $class = 'JConfig')
{
return parent::fetchConfigurationData($fileName);
return parent::fetchConfigurationData($file, $class);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/suite/joomla/application/stubs/JWebInspector.php
Expand Up @@ -181,9 +181,9 @@ public function doExecute()
*
* @since 11.3
*/
public function fetchConfigurationData($fileName = null)
public function fetchConfigurationData($file = '', $class = 'JConfig')
{
return parent::fetchConfigurationData($fileName);
return parent::fetchConfigurationData($file, $class);
}

/**
Expand Down

0 comments on commit d9d43f6

Please sign in to comment.