[pLog-svn] r3809 - plog/trunk/class/test/tests/config
oscar at devel.lifetype.net
oscar at devel.lifetype.net
Wed Jul 26 12:01:12 GMT 2006
Author: oscar
Date: 2006-07-26 12:01:11 +0000 (Wed, 26 Jul 2006)
New Revision: 3809
Added:
plog/trunk/class/test/tests/config/configfilestorage_test.class.php
Log:
Added some basic test case for ConfigFileStorage
Added: plog/trunk/class/test/tests/config/configfilestorage_test.class.php
===================================================================
--- plog/trunk/class/test/tests/config/configfilestorage_test.class.php 2006-07-26 07:32:16 UTC (rev 3808)
+++ plog/trunk/class/test/tests/config/configfilestorage_test.class.php 2006-07-26 12:01:11 UTC (rev 3809)
@@ -0,0 +1,164 @@
+<?php
+
+ include_once( PLOG_CLASS_PATH."class/test/helpers/lifetypetestcase.class.php" );
+ include_once( PLOG_CLASS_PATH."class/config/configfilestorage.class.php" );
+
+ /**
+ * \ingroup Tests
+ *
+ * Test cases for the ConfigFileStorage class.
+ *
+ * It includes regression test for svn revisions 3768 and 3799
+ */
+ class ConfigFileStorage_Test extends LifeTypeTestCase
+ {
+ /**
+ * Creates a temporary test configuration file using both single quotes
+ * and double quotes
+ */
+ function setUp()
+ {
+ include_once( PLOG_CLASS_PATH."class/config/config.class.php" );
+
+
+ $config =& Config::getConfig();
+ $tmpFolder = $config->getValue( "temp_folder" );
+
+ $this->file1 = str_replace( "\\", "/", PLOG_CLASS_PATH ).$tmpFolder."/file1.properties.php";
+
+ // create the first file
+ $data1 = '<?php
+ #
+ # this is one comment
+ #
+ $config[\'test_key_1\'] = \'\';
+ $config[\'test_key_2\'] = \'some value\';
+ #
+ # this is
+ # another
+ # comment
+ #
+ $config["test_key_3"] = "value for test_key_3";
+ #
+ # an empty value
+ #
+ $config[\'test_empty_key\'] = \'\';
+ ?>';
+
+ $this->createFile( $this->file1, $data1 );
+ }
+
+ /**
+ * delete the temporary file that was created
+ */
+ function tearDown()
+ {
+ include_once( PLOG_CLASS_PATH."class/file/file.class.php" );
+ File::delete( $this->file1 );
+ }
+
+ /**
+ * @private
+ */
+ function createFile( $file, $data )
+ {
+ include_once( PLOG_CLASS_PATH."class/file/file.class.php" );
+ $file = new File( $file );
+ $writable = $file->open( 'w' );
+ if ($writable) {
+ $file->write( $data );
+ $file->close();
+ return true;
+ }
+ else {
+ return false;
+ }
+ }
+
+ /**
+ * Check if the file was loaded properly and loads a value from a line
+ * with single quotes
+ */
+ function testGetSingleQuotesValue()
+ {
+ // open and load the file
+ $cf = new ConfigFileStorage( Array( "file" => $this->file1 ));
+
+ $this->assertEquals( "some value", $cf->getValue( "test_key_2" ),
+ "Error loading test_key_2 key from file ".$this->file1 );
+ }
+
+ /**
+ * Check if the file was loaded properly and loads a value from a line
+ * with double quotes
+ */
+ function testGetDoubleQuotesValue()
+ {
+ // open and load the file
+ $cf = new ConfigFileStorage( Array( "file" => $this->file1 ));
+
+ $this->assertEquals( "value for test_key_3", $cf->getValue( "test_key_3" ),
+ "Error loading test_key_3 key from file ".$this->file1 );
+ }
+
+ /**
+ * test whether new values are kept properly after loading the file
+ */
+ function testSetNewValue()
+ {
+ // open and load the file
+ $cf = new ConfigFileStorage( Array( "file" => $this->file1 ));
+
+ // add a new key
+ $newValue = "This is the value for test_key_new";
+ $newKey = "test_key_new";
+ $cf->setValue( $newKey, $newValue );
+
+ $this->assertEquals( $newValue, $cf->getValue( $newKey ), "Error fetching $newKey" );
+ }
+
+ /**
+ * test whether new values for keys defined with single quotes are saved properly back to the file
+ */
+ function testSaveValue()
+ {
+ include_once( PLOG_CLASS_PATH."class/file/file.class.php" );
+
+ // open and load the file
+ $cf = new ConfigFileStorage( Array( "file" => $this->file1 ));
+
+ // and save a new one
+ $newValue = "This is the value for test_empty_key";
+ $newKey = "test_empty_key";
+ $cf->setValue( $newKey, $newValue );
+ $cf->save();
+
+ // reopen and load the file
+ $cf2 = new ConfigFileStorage( Array( "file" => $this->file1 ));
+ $this->assertEquals( $newValue, $cf2->getValue( $newKey ),
+ "$newKey was not saved properly to file ".$this->file1 );
+ }
+
+ /**
+ * test whether new values for keys defined with double quotes are saved properly back to the file
+ */
+ function testSaveDoubleQuotesValue()
+ {
+ include_once( PLOG_CLASS_PATH."class/file/file.class.php" );
+
+ // open and load the file
+ $cf = new ConfigFileStorage( Array( "file" => $this->file1 ));
+
+ // and save a new one
+ $newValue = "This is the value for test_key_3";
+ $newKey = "test_key_3";
+ $cf->setValue( $newKey, $newValue );
+ $cf->save();
+
+ // reopen and load the file
+ $cf2 = new ConfigFileStorage( Array( "file" => $this->file1 ));
+ $this->assertEquals( $newValue, $cf2->getValue( $newKey ),
+ "$newKey was not saved properly to file ".$this->file1 );
+ }
+ }
+?>
\ No newline at end of file
More information about the pLog-svn
mailing list