_tempName = tempnam(dirname(__FILE__) . '/temp', 'tmp'); } public function tearDown() { @unlink($this->_tempName); } public function testNoFilenameSet() { $writer = new Zend_Config_Writer_Ini(array('config' => new Zend_Config(array()))); try { $writer->write(); $this->fail('An expected Zend_Config_Exception has not been raised'); } catch (Zend_Config_Exception $expected) { $this->assertContains('No filename was set', $expected->getMessage()); } } public function testNoConfigSet() { $writer = new Zend_Config_Writer_Ini(array('filename' => $this->_tempName)); try { $writer->write(); $this->fail('An expected Zend_Config_Exception has not been raised'); } catch (Zend_Config_Exception $expected) { $this->assertContains('No config was set', $expected->getMessage()); } } public function testFileNotWritable() { $writer = new Zend_Config_Writer_Ini(array('config' => new Zend_Config(array()), 'filename' => '/../../../')); try { $writer->write(); $this->fail('An expected Zend_Config_Exception has not been raised'); } catch (Zend_Config_Exception $expected) { $this->assertContains('Could not write to file', $expected->getMessage()); } } public function testWriteAndRead() { $config = new Zend_Config(array('default' => array('test' => 'foo'))); $writer = new Zend_Config_Writer_Ini(array('config' => $config, 'filename' => $this->_tempName)); $writer->write(); $config = new Zend_Config_Ini($this->_tempName, null); $this->assertEquals('foo', $config->default->test); } public function testNoSection() { $config = new Zend_Config(array('test' => 'foo', 'test2' => array('test3' => 'bar'))); $writer = new Zend_Config_Writer_Ini(array('config' => $config, 'filename' => $this->_tempName)); $writer->write(); $config = new Zend_Config_Ini($this->_tempName, null); $this->assertEquals('foo', $config->test); $this->assertEquals('bar', $config->test2->test3); } public function testWriteAndReadOriginalFile() { $config = new Zend_Config_Ini(dirname(__FILE__) . '/files/allsections.ini', null, array('skipExtends' => true)); $writer = new Zend_Config_Writer_Ini(array('config' => $config, 'filename' => $this->_tempName)); $writer->write(); $config = new Zend_Config_Ini($this->_tempName, null); $this->assertEquals('multi', $config->staging->one->two->three); $config = new Zend_Config_Ini($this->_tempName, null, array('skipExtends' => true)); $this->assertFalse(isset($config->staging->one)); } public function testWriteAndReadSingleSection() { $config = new Zend_Config_Ini(dirname(__FILE__) . '/files/allsections.ini', 'staging', array('skipExtends' => true)); $writer = new Zend_Config_Writer_Ini(array('config' => $config, 'filename' => $this->_tempName)); $writer->write(); $config = new Zend_Config_Ini($this->_tempName, null); $this->assertEquals('staging', $config->staging->hostname); $this->assertEquals('', $config->staging->debug); $this->assertEquals(null, @$config->production); } public function testArgumentOverride() { $config = new Zend_Config(array('default' => array('test' => 'foo'))); $writer = new Zend_Config_Writer_Ini(); $writer->write($this->_tempName, $config); $config = new Zend_Config_Ini($this->_tempName, null); $this->assertEquals('foo', $config->default->test); } /** * @group ZF-8234 */ public function testRender() { $config = new Zend_Config(array('test' => 'foo', 'bar' => array(0 => 'baz', 1 => 'foo'))); $writer = new Zend_Config_Writer_Ini(); $iniString = $writer->setConfig($config)->render(); $expected = <<assertEquals($expected, $iniString); } public function testRenderWithoutSections() { $config = new Zend_Config(array('test' => 'foo', 'test2' => array('test3' => 'bar'))); $writer = new Zend_Config_Writer_Ini(); $writer->setRenderWithoutSections(); $iniString = $writer->setConfig($config)->render(); $expected = <<assertEquals($expected, $iniString); } public function testRenderWithoutSections2() { $config = new Zend_Config_Ini(dirname(__FILE__) . '/files/allsections.ini', null, array('skipExtends' => true)); $writer = new Zend_Config_Writer_Ini(); $writer->setRenderWithoutSections(); $iniString = $writer->setConfig($config)->render(); $expected = <<assertEquals($expected, $iniString); } public function testZF6521_NoDoubleQuoutesInValue() { $config = new Zend_Config(array('default' => array('test' => 'fo"o'))); try { $writer = new Zend_Config_Writer_Ini(array('config' => $config, 'filename' => $this->_tempName)); $writer->write(); $this->fail('An expected Zend_Config_Exception has not been raised'); } catch (Zend_Config_Exception $expected) { $this->assertContains('Value can not contain double quotes "', $expected->getMessage()); } } /** * @group ZF-6289 */ public function testZF6289_NonSectionElementsAndSectionJumbling() { $config = new Zend_Config(array( 'one' => 'element', 'two' => array('type' => 'section'), 'three' => 'element', 'four' => array('type' => 'section'), 'five' => 'element' )); $writer = new Zend_Config_Writer_Ini; $iniString = $writer->setConfig($config)->render($config); $expected = <<assertEquals( $expected, $iniString ); } }