- added Ethna_Plugin_Validator_Mbregexp test code.
- ソースコード全体を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 に置き換わります。よって、古いバージョンから移行する場合はディレクトリ名の変更が必要です。
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) {
--- /dev/null
+<?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'));
+ }
+ // }}}
+}
+// }}}
+
+?>
--- /dev/null
+<?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'));
+ }
+ // }}}
+
+}
+// }}}
+
+?>