Author: kn
Date: Wed Feb 6 14:06:35 2008
New Revision: 7307
Log:
- Refactored options test structure
Modified:
experimental/Document/tests/document_options_xml_base_test.php
experimental/Document/tests/options_test_case.php
Modified: experimental/Document/tests/document_options_xml_base_test.php
==============================================================================
--- experimental/Document/tests/document_options_xml_base_test.php [iso-8859-1]
(original)
+++ experimental/Document/tests/document_options_xml_base_test.php [iso-8859-1]
Wed Feb 6 14:06:35 2008
@@ -24,11 +24,25 @@
return new PHPUnit_Framework_TestSuite( __CLASS__ );
}
+ protected function getOptionsClassName()
+ {
+ return 'ezcDocumentXmlBaseOptions';
+ }
+
+ public static function provideDefaultValues()
+ {
+ return array(
+ array(
+ 'indentXml',
+ false,
+ ),
+ );
+ }
+
public static function provideValidData()
{
return array(
array(
- new ezcDocumentXmlBaseOptions(),
'indentXml',
array( true, false ),
),
@@ -39,7 +53,6 @@
{
return array(
array(
- new ezcDocumentXmlBaseOptions(),
'indentXml',
array( 1, 'foo', .5, new StdClass(), array() ),
),
Modified: experimental/Document/tests/options_test_case.php
==============================================================================
--- experimental/Document/tests/options_test_case.php [iso-8859-1] (original)
+++ experimental/Document/tests/options_test_case.php [iso-8859-1] Wed Feb 6
14:06:35 2008
@@ -18,6 +18,35 @@
abstract class ezcDocumentOptionsTestCase extends ezcTestCase
{
/**
+ * Return class name of options class to test
+ *
+ * @return string
+ */
+ abstract protected function getOptionsClassName();
+
+ /**
+ * Return default values for the options
+ *
+ * Returned array should be in the format:
+ *
+ * <code>
+ * array(
+ * array(
+ * 'optionname',
+ * $value,
+ * ),
+ * ...
+ * )
+ * </code>
+ *
+ * @return array
+ */
+ public static function provideDefaultValues()
+ {
+ return array();
+ }
+
+ /**
* Return valid data for options to test
*
* Returned array should be in the format:
@@ -34,7 +63,7 @@
* )
* </code>
*
- * @return void
+ * @return array
*/
public static function provideValidData()
{
@@ -49,7 +78,6 @@
* <code>
* array(
* array(
- * new ezcComponentOptionClass(),
* 'optionname',
* array(
* 'value 1', 'value 2', ...
@@ -59,7 +87,7 @@
* )
* </code>
*
- * @return void
+ * @return array
*/
public static function provideInvalidData()
{
@@ -69,10 +97,30 @@
/**
* Test all options provided by the data provider
*
+ * @dataProvider provideDefaultValues
+ */
+ public function testOptionsDefaultValues( $property, $value )
+ {
+ $class = $this->getOptionsClassName();
+ $option = new $class();
+
+ $this->assertSame(
+ $value,
+ $option->$property,
+ "Default value in option class '$class' of property '$property' is
not '$value'."
+ );
+ }
+
+ /**
+ * Test all options provided by the data provider
+ *
* @dataProvider provideValidData
*/
- public function testOptionsValidValues( $option, $property, $values )
+ public function testOptionsValidValues( $property, $values )
{
+ $class = $this->getOptionsClassName();
+ $option = new $class();
+
$this->assertSetProperty(
$option,
$property,
@@ -85,14 +133,39 @@
*
* @dataProvider provideInvalidData
*/
- public function testOptionsInvalidValues( $option, $property, $values )
+ public function testOptionsInvalidValues( $property, $values )
{
+ $class = $this->getOptionsClassName();
+ $option = new $class();
+
$this->assertSetPropertyFails(
$option,
$property,
$values
);
}
+
+ public function testUnknownValue()
+ {
+ $class = $this->getOptionsClassName();
+ $option = new $class();
+
+ try
+ {
+ $option->get_an_not_existing_property;
+ $this->fail( 'Expected ezcBasePropertyNotFoundException.' );
+ }
+ catch ( ezcBasePropertyNotFoundException $e )
+ { /* Expected */ }
+
+ try
+ {
+ $option->get_an_not_existing_property = true;
+ $this->fail( 'Expected ezcBasePropertyNotFoundException.' );
+ }
+ catch ( ezcBasePropertyNotFoundException $e )
+ { /* Expected */ }
+ }
}
?>
--
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components