2010-12-03 04:06:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* PhpConfigReaderTest
|
|
|
|
*
|
|
|
|
* PHP 5
|
|
|
|
*
|
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
2012-03-13 02:46:46 +00:00
|
|
|
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-12-03 04:06:08 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice
|
|
|
|
*
|
2012-03-13 02:46:46 +00:00
|
|
|
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-12-03 04:06:08 +00:00
|
|
|
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Configure
|
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 {
|
2012-03-11 03:30:56 +00:00
|
|
|
|
2010-12-03 04:06:08 +00:00
|
|
|
/**
|
|
|
|
* setup
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function setUp() {
|
2010-12-03 04:06:08 +00:00
|
|
|
parent::setUp();
|
2012-03-11 03:30:56 +00:00
|
|
|
$this->path = CAKE . 'Test' . DS . 'test_app' . DS . 'Config' . DS;
|
2010-12-03 04:06:08 +00:00
|
|
|
}
|
2011-12-06 20:52:48 +00:00
|
|
|
|
2010-12-03 04:06:08 +00:00
|
|
|
/**
|
|
|
|
* test reading files
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testRead() {
|
2010-12-03 04:06:08 +00:00
|
|
|
$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
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testReadWithNonExistantFile() {
|
2010-12-03 04:06:08 +00:00
|
|
|
$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
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testReadEmptyFile() {
|
2010-12-03 04:22:26 +00:00
|
|
|
$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
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testReadWithDots() {
|
2010-12-04 05:58:02 +00:00
|
|
|
$reader = new PhpReader($this->path);
|
|
|
|
$reader->read('../empty');
|
|
|
|
}
|
|
|
|
|
2010-12-03 04:14:26 +00:00
|
|
|
/**
|
|
|
|
* test reading from plugins
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testReadPluginValue() {
|
2010-12-03 04:14:26 +00:00
|
|
|
App::build(array(
|
2012-02-18 12:31:29 +00:00
|
|
|
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
2012-02-18 12:04:54 +00:00
|
|
|
), App::RESET);
|
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
|
|
|
}
|