Author: Tobias Schlitt
Date: 2006-01-29 11:25:49 +0100 (Sun, 29 Jan 2006)
New Revision: 2077

Log:
- Fix unreported bug: ezcConsoleTable "colWrap" option not recognized correctly.
- Fix test case accoridingly.
- Fix unreported bug: ezcConsoleTable "defaultFormat" and "defaultBorderFormat" 
not recognized.
- Added test cases for all options of ezcConsoleTable.

Modified:
   packages/ConsoleTools/trunk/src/structs/table_options.php
   packages/ConsoleTools/trunk/tests/data/testTable4c.dat
   packages/ConsoleTools/trunk/tests/table_test.php

Modified: packages/ConsoleTools/trunk/src/structs/table_options.php
===================================================================
--- packages/ConsoleTools/trunk/src/structs/table_options.php   2006-01-28 
23:17:32 UTC (rev 2076)
+++ packages/ConsoleTools/trunk/src/structs/table_options.php   2006-01-29 
10:25:49 UTC (rev 2077)
@@ -121,16 +121,16 @@
         $defaultBorderFormat = 'default'
     )
     {
-        $this->colWidth = $colWidth;
-        $this->colWrap = $colWrap;
-        $this->defaultAlign = $defaultAlign;
-        $this->colPadding = $colPadding;
-        $this->widthType = $widthType;
-        $this->lineVertical = $lineVertical;
-        $this->lineHorizontal = $lineHorizontal;
-        $this->corner = $corner;
-        $this->defaultFormat = $defaultFormat;
-        $this->defaultBorderFormat = $defaultBorderFormat;
+        $this->__set( 'colWidth', $colWidth );
+        $this->__set( 'colWrap', $colWrap );
+        $this->__set( 'defaultAlign', $defaultAlign );
+        $this->__set( 'colPadding', $colPadding );
+        $this->__set( 'widthType', $widthType );
+        $this->__set( 'lineVertical', $lineVertical );
+        $this->__set( 'lineHorizontal', $lineHorizontal );
+        $this->__set( 'corner', $corner );
+        $this->__set( 'defaultFormat', $defaultFormat );
+        $this->__set( 'defaultBorderFormat', $defaultBorderFormat );
     }
     
     /**
@@ -168,7 +168,7 @@
         switch ( $propertyName )
         {
             case 'colWidth':
-                if ( !is_array( $val ) && !is_string( $val ) && $val !== 
'auto' )
+                if ( !is_array( $val ) && is_string( $val ) && $val !== 'auto' 
)
                 {
                     throw new ezcBaseSettingValueException( $propertyName, 
$val, 'array(int) or "auto"' );
                 }
@@ -205,6 +205,18 @@
                     throw new ezcBaseSettingValueException( $propertyName, 
$val, 'string, length = 1' );
                 }
                 break;
+            case 'defaultFormat':
+                if ( !is_string( $val ) || strlen( $val ) < 1 )
+                {
+                    throw new ezcBaseSettingValueException( $propertyName, 
$val, 'string, length = 1' );
+                }
+                break;
+            case 'defaultBorderFormat':
+                if ( !is_string( $val ) || strlen( $val ) < 1 )
+                {
+                    throw new ezcBaseSettingValueException( $propertyName, 
$val, 'string, length = 1' );
+                }
+                break;
             default:
                 throw new ezcBaseSettingNotFoundException( $propertyName );
         }

Modified: packages/ConsoleTools/trunk/tests/data/testTable4c.dat
===================================================================
--- packages/ConsoleTools/trunk/tests/data/testTable4c.dat      2006-01-28 
23:17:32 UTC (rev 2076)
+++ packages/ConsoleTools/trunk/tests/data/testTable4c.dat      2006-01-29 
10:25:49 UTC (rev 2077)
@@ -1,9 +1,9 @@
 
+-----------------------------+-----------------------------+-----------------------------+-----------------------------+
-| Some very very long data here.... and it becomes even much 
much longer... and even longer.... |            Short        
    | Some very very long data here.... and it becomes even 
much much longer... and even longer.... |            Short   
         |
+| Some very very long data he |           
 Short            | Some very very long data he 
|            Short            |
 
+-----------------------------+-----------------------------+-----------------------------+-----------------------------+
-|            Short            | Some very very 
long data here.... |            Short            | 
Some very very long data here.... and it becomes even much much longer... 
and even longer.... |
+|            Short            | Some very very 
long data he |            Short            | 
Some very very long data he |
 |                             |                    
         |                             |        
                     |
-|                             | and it becomes 
even much much longer... |                             
|                             |
+|                             | and it becomes 
even much mu |                             |    
                         |
 |                             |                    
         |                             |        
                     |
 |                             |     and even 
longer....     |                             |  
                           |
 
+-----------------------------+-----------------------------+-----------------------------+-----------------------------+
\ No newline at end of file

Modified: packages/ConsoleTools/trunk/tests/table_test.php
===================================================================
--- packages/ConsoleTools/trunk/tests/table_test.php    2006-01-28 23:17:32 UTC 
(rev 2076)
+++ packages/ConsoleTools/trunk/tests/table_test.php    2006-01-29 10:25:49 UTC 
(rev 2077)
@@ -183,7 +183,7 @@
             __FUNCTION__,
             $this->tableData4,
             array( 'cols' => count( $this->tableData4[0] ), 'width' =>  120 ),
-            array( 'lineFormatHead' => 'blue', 'defaultAlign' => 
ezcConsoleTable::ALIGN_CENTER, 'colWrap' => ezcConsoleTable::WRAP_NONE ),
+            array( 'lineFormatHead' => 'blue', 'defaultAlign' => 
ezcConsoleTable::ALIGN_CENTER, 'colWrap' => ezcConsoleTable::WRAP_CUT ),
             array( 0 )
         );
     }
@@ -247,7 +247,202 @@
         $table = new ezcConsoleTable( $this->output, 100 );
         $table[0];
     }
+
+    public function testSetOptions_Success1()
+    {
+        $out = new ezcConsoleOutput();
+        $table = new ezcConsoleTable( $out, 100 );
+        try
+        {
+            $table->options->colWidth = array( 1, 2, 3 );
+            $table->options->colWrap = ezcConsoleTable::WRAP_CUT;
+            $table->options->defaultAlign = ezcConsoleTable::ALIGN_CENTER;
+            $table->options->colPadding = ':';
+            $table->options->widthType = ezcConsoleTable::WIDTH_FIXED;
+            $table->options->lineVertical = ':';
+            $table->options->lineHorizontal = '-';
+            $table->options->corner = 'o';
+            $table->options->defaultFormat = 'test';
+            $table->options->defaultBorderFormat = 'test2';
+        }
+        catch ( Exception $e )
+        {
+            $this->fail( "Exception while setting valid option: 
{$e->getMessage()}." );
+        }
+    }
     
+    public function testSetOptions_Success2()
+    {
+        try
+        {
+            $opt = new ezcConsoleTableOptions(
+                array( 1, 2, 3 ),
+                ezcConsoleTable::WRAP_CUT,
+                ezcConsoleTable::ALIGN_CENTER,
+                ':',
+                ezcConsoleTable::WIDTH_FIXED,
+                ':',
+                '-',
+                'o',
+                'test',
+                'test2'
+            );
+        }
+        catch ( Exception $e )
+        {
+            $this->fail( "Exception while setting valid option: 
{$e->getMessage()}." );
+        }
+    }
+    
+    public function testSetOptions_Failure()
+    {
+        $out = new ezcConsoleOutput();
+        $table = new ezcConsoleTable( $out, 100 );
+    
+        $exceptionThrown = false;
+        
+        try
+        {
+            $table->options->colWidth = 'test';
+        } 
+        catch ( ezcBaseSettingValueException $e)
+        {
+            $exceptionThrown = true;
+        }
+        if ( !$exceptionThrown )
+        {
+            $this->fail( 'No exception thrown on invalid setting for 
<colWidth>.');
+        }
+        $exceptionThrown = false;
+
+        try
+        {
+            $table->options->colWrap = 100;
+        } 
+        catch ( ezcBaseSettingValueException $e)
+        {
+            $exceptionThrown = true;
+        }
+        if ( !$exceptionThrown )
+        {
+            $this->fail( 'No exception thrown on invalid setting for 
<colWrap>.');
+        }
+        $exceptionThrown = false;
+        
+        try
+        {
+            $table->options->defaultAlign = 101;
+        } 
+        catch ( ezcBaseSettingValueException $e)
+        {
+            $exceptionThrown = true;
+        }
+        if ( !$exceptionThrown )
+        {
+            $this->fail( 'No exception thrown on invalid setting for 
<defaultAlign>.');
+        }
+        $exceptionThrown = false;
+        
+        try
+        {
+            $table->options->colPadding = 102;
+        } 
+        catch ( ezcBaseSettingValueException $e)
+        {
+            $exceptionThrown = true;
+        }
+        if ( !$exceptionThrown )
+        {
+            $this->fail( 'No exception thrown on invalid setting for 
<colPadding>.');
+        }
+        $exceptionThrown = false;
+        
+        try
+        {
+            $table->options->widthType = 103;
+        } 
+        catch ( ezcBaseSettingValueException $e)
+        {
+            $exceptionThrown = true;
+        }
+        if ( !$exceptionThrown )
+        {
+            $this->fail( 'No exception thrown on invalid setting for 
<widthType>.');
+        }
+        $exceptionThrown = false;
+        
+        try
+        {
+            $table->options->lineVertical = 104;
+        } 
+        catch ( ezcBaseSettingValueException $e)
+        {
+            $exceptionThrown = true;
+        }
+        if ( !$exceptionThrown )
+        {
+            $this->fail( 'No exception thrown on invalid setting for 
<lineVertical>.');
+        }
+        $exceptionThrown = false;
+        
+        try
+        {
+            $table->options->lineHorizontal = 105;
+        } 
+        catch ( ezcBaseSettingValueException $e)
+        {
+            $exceptionThrown = true;
+        }
+        if ( !$exceptionThrown )
+        {
+            $this->fail( 'No exception thrown on invalid setting for 
<lineHorizontal>.');
+        }
+        $exceptionThrown = false;
+        
+        try
+        {
+            $table->options->corner = 106;
+        } 
+        catch ( ezcBaseSettingValueException $e)
+        {
+            $exceptionThrown = true;
+        }
+        if ( !$exceptionThrown )
+        {
+            $this->fail( 'No exception thrown on invalid setting for 
<corner>.');
+        }
+        $exceptionThrown = false;
+        
+        try
+        {
+            $table->options->defaultFormat = array();
+        } 
+        catch ( ezcBaseSettingValueException $e)
+        {
+            $exceptionThrown = true;
+        }
+        if ( !$exceptionThrown )
+        {
+            $this->fail( 'No exception thrown on invalid setting for 
<defaultFormat>.');
+        }
+        $exceptionThrown = false;
+        
+        try
+        {
+            $table->options->defaultBorderFormat = true;
+        }
+        catch ( ezcBaseSettingValueException $e)
+        {
+            $exceptionThrown = true;
+        }
+        if ( !$exceptionThrown )
+        {
+            $this->fail( 'No exception thrown on invalid setting for 
<defaultBorderFormat>.');
+        }
+        $exceptionThrown = false;
+        
+    }
+    
     private function commonTableTest( $refFile, $tableData, $settings, 
$options, $headrows = array() )
     {
         $table =  new ezcConsoleTable( 
@@ -283,12 +478,22 @@
             $table[$row]->borderFormat = isset( $options['lineFormatHead'] ) ? 
$options['lineFormatHead'] : 'default';
         }
         
+        // For visual inspection, uncomment this block
+//        echo "\n\n";
+//        echo "Old $refFile:\n:";
+//        echo file_get_contents( dirname( __FILE__ ) . '/data/' . $refFile . 
'.dat' );
+//        echo "New $refFile:\n:";
+//        echo implode( "\n", $table->getTable() );
+//        echo "\n\n";
+        
+        // For test assertion, uncomment this block
         $this->assertEquals(
             file_get_contents( dirname( __FILE__ ) . '/data/' . $refFile . 
'.dat' ),
             implode( "\n", $table->getTable() ),
             'Table not correctly generated for ' . $refFile . '.'
         );
-        // To prepare test files use this:
+
+        // To prepare test files, uncomment this block
         // file_put_contents( dirname( __FILE__ ) . '/data/' . $refFile . 
'.dat', implode( "\n", $table->getTable() ) );
     }
 }

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

Reply via email to