Author: dr Date: Fri Jan 11 11:28:01 2008 New Revision: 7124 Log: - Fixed issue #12368: ezcTemplateConfiguration::addExtension() did not check for invalid arguments correctly.
Modified: trunk/Template/ChangeLog trunk/Template/src/configuration.php trunk/Template/tests/template_test.php Modified: trunk/Template/ChangeLog ============================================================================== --- trunk/Template/ChangeLog [iso-8859-1] (original) +++ trunk/Template/ChangeLog [iso-8859-1] Fri Jan 11 11:28:01 2008 @@ -15,6 +15,9 @@ * {dynamic} is only allowed after {cache_template} or in {cache_block}. * corrected documentation in regard to TTL vs. ttl. * fixed the cache file names in Windows (replace '\' with '-'). + +- Fixed issue #12368: ezcTemplateConfiguration::addExtension() did not + check for invalid arguments correctly. 1.2 - Monday 02 July 2007 Modified: trunk/Template/src/configuration.php ============================================================================== --- trunk/Template/src/configuration.php [iso-8859-1] (original) +++ trunk/Template/src/configuration.php [iso-8859-1] Fri Jan 11 11:28:01 2008 @@ -151,7 +151,7 @@ * @param string $value * * @throws ezcBasePropertyNotFoundException if the property does not exist. - * @return void + * @throws ezcBaseValueException if the desired property value is out of range. * @ignore */ public function __set( $name, $value ) @@ -284,8 +284,9 @@ } /** - * Adds custom tags or function to the customBlock or customFunction property and - * indirectly add the custom extension to the template language. + * Adds custom tags or functions to the customBlock or customFunction + * property and indirectly adds the custom extension to the template + * language. * * The parameter $customBlockClass expects a class that implements either * the interface ezcTemplateCustomBlock, ezcTemplateCustomFunction, or both. @@ -296,14 +297,16 @@ * [EMAIL PROTECTED] ezcTemplateConfiguration::customFunctions $customFunctions} property. * * @param string $customClass - * @throws ezcTemplateCustomBlockException if the $customClass parameter is not a string. - * @return void + * @throws ezcBaseValueException if the $customClass parameter is not a + * string, or when the classname that it represents does not + * implement either the ezcTemplateCustomBlock or + * ezcTemplateCustomFunction interface. */ public function addExtension( $customClass ) { - if ( !is_string( $customClass ) ) - { - throw new ezcTemplateCustomBlockException( "Could not add the extension $customClass, because the given value is not a string." ); + if ( !is_string( $customClass ) || !ezcBaseFeatures::classExists( $customClass, true ) ) + { + throw new ezcBaseValueException( 'customClass', $customClass, 'string with classname that implements the ezcTemplateCustomBlock or ezcTemplateCustomFunction interface', 'argument' ); } $implements = class_implements( $customClass ); @@ -321,9 +324,9 @@ $added = true; } - if ( !$added) - { - throw new ezcTemplateCustomBlockException( "Could not add the extension $customClass. Does it implement ezcTemplateCustomBlock or ezcTemplateCustomFunction?" ); + if ( !$added ) + { + throw new ezcBaseValueException( 'customClass', $customClass, 'string with classname that implements the ezcTemplateCustomBlock or ezcTemplateCustomFunction interface', 'argument' ); } } Modified: trunk/Template/tests/template_test.php ============================================================================== --- trunk/Template/tests/template_test.php [iso-8859-1] (original) +++ trunk/Template/tests/template_test.php [iso-8859-1] Fri Jan 11 11:28:01 2008 @@ -316,6 +316,47 @@ self::assertEquals(1, count(glob($tc->compilePath . "/compiled_templates/xhtml-*/*.php")) ); } + public function testAddExtensionTestWrong1() + { + $c = new ezcTemplateConfiguration(); + try + { + $c->addExtension( 'foo' ); + self::fail( "Expected exception was not thrown" ); + } + catch ( ezcBaseValueException $e ) + { + self::assertEquals( "The value 'foo' that you were trying to assign to argument 'customClass' is invalid. Allowed values are: string with classname that implements the ezcTemplateCustomBlock or ezcTemplateCustomFunction interface.", $e->getMessage() ); + } + } + + public function testAddExtensionTestWrong2() + { + $c = new ezcTemplateConfiguration(); + try + { + $c->addExtension( array( 'foo' ) ); + self::fail( "Expected exception was not thrown" ); + } + catch ( ezcBaseValueException $e ) + { + self::assertEquals( "The value 'a:1:{i:0;s:3:\"foo\";}' that you were trying to assign to argument 'customClass' is invalid. Allowed values are: string with classname that implements the ezcTemplateCustomBlock or ezcTemplateCustomFunction interface.", $e->getMessage() ); + } + } + + public function testAddExtensionTestWrong3() + { + $c = new ezcTemplateConfiguration(); + try + { + $c->addExtension( 'ezcTemplateConfiguration' ); + self::fail( "Expected exception was not thrown" ); + } + catch ( ezcBaseValueException $e ) + { + self::assertEquals( "The value 'ezcTemplateConfiguration' that you were trying to assign to argument 'customClass' is invalid. Allowed values are: string with classname that implements the ezcTemplateCustomBlock or ezcTemplateCustomFunction interface.", $e->getMessage() ); + } + } } -- svn-components mailing list svn-components@lists.ez.no http://lists.ez.no/mailman/listinfo/svn-components