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