Author: Tobias Schlitt
Date: 2006-09-24 17:27:52 +0200 (Sun, 24 Sep 2006)
New Revision: 3560

Log:
- Added more test cases.
- Added new test case to suite.

Modified:
   trunk/ConsoleTools/tests/input_test.php
   trunk/ConsoleTools/tests/option_test.php
   trunk/ConsoleTools/tests/suite.php

Modified: trunk/ConsoleTools/tests/input_test.php
===================================================================
--- trunk/ConsoleTools/tests/input_test.php     2006-09-24 11:51:40 UTC (rev 
3559)
+++ trunk/ConsoleTools/tests/input_test.php     2006-09-24 15:27:52 UTC (rev 
3560)
@@ -213,14 +213,8 @@
         unset( $this->input );
     }
 
-    /**
-     * testRegisterParam
-     * 
-     * @access public
-     */
     public function testRegisterParam()
     {
-        // Using local object to test registration itself.
         $input = new ezcConsoleInput();
         foreach ( $this->testOptions as $optionData )
         {
@@ -1156,33 +1150,7 @@
             'Program synopsis not generated correctly.'
         );
     }
-
-    public function testInvalidOptionName_short()
-    {
-        try
-        {
-            $option = new ezcConsoleOption( ' ', 'help' );
-        }
-        catch ( ezcConsoleInvalidOptionNameException $e )
-        {
-            return;
-        }
-        $this->fail( 'Exception not thrown on invalid option name.' );
-    }
     
-    public function testInvalidOptionName_long()
-    {
-        try
-        {
-            $option = new ezcConsoleOption( 'h', '--help' );
-        }
-        catch ( ezcConsoleInvalidOptionNameException $e )
-        {
-            return;
-        }
-        $this->fail( 'Exception not thrown on invalid option name.' );
-    }
-    
     private function commonProcessTestSuccess( $args, $res )
     {
         try 

Modified: trunk/ConsoleTools/tests/option_test.php
===================================================================
--- trunk/ConsoleTools/tests/option_test.php    2006-09-24 11:51:40 UTC (rev 
3559)
+++ trunk/ConsoleTools/tests/option_test.php    2006-09-24 15:27:52 UTC (rev 
3560)
@@ -23,8 +23,72 @@
                return new ezcTestSuite( "ezcConsoleToolsOptionTest" );
        }
 
-    public function testAddDependencyExisting()
+    public function testConstructionSuccess()
     {
+        $optionDependency = new ezcConsoleOption( "d", "depend" );
+        $optionExclusion = new ezcConsoleOption( "e", "exclude" );
+
+        $ruleDependency = new ezcConsoleOptionRule( $optionDependency, array( 
"abc" ) );
+        $ruleExclusion = new ezcConsoleOptionRule( $optionExclusion, array( 
"abc" ) );
+
+        $option = new ezcConsoleOption(
+            "a",
+            "aaa",
+            ezcConsoleInput::TYPE_INT,
+            23,
+            true,
+            "Shorthelp",
+            "Longhelp",
+            array( $ruleDependency ),
+            array( $ruleExclusion ),
+            false,
+            true,
+            true
+        );
+
+        $this->assertEquals( $option->short, "a" );
+        $this->assertEquals( $option->long, "aaa" );
+        $this->assertEquals( ezcConsoleInput::TYPE_INT, $option->type );
+        $this->assertEquals( 23, $option->default );
+        $this->assertTrue( $option->multiple );
+        $this->assertEquals( "Shorthelp", $option->shorthelp );
+        $this->assertEquals( "Longhelp", $option->longhelp );
+        $this->assertEquals( array( $ruleDependency ), 
$option->getDependencies() );
+        $this->assertEquals( array( $ruleExclusion ), $option->getExclusions() 
);
+        $this->assertFalse( $option->arguments );
+        $this->assertTrue( $option->mandatory );
+        $this->assertTrue( $option->isHelpOption );
+    }
+
+    public function testInvalidOptionName_short()
+    {
+        try
+        {
+            $option = new ezcConsoleOption( ' ', 'help' );
+        }
+        catch ( ezcConsoleInvalidOptionNameException $e )
+        {
+            return;
+        }
+        $this->fail( 'Exception not thrown on invalid option name.' );
+    }
+    
+    public function testInvalidOptionName_long()
+    {
+        try
+        {
+            $option = new ezcConsoleOption( 'h', '--help' );
+        }
+        catch ( ezcConsoleInvalidOptionNameException $e )
+        {
+            return;
+        }
+        $this->fail( 'Exception not thrown on invalid option name.' );
+    }
+    
+
+    public function testAddDependency()
+    {
         $option_1 = new ezcConsoleOption(
             "a",
             "aaa"
@@ -48,7 +112,6 @@
         );
     }
 
-    // Bug #9052: Exception because of invalid property in ezcConsoleOption
     public function testRemoveDependency()
     {
         $option_1 = new ezcConsoleOption(
@@ -60,6 +123,32 @@
             "bbb"
         );
 
+        $rule = new ezcConsoleOptionRule(
+            $option_2, array( "c" )
+        );
+
+        $option_1->addDependency( $rule );
+        $option_1->removeDependency( $rule );
+
+        $this->assertAttributeEquals(
+            array(),
+            "dependencies",
+            $option_1
+        );
+    }
+
+    // Bug #9052: Exception because of invalid property in ezcConsoleOption
+    public function testRemoveAllDependencies()
+    {
+        $option_1 = new ezcConsoleOption(
+            "a",
+            "aaa"
+        );
+        $option_2 = new ezcConsoleOption(
+            "b",
+            "bbb"
+        );
+
         $rule_1 = new ezcConsoleOptionRule(
             $option_2, array( "c" )
         );
@@ -80,7 +169,7 @@
     }
 
     // Bug #9052: Exception because of invalid property in ezcConsoleOption
-    public function testHasDependency()
+    public function testHasDependencySuccess()
     {
         $option_1 = new ezcConsoleOption(
             "a",
@@ -102,6 +191,26 @@
         );
     }
     
+    public function testHasDependencyFailure()
+    {
+        $option_1 = new ezcConsoleOption(
+            "a",
+            "aaa"
+        );
+        $option_2 = new ezcConsoleOption(
+            "b",
+            "bbb"
+        );
+
+        $rule = new ezcConsoleOptionRule(
+            $option_2, array( "c" )
+        );
+
+        $this->assertFalse(
+            $option_1->hasDependency( $option_2 )
+        );
+    }
+    
     public function testResetDependencies()
     {
         $option_1 = new ezcConsoleOption(
@@ -127,7 +236,7 @@
         );
     }
     
-    public function testAddExclusionExisting()
+    public function testAddExclusion()
     {
         $option_1 = new ezcConsoleOption(
             "a",
@@ -152,7 +261,6 @@
         );
     }
 
-    // Bug #9052: Exception because of invalid property in ezcConsoleOption
     public function testRemoveExclusion()
     {
         $option_1 = new ezcConsoleOption(
@@ -164,6 +272,32 @@
             "bbb"
         );
 
+        $rule = new ezcConsoleOptionRule(
+            $option_2, array( "c" )
+        );
+
+        $option_1->addExclusion( $rule );
+        $option_1->removeExclusion( $rule );
+
+        $this->assertAttributeEquals(
+            array(),
+            "exclusions",
+            $option_1
+        );
+    }
+
+    // Bug #9052: Exception because of invalid property in ezcConsoleOption
+    public function testRemoveAllExclusions()
+    {
+        $option_1 = new ezcConsoleOption(
+            "a",
+            "aaa"
+        );
+        $option_2 = new ezcConsoleOption(
+            "b",
+            "bbb"
+        );
+
         $rule_1 = new ezcConsoleOptionRule(
             $option_2, array( "c" )
         );
@@ -184,7 +318,7 @@
     }
 
     // Bug #9052: Exception because of invalid property in ezcConsoleOption
-    public function testHasExclusion()
+    public function testHasExclusionSuccess()
     {
         $option_1 = new ezcConsoleOption(
             "a",
@@ -206,6 +340,26 @@
         );
     }
     
+    public function testHasExclusionFailure()
+    {
+        $option_1 = new ezcConsoleOption(
+            "a",
+            "aaa"
+        );
+        $option_2 = new ezcConsoleOption(
+            "b",
+            "bbb"
+        );
+
+        $rule = new ezcConsoleOptionRule(
+            $option_2, array( "c" )
+        );
+
+        $this->assertFalse(
+            $option_1->hasExclusion( $option_2 )
+        );
+    }
+    
     public function testResetExclusions()
     {
         $option_1 = new ezcConsoleOption(
@@ -230,6 +384,272 @@
             $option_1
         );
     }
+
+    public function testPropertyGetAccessSuccess()
+    {
+        $option = new ezcConsoleOption( "a", "aaa" );
+
+        $this->assertEquals( "a", $option->short );
+        $this->assertEquals( "aaa", $option->long );
+        $this->assertEquals( ezcConsoleInput::TYPE_NONE, $option->type );
+        $this->assertNull( $option->default );
+        $this->assertFalse( $option->multiple );
+        $this->assertEquals( "No help available.", $option->shorthelp );
+        $this->assertEquals( "Sorry, there is no help text available for this 
parameter.", $option->longhelp );
+        $this->assertTrue( $option->arguments );
+        $this->assertFalse( $option->mandatory );
+        $this->assertFalse( $option->isHelpOption );
+    }
+
+    public function testPropertyGetAccessFailureDependencies()
+    {
+        $option = new ezcConsoleOption( "a", "aaa" );
+
+        try
+        {
+            $foo = $option->dependencies;
+        }
+        catch( ezcBasePropertyNotFoundException $e )
+        {
+            return;
+        }
+        $this->fail( "Exception not thrown on access of 
ezcConsoleOption->dependencies." );
+    }
+
+    public function testPropertyGetAccessFailureExclusions()
+    {
+        $option = new ezcConsoleOption( "a", "aaa" );
+
+        try
+        {
+            $foo = $option->exclusions;
+        }
+        catch( ezcBasePropertyNotFoundException $e )
+        {
+            return;
+        }
+        $this->fail( "Exception not thrown on access of 
ezcConsoleOption->exclusions." );
+    }
+
+    public function testPropertyGetAccessFailureNotExisting()
+    {
+        $option = new ezcConsoleOption( "a", "aaa" );
+
+        try
+        {
+            $foo = $option->nonExisting;
+        }
+        catch( ezcBasePropertyNotFoundException $e )
+        {
+            return;
+        }
+        $this->fail( "Exception not thrown on access of 
ezcConsoleOption->nonExisting." );
+    }
+
+    public function testPropertySetAccessSuccess()
+    {
+        $option = new ezcConsoleOption( "a", "aaa" );
+        $option->type = ezcConsoleInput::TYPE_STRING;
+        $option->type = ezcConsoleInput::TYPE_NONE;
+        $option->type = ezcConsoleInput::TYPE_INT;
+        $option->default = 10;
+        $option->multiple = true;
+        $option->shorthelp = "Shorthelp";
+        $option->longhelp = "Longhelp";
+        $option->arguments = false;
+        $option->mandatory = true;
+        $option->isHelpOption = true;
+
+        $this->assertEquals( ezcConsoleInput::TYPE_INT, $option->type );
+        $this->assertEquals( 10, $option->default );
+        $this->assertTrue( $option->multiple );
+        $this->assertEquals( "Shorthelp", $option->shorthelp );
+        $this->assertEquals( "Longhelp", $option->longhelp );
+        $this->assertFalse( $option->arguments );
+        $this->assertTrue( $option->mandatory );
+        $this->assertTrue( $option->isHelpOption );
+    }
+    
+    public function testPropertySetAccessFailureShort()
+    {
+        $option = new ezcConsoleOption( "a", "aaa" );
+
+        try
+        {
+            $option->short = "b";
+        }
+        catch ( ezcBasePropertyPermissionException $e )
+        {
+            return;
+        }
+        $this->fail( "Exception not thrown on invalid value for 
ezcConsoleOption->short." );
+    }
+
+    public function testPropertySetAccessFailureLong()
+    {
+        $option = new ezcConsoleOption( "a", "aaa" );
+
+        try
+        {
+            $option->long = "bbb";
+        }
+        catch ( ezcBasePropertyPermissionException $e )
+        {
+            return;
+        }
+        $this->fail( "Exception not thrown on invalid value for 
ezcConsoleOption->long." );
+    }
+
+    public function testPropertySetAccessFailureType()
+    {
+        $option = new ezcConsoleOption( "a", "aaa" );
+
+        try
+        {
+            $option->type = "Invalid type";
+        }
+        catch ( ezcBaseValueException $e )
+        {
+            return;
+        }
+        $this->fail( "Exception not thrown on invalid value for 
ezcConsoleOption->type." );
+    }
+    
+    public function testPropertySetAccessFailureDefault()
+    {
+        $option = new ezcConsoleOption( "a", "aaa" );
+
+        try
+        {
+            $option->default = array();
+        }
+        catch ( ezcBaseValueException $e )
+        {
+            return;
+        }
+        $this->fail( "Exception not thrown on invalid value for 
ezcConsoleOption->default." );
+    }
+    
+    public function testPropertySetAccessFailureMultiple()
+    {
+        $option = new ezcConsoleOption( "a", "aaa" );
+
+        try
+        {
+            $option->multiple = array();
+        }
+        catch ( ezcBaseValueException $e )
+        {
+            return;
+        }
+        $this->fail( "Exception not thrown on invalid value for 
ezcConsoleOption->multiple." );
+    }
+    
+    public function testPropertySetAccessFailureShorthelp()
+    {
+        $option = new ezcConsoleOption( "a", "aaa" );
+
+        try
+        {
+            $option->shorthelp = array();
+        }
+        catch ( ezcBaseValueException $e )
+        {
+            return;
+        }
+        $this->fail( "Exception not thrown on invalid value for 
ezcConsoleOption->shorthelp." );
+    }
+
+    public function testPropertySetAccessFailureLonghelp()
+    {
+        $option = new ezcConsoleOption( "a", "aaa" );
+
+        try
+        {
+            $option->longhelp = array();
+        }
+        catch ( ezcBaseValueException $e )
+        {
+            return;
+        }
+        $this->fail( "Exception not thrown on invalid value for 
ezcConsoleOption->longhelp." );
+    }
+
+    public function testPropertySetAccessFailureArguments()
+    {
+        $option = new ezcConsoleOption( "a", "aaa" );
+
+        try
+        {
+            $option->arguments = array();
+        }
+        catch ( ezcBaseValueException $e )
+        {
+            return;
+        }
+        $this->fail( "Exception not thrown on invalid value for 
ezcConsoleOption->arguments." );
+    }
+
+    public function testPropertySetAccessFailureMandatory()
+    {
+        $option = new ezcConsoleOption( "a", "aaa" );
+
+        try
+        {
+            $option->mandatory = array();
+        }
+        catch ( ezcBaseValueException $e )
+        {
+            return;
+        }
+        $this->fail( "Exception not thrown on invalid value for 
ezcConsoleOption->mandatory." );
+    }
+
+    public function testPropertySetAccessFailureIsHelpOption()
+    {
+        $option = new ezcConsoleOption( "a", "aaa" );
+
+        try
+        {
+            $option->isHelpOption = array();
+        }
+        catch ( ezcBaseValueException $e )
+        {
+            return;
+        }
+        $this->fail( "Exception not thrown on invalid value for 
ezcConsoleOption->isHelpOption." );
+    }
+    
+    public function testPropertySetAccessFailureNonExistent()
+    {
+        $option = new ezcConsoleOption( "a", "aaa" );
+
+        try
+        {
+            $option->nonExistent = array();
+        }
+        catch ( ezcBasePropertyNotFoundException $e )
+        {
+            return;
+        }
+        $this->fail( "Exception not thrown on invalid value for 
ezcConsoleOption->nonExsitent." );
+    }
+
+    public function testPropertyIssetAccessSuccess()
+    {
+        $option = new ezcConsoleOption( "a", "aaa" );
+        
+        $this->assertTrue( isset( $option->type ) );
+        $this->assertFalse( isset( $option->default ) );
+        $this->assertTrue( isset( $option->multiple ) );
+        $this->assertTrue( isset( $option->shorthelp ) );
+        $this->assertTrue( isset( $option->longhelp ) );
+        $this->assertTrue( isset( $option->arguments ) );
+        $this->assertTrue( isset( $option->mandatory ) );
+        $this->assertTrue( isset( $option->isHelpOption ) );
+        $this->assertFalse( isset(  $option->nonExistent ) );
+
+    }
 }
 
 ?>

Modified: trunk/ConsoleTools/tests/suite.php
===================================================================
--- trunk/ConsoleTools/tests/suite.php  2006-09-24 11:51:40 UTC (rev 3559)
+++ trunk/ConsoleTools/tests/suite.php  2006-09-24 15:27:52 UTC (rev 3560)
@@ -30,6 +30,10 @@
  */
 require_once 'input_test.php';
 /**
+ * Require test suite for ezcConsoleOption class.
+ */
+require_once 'option_test.php';
+/**
  * Require test suite for ezcConsoleTable class.
  */
 require_once 'table_test.php';
@@ -88,6 +92,7 @@
                $this->addTest( ezcConsoleToolsOutputFormatsTest::suite() );
                $this->addTest( ezcConsoleToolsOutputOptionsTest::suite() );
                $this->addTest( ezcConsoleToolsInputTest::suite() );
+               $this->addTest( ezcConsoleToolsOptionTest::suite() );
                $this->addTest( ezcConsoleToolsTableCellTest::suite() );
                $this->addTest( ezcConsoleToolsTableRowTest::suite() );
                $this->addTest( ezcConsoleToolsTableTest::suite() );

-- 
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components

Reply via email to