2010-11-28 17:54:32 +00:00
|
|
|
<?php
|
2010-11-29 02:11:18 +00:00
|
|
|
/**
|
2010-12-04 17:15:47 +00:00
|
|
|
* IniReaderTest
|
2010-11-29 02:11:18 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.cases
|
|
|
|
* @since CakePHP(tm) v 2.0
|
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
|
|
|
*/
|
2010-12-04 17:15:47 +00:00
|
|
|
App::import('Core', 'config/IniReader');
|
2010-11-28 17:54:32 +00:00
|
|
|
|
2010-12-04 17:15:47 +00:00
|
|
|
class IniReaderTest extends CakeTestCase {
|
2010-11-28 17:54:32 +00:00
|
|
|
|
2010-11-29 00:58:59 +00:00
|
|
|
/**
|
|
|
|
* The test file that will be read.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2010-11-28 17:54:32 +00:00
|
|
|
var $file;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* setup
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function setup() {
|
|
|
|
parent::setup();
|
2010-12-04 17:15:47 +00:00
|
|
|
$this->path = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'config'. DS;
|
2010-11-28 17:54:32 +00:00
|
|
|
}
|
2010-11-29 00:58:59 +00:00
|
|
|
|
2010-11-28 17:54:32 +00:00
|
|
|
/**
|
|
|
|
* test constrction
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testConstruct() {
|
2010-12-04 17:15:47 +00:00
|
|
|
$reader = new IniReader($this->path);
|
|
|
|
$config = $reader->read('acl.ini.php');
|
2010-11-29 00:58:59 +00:00
|
|
|
|
|
|
|
$this->assertTrue(isset($config['admin']));
|
|
|
|
$this->assertTrue(isset($config['paul']['groups']));
|
|
|
|
$this->assertEquals('ads', $config['admin']['deny']);
|
2010-11-28 17:54:32 +00:00
|
|
|
}
|
2010-11-29 01:27:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* no other sections should exist.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testReadingOnlyOneSection() {
|
2010-12-04 17:15:47 +00:00
|
|
|
$reader = new IniReader($this->path, 'admin');
|
|
|
|
$config = $reader->read('acl.ini.php');
|
2010-11-29 01:27:45 +00:00
|
|
|
|
|
|
|
$this->assertTrue(isset($config['groups']));
|
|
|
|
$this->assertEquals('administrators', $config['groups']);
|
|
|
|
}
|
|
|
|
|
2010-12-04 17:56:37 +00:00
|
|
|
/**
|
|
|
|
* test that names with .'s get exploded into arrays.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testReadingValuesWithDots() {
|
|
|
|
$reader = new IniReader($this->path);
|
|
|
|
$config = $reader->read('nested.ini');
|
|
|
|
|
|
|
|
$this->assertTrue(isset($config['database']['db']['username']));
|
|
|
|
$this->assertEquals('mark', $config['database']['db']['username']);
|
|
|
|
$this->assertEquals(3, $config['nesting']['one']['two']['three']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test boolean reading
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testBooleanReading() {
|
|
|
|
$reader = new IniReader($this->path);
|
|
|
|
$config = $reader->read('nested.ini');
|
2010-12-04 17:58:02 +00:00
|
|
|
|
2010-12-04 17:56:37 +00:00
|
|
|
$this->assertTrue($config['bools']['test_on']);
|
2010-12-04 17:58:02 +00:00
|
|
|
$this->assertFalse($config['bools']['test_off']);
|
|
|
|
|
2010-12-04 17:56:37 +00:00
|
|
|
$this->assertTrue($config['bools']['test_yes']);
|
|
|
|
$this->assertFalse($config['bools']['test_no']);
|
2010-12-04 17:58:02 +00:00
|
|
|
|
|
|
|
$this->assertTrue($config['bools']['test_true']);
|
|
|
|
$this->assertFalse($config['bools']['test_false']);
|
|
|
|
|
|
|
|
$this->assertFalse($config['bools']['test_null']);
|
2010-12-04 17:56:37 +00:00
|
|
|
}
|
2010-11-28 17:54:32 +00:00
|
|
|
}
|