Merge pull request #772 from bar/master-fix-phpreader

The actual config file must always have .php extension.
This commit is contained in:
Mark Story 2012-08-16 11:00:27 -07:00
commit 08e4362d40
3 changed files with 31 additions and 12 deletions

View file

@ -66,22 +66,21 @@ class PhpReader implements ConfigReaderInterface {
$key = substr($key, 0, -4); $key = substr($key, 0, -4);
} }
list($plugin, $key) = pluginSplit($key); list($plugin, $key) = pluginSplit($key);
$key .= '.php';
if ($plugin) { if ($plugin) {
$file = App::pluginPath($plugin) . 'Config' . DS . $key; $file = App::pluginPath($plugin) . 'Config' . DS . $key;
} else { } else {
$file = $this->_path . $key; $file = $this->_path . $key;
} }
$file .= '.php';
if (!is_file($file)) { if (!is_file($file)) {
if (!is_file(substr($file, 0, -4))) { throw new ConfigureException(__d('cake_dev', 'Could not load configuration file: %s', $file));
throw new ConfigureException(__d('cake_dev', 'Could not load configuration files: %s or %s', $file, substr($file, 0, -4)));
}
} }
include $file; include $file;
if (!isset($config)) { if (!isset($config)) {
throw new ConfigureException( throw new ConfigureException(
sprintf(__d('cake_dev', 'No variable $config found in %s.php'), $file) sprintf(__d('cake_dev', 'No variable $config found in %s'), $file)
); );
} }
return $config; return $config;

View file

@ -41,7 +41,7 @@ class PhpReaderTest extends CakeTestCase {
); );
/** /**
* setup * Setup.
* *
* @return void * @return void
*/ */
@ -51,7 +51,7 @@ class PhpReaderTest extends CakeTestCase {
} }
/** /**
* test reading files * Test reading files.
* *
* @return void * @return void
*/ */
@ -65,21 +65,32 @@ class PhpReaderTest extends CakeTestCase {
$this->assertEquals('value', $values['Read']); $this->assertEquals('value', $values['Read']);
} }
/**
* Test an exception is thrown by reading files that exist without .php extension.
*
* @expectedException ConfigureException
* @return void
*/
public function testReadWithExistentFileWithoutExtension() {
$reader = new PhpReader($this->path);
$reader->read('no_php_extension');
}
/** /**
* Test an exception is thrown by reading files that don't exist. * Test an exception is thrown by reading files that don't exist.
* *
* @expectedException ConfigureException * @expectedException ConfigureException
* @return void * @return void
*/ */
public function testReadWithNonExistantFile() { public function testReadWithNonExistentFile() {
$reader = new PhpReader($this->path); $reader = new PhpReader($this->path);
$reader->read('fake_values'); $reader->read('fake_values');
} }
/** /**
* test reading an empty file. * Test reading an empty file.
* *
* @expectedException RuntimeException * @expectedException ConfigureException
* @return void * @return void
*/ */
public function testReadEmptyFile() { public function testReadEmptyFile() {
@ -88,7 +99,7 @@ class PhpReaderTest extends CakeTestCase {
} }
/** /**
* test reading keys with ../ doesn't work * Test reading keys with ../ doesn't work.
* *
* @expectedException ConfigureException * @expectedException ConfigureException
* @return void * @return void
@ -99,7 +110,7 @@ class PhpReaderTest extends CakeTestCase {
} }
/** /**
* test reading from plugins * Test reading from plugins.
* *
* @return void * @return void
*/ */

View file

@ -0,0 +1,9 @@
<?php
// Test file for testing config file without .php extension.
$config = array(
'Deep' => array(
'Third' => array(
'ThirdDeepest' => 'buried3'
)
)
);