OSDN Git Service

- changed default encoding of Ethna_Plugin_Validator_Mbregexp is now UTF-8 which...
authormumumu-org <mumumu-org@2ef88817-412d-0410-a32c-8029a115e976>
Sat, 24 May 2008 22:24:26 +0000 (22:24 +0000)
committermumumu-org <mumumu-org@2ef88817-412d-0410-a32c-8029a115e976>
Sat, 24 May 2008 22:24:26 +0000 (22:24 +0000)
- added Ethna_Plugin_Validator_Mbregexp test code.

CHANGES
class/Plugin/Validator/Ethna_Plugin_Validator_Mbregexp.php
test/Ethna_ActionForm_Validator_Mbregexp_Test.php [new file with mode: 0644]
test/Ethna_Plugin_Validator_Mbregexp_Test.php [new file with mode: 0644]

diff --git a/CHANGES b/CHANGES
index 66f40d5..dccb9f8 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -6,10 +6,13 @@
 
 - ソースコード全体をUTF-8化
 -- 但し、日本語のソースコードコメントはそのまま
--- [Breaking B.C] フレームワークで扱う内部エンコーディング(mb_internal_encoding)もUTF-8に変更。但し、これは Ethna_Controller#_getDefaultLanguage
+-- [Breaking B.C] フレームワークで扱う内部エンコーディング(mb_internal_encoding)もデフォルトはUTF-8に変更。但し、これは Ethna_Controller#_getDefaultLanguage
    をオーバーライドし、クライアントエンコーディングの値を変えることで変更可能です。
 -- 内部エンコーディングの変更に伴い、動作しなくなった箇所を修正
 --- Ethna_Plugin_Validator_Min.php
+--- Ethna_Plugin_Validator_Max.php
+-- 内部エンコーディングの変更に伴う動作の変更
+--- Ethna_Plugin_Validator_Mbregexp のデフォルトのエンコーディングは、クライアントエンコーディングが仮定されます。デフォルトはUTF-8です。
 - 国際化 (i18n) のための機能追加および変更
 -- [Breaking B.C] 言語名として解釈していた部分をロケール名に変更
 --- これにより、[appid]template/ja, [appid]/locale/ja の「ja」の部分が ja_JP に置き換わります。よって、古いバージョンから移行する場合はディレクトリ名の変更が必要です。
index a8bb27a..978c8b9 100644 (file)
@@ -29,9 +29,11 @@ class Ethna_Plugin_Validator_Mbregexp extends Ethna_Plugin_Validator
             return $true;
         }
 
+        $ctl =& $this->backend->getController();
+        list($locale, $sys_enc, $cli_enc) = $ctl->_getDefaultLanguage();
         $encoding = (isset($params['encoding']))
                   ? $params['encoding']
-                  : 'UTF-8';
+                  : $cli_enc;
         mb_regex_encoding($encoding);
 
         if (mb_ereg($params['mbregexp'], $var) !== 1) {
diff --git a/test/Ethna_ActionForm_Validator_Mbregexp_Test.php b/test/Ethna_ActionForm_Validator_Mbregexp_Test.php
new file mode 100644 (file)
index 0000000..6af83a4
--- /dev/null
@@ -0,0 +1,62 @@
+<?php
+// vim: foldmethod=marker
+/**
+ *  Ethna_ActionForm_Validator_Mbregexp_Test.php
+ *
+ *  @author     Yoshinari Takaoka <takaoka@beatcraft.com>
+ *  @version    $Id$
+ */
+
+// {{{    Ethna_ActionForm_Validator_Mbregexp_Test
+/**
+ *  Test Case For Ethna_ActionForm(Mbregexp Validator)
+ *
+ *  @access public
+ */
+class Ethna_ActionForm_Validator_Mbregexp_Test extends Ethna_UnitTestBase
+{
+    function setUp()
+    {
+        $this->af->use_validator_plugin = false;
+        $this->af->clearFormVars();
+        $this->af->form = array();
+        $this->ae->clear();
+    }
+
+    // {{{ Validator Mbregexp. 
+    function test_Validate_Regexp()
+    {
+        $form_def = array(
+                        'type' => VAR_TYPE_STRING,
+                        'form_type' => FORM_TYPE_TEXT,
+                        'required' => true,
+                        'mbregexp' => '^[あ-ん]+$',
+                    );        
+        $this->af->setDef('input', $form_def);
+        
+        $this->af->set('input', 'a5A4Pgw9');
+        $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', 1459); 
+        $this->af->validate();
+        $this->assertTrue($this->ae->isError('input'));
+        $this->ae->clear();
+
+        //    encoding に指定された文字コード以外の文字列
+        $euc_input = mb_convert_encoding('あいうえお', 'EUC-JP', 'UTF-8');
+        $this->af->set('input', $euc_input);
+        $this->af->validate();
+        $this->assertTrue($this->ae->isError('input'));
+    }
+    // }}}
+}
+// }}}
+
+?>
diff --git a/test/Ethna_Plugin_Validator_Mbregexp_Test.php b/test/Ethna_Plugin_Validator_Mbregexp_Test.php
new file mode 100644 (file)
index 0000000..f4dc88b
--- /dev/null
@@ -0,0 +1,55 @@
+<?php
+// vim: foldmethod=marker
+/**
+ *  Ethna_Plugin_Validator_Mbregexp_Test.php
+ *
+ *  @author     Yoshinari Takaoka <takaoka@beatcraft.com>
+ *  @version    $Id$
+ */
+
+// {{{    Ethna_Plugin_Validator_Mbregexp_Test
+/**
+ *  Test Case For Ethna_ActionForm(Mbegexp Validator)
+ *
+ *  @access public
+ */
+class Ethna_Plugin_Validator_Mbregexp_Test extends Ethna_UnitTestBase
+{
+    var $vld;
+
+    function setUp()
+    {
+        $ctl =& Ethna_Controller::getInstance();
+        $plugin =& $ctl->getPlugin();
+        $this->vld = $plugin->getPlugin('Validator', 'Mbregexp');
+    }
+
+    // {{{ Validator Mbregexp. 
+    function test_Validate_Mbregexp()
+    {
+        $form_def = array(
+                        'type' => VAR_TYPE_STRING,
+                        'form_type' => FORM_TYPE_TEXT,
+                        'required' => true,
+                        'mbregexp' => '^[あ-ん]+$',  // 全角ひらがなonly
+                        'mbregexp_encoding' => 'UTF-8',
+                    );        
+
+        $this->vld->af->setDef('input', $form_def);
+        $pear_error = $this->vld->validate('input', 9, $form_def);
+        $this->assertTrue(is_a($pear_error, 'PEAR_Error'));
+
+        $pear_error = $this->vld->validate('input', 'あいう', $form_def);
+        $this->assertFalse(is_a($pear_error, 'PEAR_Error'));
+
+        //    encoding に指定された文字コード以外の文字列
+        $euc_input = mb_convert_encoding('あいう', 'EUC-JP', 'UTF-8');
+        $pear_error = $this->vld->validate('input', $euc_input, $form_def);
+        $this->assertTrue(is_a($pear_error, 'PEAR_Error'));
+    }
+    // }}}
+
+}
+// }}}
+
+?>