2010-12-03 04:06:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* PhpConfigReaderTest
|
|
|
|
*
|
|
|
|
* PHP 5
|
|
|
|
*
|
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
|
|
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice
|
|
|
|
*
|
|
|
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
|
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases
|
2010-12-03 04:06:08 +00:00
|
|
|
* @since CakePHP(tm) v 2.0
|
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
|
|
|
*/
|
2010-12-09 05:13:11 +00:00
|
|
|
App::uses('PhpReader', 'Configure');
|
2010-12-03 04:06:08 +00:00
|
|
|
|
|
|
|
class PhpReaderTest extends CakeTestCase {
|
|
|
|
/**
|
|
|
|
* setup
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function setUp() {
|
|
|
|
parent::setUp();
|
2011-04-17 10:35:21 +00:00
|
|
|
$this->path = CAKE . 'Test' . DS . 'test_app' . DS . 'Config'. DS;
|
2010-12-03 04:06:08 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* test reading files
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testRead() {
|
|
|
|
$reader = new PhpReader($this->path);
|
|
|
|
$values = $reader->read('var_test');
|
|
|
|
$this->assertEquals('value', $values['Read']);
|
2010-12-03 04:22:26 +00:00
|
|
|
$this->assertEquals('buried', $values['Deep']['Deeper']['Deepest']);
|
2011-01-23 22:27:46 +00:00
|
|
|
|
|
|
|
$values = $reader->read('var_test.php');
|
|
|
|
$this->assertEquals('value', $values['Read']);
|
2010-12-03 04:06:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test an exception is thrown by reading files that don't exist.
|
|
|
|
*
|
2010-12-12 00:01:07 +00:00
|
|
|
* @expectedException ConfigureException
|
2010-12-03 04:06:08 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testReadWithNonExistantFile() {
|
|
|
|
$reader = new PhpReader($this->path);
|
|
|
|
$reader->read('fake_values');
|
|
|
|
}
|
2010-12-03 04:14:26 +00:00
|
|
|
|
2010-12-03 04:22:26 +00:00
|
|
|
/**
|
|
|
|
* test reading an empty file.
|
|
|
|
*
|
|
|
|
* @expectedException RuntimeException
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testReadEmptyFile() {
|
|
|
|
$reader = new PhpReader($this->path);
|
|
|
|
$reader->read('empty');
|
|
|
|
}
|
|
|
|
|
2010-12-04 05:58:02 +00:00
|
|
|
/**
|
|
|
|
* test reading keys with ../ doesn't work
|
|
|
|
*
|
2010-12-12 00:01:07 +00:00
|
|
|
* @expectedException ConfigureException
|
2010-12-04 05:58:02 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testReadWithDots() {
|
|
|
|
$reader = new PhpReader($this->path);
|
|
|
|
$reader->read('../empty');
|
|
|
|
}
|
|
|
|
|
2010-12-03 04:14:26 +00:00
|
|
|
/**
|
|
|
|
* test reading from plugins
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testReadPluginValue() {
|
|
|
|
App::build(array(
|
2011-04-17 10:35:21 +00:00
|
|
|
'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
2010-12-03 04:14:26 +00:00
|
|
|
), true);
|
2011-05-13 05:58:17 +00:00
|
|
|
CakePlugin::load('TestPlugin');
|
2010-12-03 04:14:26 +00:00
|
|
|
$reader = new PhpReader($this->path);
|
|
|
|
$result = $reader->read('TestPlugin.load');
|
2011-01-23 22:27:46 +00:00
|
|
|
$this->assertTrue(isset($result['plugin_load']));
|
2010-12-03 04:14:26 +00:00
|
|
|
|
2011-01-23 22:27:46 +00:00
|
|
|
$result = $reader->read('TestPlugin.load.php');
|
2010-12-03 04:14:26 +00:00
|
|
|
$this->assertTrue(isset($result['plugin_load']));
|
2011-05-13 05:58:17 +00:00
|
|
|
CakePlugin::unload();
|
2010-12-03 04:14:26 +00:00
|
|
|
}
|
2010-12-03 04:06:08 +00:00
|
|
|
}
|