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
|
|
|
|
*
|
2012-04-27 02:49:18 +00:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
2012-03-13 02:46:07 +00:00
|
|
|
* Copyright 2005-2012, 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
|
|
|
|
*
|
2012-03-13 02:46:07 +00:00
|
|
|
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2012-04-27 02:49:18 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/development/testing.html 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
|
|
|
|
*/
|
2011-10-10 21:18:48 +00:00
|
|
|
public $file;
|
2010-11-28 17:54:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* setup
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-12-04 21:27:51 +00:00
|
|
|
public function setUp() {
|
|
|
|
parent::setUp();
|
2012-03-11 03:30:56 +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
|
|
|
/**
|
2012-02-23 23:29:53 +00:00
|
|
|
* test construct
|
2010-11-28 17:54:32 +00:00
|
|
|
*
|
|
|
|
* @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
|
|
|
|
);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals($expected, $config);
|
2011-01-23 21:26:13 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|