OSDN Git Service

- fixed missed 'selected="selected"' fix.
authormumumu-org <mumumu-org@2ef88817-412d-0410-a32c-8029a115e976>
Fri, 1 Aug 2008 23:58:49 +0000 (23:58 +0000)
committermumumu-org <mumumu-org@2ef88817-412d-0410-a32c-8029a115e976>
Fri, 1 Aug 2008 23:58:49 +0000 (23:58 +0000)
CHANGES
class/Ethna_SmartyPlugin.php
test/Ethna_SmartyPlugin_Test.php

diff --git a/CHANGES b/CHANGES
index 918f7f2..4d0bb5f 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -8,6 +8,7 @@
   1. PEAR が PEAR2 に移行するに伴い、APIが不安定になること
   2. Ethna が依存している PEAR_Error は既に非推奨であること
   3. 外部ライブラリにできうる限り依存しない方がユーザの便宜となる
+  4. PEAR に依存していると、PHPライセンスと抵触しているライセンスで配布できない
 -- Console_Getopt の代替として、Ethna_Getopt.php を追加 (Public Domain)
 -- 性質上依存せざるを得ない以下のファイルを除き、Console_Getopt への依存を排除
 --- ETHNA_BASE/bin/ethna_make_package.php
@@ -19,6 +20,7 @@
 *** bug fix
 
 - テストディレクトリの変更のタイミングによっては、Ethna_UnitTestMangerがWARNINGを出す問題を回避 (thanks: maru_cc)
+- selected="selected" の修正漏れを修正 (thanks:maru_cc) 
 
 ** 2.5.0-preview1
 
index e9feace..4c09b7e 100644 (file)
@@ -360,7 +360,7 @@ function smarty_modifier_checkbox($string)
  *  <option value="2" {$form|select:"2"}>bar</option>
  *  </code>
  *  <code>
- *  <option value="1" selected>foo</option>
+ *  <option value="1" selected="selected">foo</option>
  *  <option value="2" >bar</option>
  *  </code>
  *
@@ -497,6 +497,24 @@ function smarty_function_uniqid($params, &$smarty)
 /**
  *  smarty function:セレクトフィールド生成
  *
+ *  sample:
+ *  <code>
+ *  $smarty->assign('hoge',
+ *                   array(
+ *                       '1' => array('name' => 'foo'),
+ *                       '2' => array('name' => 'bar')
+ *                   )
+ *  );
+ *  {select list=$hoge name="hoge" value="1" empty="-- please select --"}
+ *  </code>
+ *  <code>
+ *  <select name="hoge">
+ *    <option value="">-- please select --</option>
+ *    <option value="1" selected="selected">foo</option>
+ *    <option value="2">bar</option>
+ *  </select>
+ *  </code>
+ *
  *  @param  array   $list   選択肢一覧
  *  @param  string  $name   フォーム項目名
  *  @param  string  $value  セレクトボックスに渡されたフォーム値
@@ -507,12 +525,21 @@ function smarty_function_select($params, &$smarty)
 {
     extract($params);
 
+    //  empty="...." を加えると、無条件に追加される
+    //  ない場合は追加されない
     print "<select name=\"$name\">\n";
     if ($empty) {
         printf("<option value=\"\">%s</option>\n", $empty);
     }
     foreach ($list as $id => $elt) {
-        printf("<option value=\"%s\" %s>%s</option>\n", $id, $id == $value ? 'selected="true"' : '', $elt['name']);
+        //    標準に合わせる
+        //    @see http://www.w3.org/TR/html401/interact/forms.html#adef-selected
+        //    @see http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-transitional.dtd
+        //    @see http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-strict.dtd
+        //    @see http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-frameset.dtd
+        //    @see http://www.w3.org/TR/xhtml-modularization/abstract_modules.html#s_sformsmodule
+        printf("<option value=\"%s\" %s>%s</option>\n",
+               $id, $id == $value ? 'selected="selected"' : '', $elt['name']);
     }
     print "</select>\n";
 }
index 9ea0e30..c790b79 100644 (file)
@@ -7,7 +7,6 @@
  *  @version    $Id$
  */
 
-
 require_once ETHNA_BASE . '/class/Ethna_SmartyPlugin.php';
 
 //{{{    Ethna_SmartyPlugin_Test
@@ -18,6 +17,41 @@ require_once ETHNA_BASE . '/class/Ethna_SmartyPlugin.php';
  */
 class Ethna_SmartyPlugin_Test extends Ethna_UnitTestBase
 {
+    // {{{ test_smarty_function_select
+    function test_smarty_function_select()
+    {
+        $params = array('list'  => array(
+                                       '1' => array('name' => 'foo'),
+                                       'value' => array('name' => 'bar'),
+                                   ),
+                        'name'  => 'name',
+                        'value' => 'value',
+                        'empty' => false,
+                  );
+        $dummy_smarty = null;
+        $expected = "<select name=\"name\">\n"
+                  . "<option value=\"1\" >foo</option>\n"
+                  . "<option value=\"value\" selected=\"selected\">bar</option>\n"
+                  . "</select>\n";
+
+        ob_start();
+        smarty_function_select($params, $dummy_smarty);
+        $actual = ob_get_clean();
+        $this->assertEqual($expected, $actual); 
+
+        $params['empty'] = '-- please select --';
+        $expected = "<select name=\"name\">\n"
+                  . "<option value=\"\">-- please select --</option>\n"
+                  . "<option value=\"1\" >foo</option>\n"
+                  . "<option value=\"value\" selected=\"selected\">bar</option>\n"
+                  . "</select>\n";
+        ob_start();
+        smarty_function_select($params, $dummy_smarty);
+        $actual = ob_get_clean();
+        $this->assertEqual($expected, $actual); 
+    }
+    // }}}
+
     // {{{ test_smarty_modifier_select
     function test_smarty_modifier_select()
     {