|
|
@@ -57,7 +57,7 @@ class IniReaderTest extends CakeTestCase {
|
|
|
*/
|
|
|
public function testConstruct() {
|
|
|
$reader = new IniReader($this->path);
|
|
|
- $config = $reader->read('acl.ini.php');
|
|
|
+ $config = $reader->read('acl.ini');
|
|
|
|
|
|
$this->assertTrue(isset($config['admin']));
|
|
|
$this->assertTrue(isset($config['paul']['groups']));
|
|
|
@@ -65,24 +65,52 @@ class IniReaderTest extends CakeTestCase {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * no other sections should exist.
|
|
|
+ * Test reading files.
|
|
|
*
|
|
|
* @return void
|
|
|
*/
|
|
|
- public function testReadingOnlyOneSection() {
|
|
|
+ public function testRead() {
|
|
|
+ $reader = new IniReader($this->path);
|
|
|
+ $config = $reader->read('nested');
|
|
|
+ $this->assertTrue($config['bools']['test_on']);
|
|
|
+
|
|
|
+ $config = $reader->read('nested.ini');
|
|
|
+ $this->assertTrue($config['bools']['test_on']);
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
+ * No other sections should exist.
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testReadOnlyOneSection() {
|
|
|
$reader = new IniReader($this->path, 'admin');
|
|
|
- $config = $reader->read('acl.ini.php');
|
|
|
+ $config = $reader->read('acl.ini');
|
|
|
|
|
|
$this->assertTrue(isset($config['groups']));
|
|
|
$this->assertEquals('administrators', $config['groups']);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * test without section
|
|
|
+ * Test reading acl.ini.php.
|
|
|
*
|
|
|
* @return void
|
|
|
*/
|
|
|
- public function testReadingWithoutSection() {
|
|
|
+ public function testReadSpecialAclIniPhp() {
|
|
|
+ $reader = new IniReader($this->path);
|
|
|
+ $config = $reader->read('acl.ini.php');
|
|
|
+
|
|
|
+ $this->assertTrue(isset($config['admin']));
|
|
|
+ $this->assertTrue(isset($config['paul']['groups']));
|
|
|
+ $this->assertEquals('ads', $config['admin']['deny']);
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
+ * Test without section.
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testReadWithoutSection() {
|
|
|
$reader = new IniReader($this->path);
|
|
|
$config = $reader->read('no_section.ini');
|
|
|
|
|
|
@@ -94,11 +122,11 @@ class IniReaderTest extends CakeTestCase {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * test that names with .'s get exploded into arrays.
|
|
|
+ * Test that names with .'s get exploded into arrays.
|
|
|
*
|
|
|
* @return void
|
|
|
*/
|
|
|
- public function testReadingValuesWithDots() {
|
|
|
+ public function testReadValuesWithDots() {
|
|
|
$reader = new IniReader($this->path);
|
|
|
$config = $reader->read('nested.ini');
|
|
|
|
|
|
@@ -110,7 +138,7 @@ class IniReaderTest extends CakeTestCase {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * test boolean reading
|
|
|
+ * Test boolean reading.
|
|
|
*
|
|
|
* @return void
|
|
|
*/
|
|
|
@@ -131,18 +159,93 @@ class IniReaderTest extends CakeTestCase {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * test read file without extension
|
|
|
+ * Test an exception is thrown by reading files that exist without .ini extension.
|
|
|
*
|
|
|
+ * @expectedException ConfigureException
|
|
|
* @return void
|
|
|
*/
|
|
|
- public function testReadingWithoutExtension() {
|
|
|
+ public function testReadWithExistentFileWithoutExtension() {
|
|
|
$reader = new IniReader($this->path);
|
|
|
- $config = $reader->read('nested');
|
|
|
- $this->assertTrue($config['bools']['test_on']);
|
|
|
+ $reader->read('no_ini_extension');
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
+ * Test an exception is thrown by reading files that don't exist.
|
|
|
+ *
|
|
|
+ * @expectedException ConfigureException
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testReadWithNonExistentFile() {
|
|
|
+ $reader = new IniReader($this->path);
|
|
|
+ $reader->read('fake_values');
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
+ * Test reading an empty file.
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testReadEmptyFile() {
|
|
|
+ $reader = new IniReader($this->path);
|
|
|
+ $config = $reader->read('empty');
|
|
|
+ $this->assertEquals(array(), $config);
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
+ * Test reading keys with ../ doesn't work.
|
|
|
+ *
|
|
|
+ * @expectedException ConfigureException
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testReadWithDots() {
|
|
|
+ $reader = new IniReader($this->path);
|
|
|
+ $reader->read('../empty');
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
+ * Test reading from plugins.
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testReadPluginValue() {
|
|
|
+ App::build(array(
|
|
|
+ 'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
|
|
+ ), App::RESET);
|
|
|
+ CakePlugin::load('TestPlugin');
|
|
|
+ $reader = new IniReader($this->path);
|
|
|
+ $result = $reader->read('TestPlugin.nested');
|
|
|
+
|
|
|
+ $this->assertTrue(isset($result['database']['db']['username']));
|
|
|
+ $this->assertEquals('bar', $result['database']['db']['username']);
|
|
|
+ $this->assertFalse(isset($result['database.db.username']));
|
|
|
+ $this->assertFalse(isset($result['database']['db.username']));
|
|
|
+
|
|
|
+ $result = $reader->read('TestPlugin.nested.ini');
|
|
|
+ $this->assertEquals('foo', $result['database']['db']['password']);
|
|
|
+ CakePlugin::unload();
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
+ * Test reading acl.ini.php from plugins.
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testReadPluginSpecialAclIniPhpValue() {
|
|
|
+ App::build(array(
|
|
|
+ 'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
|
|
+ ), App::RESET);
|
|
|
+ CakePlugin::load('TestPlugin');
|
|
|
+ $reader = new IniReader($this->path);
|
|
|
+ $result = $reader->read('TestPlugin.acl.ini.php');
|
|
|
+
|
|
|
+ $this->assertTrue(isset($result['admin']));
|
|
|
+ $this->assertTrue(isset($result['paul']['groups']));
|
|
|
+ $this->assertEquals('ads', $result['admin']['deny']);
|
|
|
+ CakePlugin::unload();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * test dump method.
|
|
|
+ * Test dump method.
|
|
|
*
|
|
|
* @return void
|
|
|
*/
|