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
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases
|
2010-11-29 02:11:18 +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('IniReader', 'Configure');
|
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();
|
2011-04-17 10:35:21 +00:00
|
|
|
$this->path = CAKE . 'Test' . 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']);
|
|
|
|
}
|
|
|
|
|
2011-01-23 21:26:13 +00:00
|
|
|
/**
|
|
|
|
* test without section
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testReadingWithoutSection() {
|
|
|
|
$reader = new IniReader($this->path);
|
|
|
|
$config = $reader->read('no_section.ini');
|
|
|
|
|
|
|
|
$expected = array(
|
|
|
|
'some_key' => 'some_value',
|
|
|
|
'bool_key' => true
|
|
|
|
);
|
|
|
|
$this->assertEquals($config, $expected);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2011-01-23 22:27:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* test read file without extension
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testReadingWithoutExtension() {
|
|
|
|
$reader = new IniReader($this->path);
|
|
|
|
$config = $reader->read('nested');
|
|
|
|
$this->assertTrue($config['bools']['test_on']);
|
|
|
|
}
|
2011-04-17 10:35:21 +00:00
|
|
|
}
|