Author: Derick Rethans
Date: 2006-09-26 19:32:42 +0200 (Tue, 26 Sep 2006)
New Revision: 3594
Log:
- Removed debug code from the ezcConfigurationIniWriter.
- Corrected documentation and key() method return value. This can only be
an integer or string and PHP just converted the NULL to (int) 0 anyway.
- Removed an extra regexp which does not add any value for validating setting
names.
- Added test cases for ezcConfigurationIniParser.
- Added more test cases for ezcConfigurationManager and
ezcConfigurationArrayWriter.
Added:
trunk/Configuration/tests/configuration_ini_parser_test.php
Modified:
trunk/Configuration/src/ini/ini_parser.php
trunk/Configuration/src/ini/ini_writer.php
trunk/Configuration/tests/configuration_array_writer_test.php
trunk/Configuration/tests/configuration_manager_test.php
trunk/Configuration/tests/suite.php
Modified: trunk/Configuration/src/ini/ini_parser.php
===================================================================
--- trunk/Configuration/src/ini/ini_parser.php 2006-09-26 14:21:50 UTC (rev
3593)
+++ trunk/Configuration/src/ini/ini_parser.php 2006-09-26 17:32:42 UTC (rev
3594)
@@ -1,6 +1,6 @@
<?php
/**
- * File containing the ezcConfigurationIniReader class
+ * File containing the ezcConfigurationIniParser class
*
* @package Configuration
* @version //autogen//
@@ -260,13 +260,13 @@
* Returns the "key" for each element.
*
* This is used by the Iterator to assign a key to each "array" element. As
- * we don't use that we simply return NULL.
+ * we don't use that we simply return 0.
*
- * @return null
+ * @return int
*/
public function key()
{
- return NULL;
+ return 0;
}
/**
@@ -355,12 +355,14 @@
$settingDimensions = $matches[3];
$settingValue = $matches[5];
- /* Check if the setting name is not valid ID */
+ /* There could be a check if the setting name is not valid ID,
+ * but that is unnecesary because the previous regexps
+ * filter this out already.:
if ( !preg_match( '@'. self::ID_REGEXP . '@', $settingID ) )
{
$this->raiseError( "Setting ID <$settingID> has invalid
characters" );
return;
- }
+ } */
$settingComments = $this->fetchComments();
if ( $this->emitSetting( $this->currentGroup, $settingID,
$settingDimensions, $settingComments, $settingValue ) )
Modified: trunk/Configuration/src/ini/ini_writer.php
===================================================================
--- trunk/Configuration/src/ini/ini_writer.php 2006-09-26 14:21:50 UTC (rev
3593)
+++ trunk/Configuration/src/ini/ini_writer.php 2006-09-26 17:32:42 UTC (rev
3594)
@@ -149,8 +149,6 @@
self::writeSetting( $fp, "{$settingName}[{$settingKey}]",
$settingElement, $commentSettingValue );
}
break;
- default:
- echo $type, "\n";
}
}
}
Modified: trunk/Configuration/tests/configuration_array_writer_test.php
===================================================================
--- trunk/Configuration/tests/configuration_array_writer_test.php
2006-09-26 14:21:50 UTC (rev 3593)
+++ trunk/Configuration/tests/configuration_array_writer_test.php
2006-09-26 17:32:42 UTC (rev 3594)
@@ -413,6 +413,40 @@
$this->assertEquals( POSIX_S_IFREG | 0640, $stat['mode'] );
}
+ public function testValidationNonStrict()
+ {
+ $settings = array(
+ '3D' => array(
+ 'Decimal' => array( 42, 0 ),
+ 'Array' => array(
+ 'Decimal' => array( 'a' => 42, 'b' => 0 ),
+ 'Mixed' => array( 'b' => false, 2 => "Derick \"Tiger\"
Rethans" ),
+ ),
+ ),
+ );
+ $comments = array(
+ '3D' => array(
+ 'Decimal' => array( " One with a comment", " Second one with a
comment" ),
+ 'Array' => array(
+ 'Mixed' => array( 2 => " One with a comment" ),
+ ),
+ ),
+ );
+ $test = new ezcConfiguration( $settings, $comments );
+
+ $path = $this->tempDir . '/multi-dim2.php';
+ $backend = new ezcConfigurationArrayWriter( $path, $test );
+ $backend->save();
+
+ $backend = new ezcConfigurationArrayReader( $path );
+ $return = $backend->validate( false );
+
+ $expected = new ezcConfigurationValidationResult(
$backend->getLocation(), $backend->getName(), $path );
+ $expected->isValid = true;
+
+ $this->assertEquals( $expected, $return );
+ }
+
/*
public function testWriteFailure()
{
Added: trunk/Configuration/tests/configuration_ini_parser_test.php
===================================================================
--- trunk/Configuration/tests/configuration_ini_parser_test.php 2006-09-26
14:21:50 UTC (rev 3593)
+++ trunk/Configuration/tests/configuration_ini_parser_test.php 2006-09-26
17:32:42 UTC (rev 3594)
@@ -0,0 +1,61 @@
+<?php
+/**
+ * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ * @version //autogentag//
+ * @filesource
+ * @package Configuration
+ * @subpackage Tests
+ */
+
+/**
+ * @package Configuration
+ * @subpackage Tests
+ */
+class ezcConfigurationIniParserTest extends ezcTestCase
+{
+ public function testNonExistingFile()
+ {
+ try
+ {
+ $parser = new ezcConfigurationIniParser(
ezcConfigurationIniParser::PARSE, 'Configuration/tests/files/not-here.ini' );
+ $this->fail( "Expected exception was not thrown." );
+ }
+ catch ( ezcBaseFileNotFoundException $e )
+ {
+ $this->assertEquals( 'The file
<Configuration/tests/files/not-here.ini> could not be found.', $e->getMessage()
);
+ }
+ }
+
+ public function testIterator1()
+ {
+ $parser = new ezcConfigurationIniParser(
ezcConfigurationIniParser::PARSE, 'Configuration/tests/files/one-group.ini' );
+ try
+ {
+ foreach ( $parser as $item )
+ {
+ }
+ $this->fail( "Expected exception was not thrown." );
+ }
+ catch ( Exception $e )
+ {
+ $this->assertEquals( 'You can only use this implementation of the
iterator with a NoRewindIterator.', $e->getMessage() );
+ }
+ }
+
+ public function testIterator2()
+ {
+ $parser = new ezcConfigurationIniParser(
ezcConfigurationIniParser::PARSE, 'Configuration/tests/files/multi-dim2.ini' );
+ foreach ( new NoRewindIterator( $parser ) as $key => $item )
+ {
+ $this->assertSame( 0, $key );
+ }
+ }
+
+ public static function suite()
+ {
+ return new ezcTestSuite( 'ezcConfigurationIniParserTest' );
+ }
+
+}
+?>
Property changes on: trunk/Configuration/tests/configuration_ini_parser_test.php
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/Configuration/tests/configuration_manager_test.php
===================================================================
--- trunk/Configuration/tests/configuration_manager_test.php 2006-09-26
14:21:50 UTC (rev 3593)
+++ trunk/Configuration/tests/configuration_manager_test.php 2006-09-26
17:32:42 UTC (rev 3594)
@@ -93,6 +93,21 @@
$this->assertEquals( false, $setting );
}
+ public function testNoConfig()
+ {
+ $config = ezcConfigurationManager::getInstance();
+
+ try
+ {
+ $setting = $config->getSetting( 'not-there', 'TheOnlyGroup',
'NotThere' );
+ $this->fail( 'Expected exception was not thrown' );
+ }
+ catch ( ezcConfigurationUnknownConfigException $e )
+ {
+ $this->assertEquals( "The configuration <not-there> does not
exist.", $e->getMessage() );
+ }
+ }
+
public function testHasSettingNotExists()
{
$config = ezcConfigurationManager::getInstance();
Modified: trunk/Configuration/tests/suite.php
===================================================================
--- trunk/Configuration/tests/suite.php 2006-09-26 14:21:50 UTC (rev 3593)
+++ trunk/Configuration/tests/suite.php 2006-09-26 17:32:42 UTC (rev 3594)
@@ -13,6 +13,7 @@
*/
require_once 'configuration_test.php';
require_once 'configuration_manager_test.php';
+require_once 'configuration_ini_parser_test.php';
require_once 'configuration_ini_reader_test.php';
require_once 'configuration_ini_writer_test.php';
require_once 'configuration_array_writer_test.php';
@@ -31,6 +32,7 @@
$this->addTest( ezcConfigurationTest::suite() );
$this->addTest( ezcConfigurationManagerTest::suite() );
$this->addTest( ezcConfigurationIniReaderTest::suite() );
+ $this->addTest( ezcConfigurationIniParserTest::suite() );
$this->addTest( ezcConfigurationIniWriterTest::suite() );
$this->addTest( ezcConfigurationArrayWriterTest::suite() );
}
--
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components