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>
|
2011-05-29 21:31:39 +00:00
|
|
|
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-11-29 02:11:18 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice
|
|
|
|
*
|
2011-05-29 21:31:39 +00:00
|
|
|
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-11-29 02:11:18 +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-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
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function setup() {
|
2010-11-28 17:54:32 +00:00
|
|
|
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
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public 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
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public 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
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testReadingValuesWithDots() {
|
2010-12-04 17:56:37 +00:00
|
|
|
$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
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testBooleanReading() {
|
2010-12-04 17:56:37 +00:00
|
|
|
$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
|
|
|
}
|