OSDN Git Service

- added Validator Required and Filter Test.
authormumumu-org <mumumu-org@2ef88817-412d-0410-a32c-8029a115e976>
Sat, 24 May 2008 21:21:17 +0000 (21:21 +0000)
committermumumu-org <mumumu-org@2ef88817-412d-0410-a32c-8029a115e976>
Sat, 24 May 2008 21:21:17 +0000 (21:21 +0000)
test/Ethna_ActionForm_Filter_Test.php [new file with mode: 0644]
test/Ethna_ActionForm_Validator_Required_Test.php [new file with mode: 0644]

diff --git a/test/Ethna_ActionForm_Filter_Test.php b/test/Ethna_ActionForm_Filter_Test.php
new file mode 100644 (file)
index 0000000..3c3664e
--- /dev/null
@@ -0,0 +1,202 @@
+<?php
+// vim: foldmethod=marker
+/**
+ *  Ethna_ActionForm_Filter_Test.php
+ *
+ *  @author     Yoshinari Takaoka <takaoka@beatcraft.com>
+ *  @version    $Id$
+ */
+
+// {{{    Ethna_FilterTest_ActionForm
+/**
+ *  Test ActionForm For Filter 
+ *
+ *  @access public
+ */
+class Ethna_FilterTest_ActionForm extends Ethna_ActionForm
+{
+    var $form = array(
+        'test' => array(
+            'type' => VAR_TYPE_STRING,
+            'form_type' => FORM_TYPE_TEXT,
+            'name' => 'test',
+        ),
+    );
+
+    //    user defined filter
+    function _filter_toupper($value)
+    {
+        return strtoupper($value); 
+    }
+
+    function _filter_tolower($value)
+    {
+        return strtolower($value); 
+    }
+}
+// }}}
+
+// {{{    Ethna_ActionForm_Filter_Test
+/**
+ *  Test Case For Ethna_ActionForm(Filter)
+ *
+ *  @access public
+ */
+class Ethna_ActionForm_Filter_Test extends Ethna_UnitTestBase
+{
+    var $local_af;
+
+    function setUp()
+    {
+        $this->local_af = new Ethna_FilterTest_ActionForm($this->ctl); 
+        $this->local_af->clearFormVars();
+        $this->ae->clear();
+    }
+
+    // {{{ FILTER_FW Test
+    function test_filter_fw()
+    {
+        //   半角カナ -> 全角カナ + ntrim 
+        $this->local_af->form['test']['filter'] = FILTER_FW;
+        $this->local_af->set('test', "\x00アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロン\x00");
+        $this->local_af->validate();
+        $filtered_value = $this->local_af->get('test');
+        $this->assertEqual('アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロン', $filtered_value);
+        $this->ae->clear();
+    }
+    // }}}
+
+    // {{{ FILTER_HW Test
+    function test_filter_hw()
+    {
+        //   全角英数字 -> 半角英数字 + ntrim + rtrim + ltrim
+        $this->local_af->form['test']['filter'] = FILTER_HW;
+        $this->local_af->set('test', " \t\n\r\0\x0B AB\x00CDEFG0123\x00456789\t\n\r\0\x0B ");
+        $this->local_af->validate();
+        $filtered_value = $this->local_af->get('test');
+        $this->assertEqual('ABCDEFG0123456789', $filtered_value);
+    }
+    // }}}
+
+    // {{{ FILTER alnum_zentohan 
+    function test_filter_alnum_zentohan()
+    {
+        //  全角英数字->半角英数字
+        $this->local_af->form['test']['filter'] = 'alnum_zentohan'; 
+        $this->local_af->set('test', "ABCDEFG0123456789");
+        $this->local_af->validate();
+        $filtered_value = $this->local_af->get('test');
+        $this->assertEqual('ABCDEFG0123456789', $filtered_value);
+    }
+    // }}}
+
+    // {{{ FILTER numeric_zentohan 
+    function test_filter_numeric_zentohan()
+    {
+        //  全角数字->半角数字
+        $this->local_af->form['test']['filter'] = 'numeric_zentohan'; 
+        $this->local_af->set('test', "0123456789");
+        $this->local_af->validate();
+        $filtered_value = $this->local_af->get('test');
+        $this->assertEqual('0123456789', $filtered_value);
+    }
+    // }}}
+
+    // {{{ FILTER alphabet_zentohan 
+    function test_filter_alphabet_zentohan()
+    {
+        //  全角英字->半角英字(大文字)
+        $this->local_af->form['test']['filter'] = 'alnum_zentohan'; 
+        $this->local_af->set('test', "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
+        $this->local_af->validate();
+        $filtered_value = $this->local_af->get('test');
+        $this->assertEqual('ABCDEFGHIJKLMNOPQRSTUVWXYZ', $filtered_value);
+        $this->ae->clear();
+
+        //  全角英字->半角英字(小文字)
+        $this->local_af->form['test']['filter'] = 'alnum_zentohan'; 
+        $this->local_af->set('test', "abcdefghijklmnopqrstuvwxyz");
+        $this->local_af->validate();
+        $filtered_value = $this->local_af->get('test');
+        $this->assertEqual('abcdefghijklmnopqrstuvwxyz', $filtered_value);
+    }
+    // }}}
+
+    // {{{ FILTER ltrim
+    function test_filter_ltrim()
+    {
+        //    ltrim は全角スペースを除けないので注意!!!
+        //    Ethna はデフォルトの文字のみを除きます
+        //    @see http://jp.php.net/ltrim
+        $this->local_af->form['test']['filter'] = 'ltrim'; 
+        $this->local_af->set('test', " \t\n\r\0\x0Bhoge");
+        $this->local_af->validate();
+        $filtered_value = $this->local_af->get('test');
+        $this->assertEqual('hoge', $filtered_value);
+    }
+    // }}}
+
+    // {{{ FILTER rtrim
+    function test_filter_rtrim()
+    {
+        //    rtrim は全角スペースを除けないので注意!!!
+        //    Ethna はデフォルトの文字のみを除きます
+        //    @see http://jp.php.net/rtrim
+        $this->local_af->form['test']['filter'] = 'rtrim'; 
+        $this->local_af->set('test', "hoge \t\n\r\0\x0B");
+        $this->local_af->validate();
+        $filtered_value = $this->local_af->get('test');
+        $this->assertEqual('hoge', $filtered_value);
+    }
+    // }}}
+
+    // {{{ FILTER ntrim
+    function test_filter_ntrim()
+    {
+        $this->local_af->form['test']['filter'] = 'ntrim'; 
+        $this->local_af->set('test', "\x00hoge\x00\x00");
+        $this->local_af->validate();
+        $filtered_value = $this->local_af->get('test');
+        $this->assertEqual('hoge', $filtered_value);
+    }
+    // }}}
+
+    // {{{ FILTER kana_hantozen 
+    function test_filter_kana_hantozen()
+    {
+        //  半角カナ->全角カナ
+        $this->local_af->form['test']['filter'] = 'kana_hantozen'; 
+        $this->local_af->set('test', 'アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロン');
+        $this->local_af->validate();
+        $filtered_value = $this->local_af->get('test');
+        $this->assertEqual('アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロン', $filtered_value);
+    }
+    // }}}
+
+    // {{{ one custom filter 
+    function test_filter_custom_toupper()
+    {
+        //  小文字を大文字へ
+        $this->local_af->form['test']['filter'] = 'toupper'; 
+        $this->local_af->set('test', 'abcdefghijklmnopqrstuvwxyz');
+        $this->local_af->validate();
+        $filtered_value = $this->local_af->get('test');
+        $this->assertEqual('ABCDEFGHIJKLMNOPQRSTUVWXYZ', $filtered_value);
+    }
+    // }}}
+
+    // {{{ multiple custom filter 
+    function test_filter_custom_multiple()
+    {
+        //  小文字を大文字へ、そして元に戻す
+        $this->local_af->form['test']['filter'] = 'toupper,tolower'; 
+        $this->local_af->set('test', 'abcdefghijklmnopqrstuvwxyz');
+        $this->local_af->validate();
+        $filtered_value = $this->local_af->get('test');
+        $this->assertEqual('abcdefghijklmnopqrstuvwxyz', $filtered_value);
+    }
+    // }}}
+}
+// }}}
+
+?>
diff --git a/test/Ethna_ActionForm_Validator_Required_Test.php b/test/Ethna_ActionForm_Validator_Required_Test.php
new file mode 100644 (file)
index 0000000..192e950
--- /dev/null
@@ -0,0 +1,142 @@
+<?php
+// vim: foldmethod=marker
+/**
+ *  Ethna_ActionForm_Validator_Required_Test.php
+ *
+ *  @author     Yoshinari Takaoka <takaoka@beatcraft.com>
+ *  @version    $Id$
+ */
+
+// {{{    Ethna_ActionForm_Validator_Required_Test
+/**
+ *  Test Case For Ethna_ActionForm(Required Validator)
+ *
+ *  @access public
+ */
+class Ethna_ActionForm_Validator_Required_Test extends Ethna_UnitTestBase
+{
+    function setUp()
+    {
+        $this->af->use_validator_plugin = false;
+        $this->af->clearFormVars();
+        $this->af->form = array();
+        $this->ae->clear();
+    }
+
+    // {{{ Validator Required Integer. 
+    function test_Validate_Required_Integer()
+    {
+        $form_def = array(
+                        'type' => VAR_TYPE_INT,
+                        'form_type' => FORM_TYPE_TEXT,
+                        'required' => true,
+                    );        
+        $this->af->setDef('input', $form_def);
+        
+        $this->af->validate();
+        $this->assertTrue($this->ae->isError('input'));
+        $this->ae->clear();
+        $this->af->set('input', 5);
+        $this->af->validate();
+        $this->assertFalse($this->ae->isError('input'));
+        $this->ae->clear();
+
+        $this->af->set('input', null); 
+        $this->af->validate();
+        $this->assertTrue($this->ae->isError('input'));
+    }
+    // }}}
+
+    // {{{ Validator Required Float. 
+    function test_Validate_Required_Float()
+    {
+        $form_def = array(
+                        'type' => VAR_TYPE_FLOAT,
+                        'form_type' => FORM_TYPE_TEXT,
+                        'required' => true,
+                    );        
+        $this->af->setDef('input', $form_def);
+        
+        $this->af->validate();
+        $this->assertTrue($this->ae->isError('input'));
+        $this->ae->clear();
+        $this->af->set('input', 4.999999); 
+        $this->af->validate();
+        $this->assertFalse($this->ae->isError('input'));
+        $this->ae->clear();
+
+        $this->af->set('input', null); 
+        $this->af->validate();
+        $this->assertTrue($this->ae->isError('input'));
+    }
+    // }}}
+
+    // {{{ Validator Required Datetime. 
+    function test_Validate_Required_DateTime()
+    {
+        $form_def = array(
+                        'type' => VAR_TYPE_DATETIME,
+                        'form_type' => FORM_TYPE_TEXT,
+                        'required' => true,
+                    );        
+        $this->af->setDef('input', $form_def);
+        
+        $this->af->validate();
+        $this->assertTrue($this->ae->isError('input'));
+        $this->ae->clear();
+        $this->af->set('input', '1999-12-31'); 
+        $this->af->validate();
+        $this->assertFalse($this->ae->isError('input'));
+        $this->ae->clear();
+
+        $this->af->set('input', null); 
+        $this->af->validate();
+        $this->assertTrue($this->ae->isError('input'));
+    }
+    // }}}
+
+    // {{{ Validator Required String. 
+    function test_Validate_Min_String()
+    {
+        $form_def = array(
+                        'type' => VAR_TYPE_STRING,
+                        'form_type' => FORM_TYPE_TEXT,
+                        'required' => true,
+                    );        
+        $this->af->setDef('input', $form_def);
+        
+        $this->af->validate();
+        $this->assertTrue($this->ae->isError('input'));
+        $this->ae->clear();
+        $this->af->set('input', 'ああああ'); 
+        $this->af->validate();
+        $this->assertFalse($this->ae->isError('input'));
+        $this->ae->clear();
+
+        $this->af->set('input', 'abcd'); 
+        $this->af->validate();
+        $this->assertFalse($this->ae->isError('input'));
+        $this->ae->clear();
+
+        $this->af->set('input', null); 
+        $this->af->validate();
+        $this->assertTrue($this->ae->isError('input'));
+    }
+    // }}}
+
+    // {{{ Validator Max File. 
+    function test_Validate_Max_File()
+    {
+        //  skipped because we can't bypass 
+        //  is_uploaded_file function.
+    }
+    // }}}
+
+}
+// }}}
+
+?>