Browse Source

Merge branch 'master' into 3.1

Mark Story 10 years ago
parent
commit
5f5d1e19db

+ 3 - 0
src/Database/Schema/PostgresSchema.php

@@ -85,6 +85,9 @@ class PostgresSchema extends BaseSchema
         if (strpos($col, 'timestamp') !== false) {
             return ['type' => 'timestamp', 'length' => null];
         }
+        if (strpos($col, 'time') !== false) {
+            return ['type' => 'time', 'length' => null];
+        }
         if ($col === 'serial' || $col === 'integer') {
             return ['type' => 'integer', 'length' => 10];
         }

+ 5 - 1
src/View/StringTemplate.php

@@ -238,7 +238,11 @@ class StringTemplate
         }
         $replace = [];
         foreach ($placeholders as $placeholder) {
-            $replace[] = isset($data[$placeholder]) ? $data[$placeholder] : null;
+            $replacement = isset($data[$placeholder]) ? $data[$placeholder] : null;
+            if (is_array($replacement)) {
+                $replacement = implode('', $replacement);
+            }
+            $replace[] = $replacement;
         }
         return vsprintf($template, $replace);
     }

+ 2 - 2
src/View/Widget/SelectBoxWidget.php

@@ -234,7 +234,7 @@ class SelectBoxWidget extends BasicWidget
             // Option groups
             $arrayVal = (is_array($val) || $val instanceof Traversable);
             if ((!is_int($key) && $arrayVal) ||
-                (is_int($key) && $arrayVal && isset($val['options']))
+                (is_int($key) && $arrayVal && (isset($val['options']) || !isset($val['value'])))
             ) {
                 $out[] = $this->_renderOptgroup($key, $val, $disabled, $selected, $templateVars, $escape);
                 continue;
@@ -246,7 +246,7 @@ class SelectBoxWidget extends BasicWidget
                 'text' => $val,
                 'templateVars' => [],
             ];
-            if (is_array($val) && isset($optAttrs['text'], $optAttrs['value'])) {
+            if (is_array($val) && isset($val['text'], $val['value'])) {
                 $optAttrs = $val;
                 $key = $optAttrs['value'];
             }

+ 13 - 0
tests/TestCase/Database/Schema/PostgresSchemaTest.php

@@ -72,6 +72,7 @@ body TEXT,
 author_id INTEGER NOT NULL,
 published BOOLEAN DEFAULT false,
 views SMALLINT DEFAULT 0,
+readingtime TIME,
 created TIMESTAMP,
 CONSTRAINT "content_idx" UNIQUE ("title", "body"),
 CONSTRAINT "author_idx" FOREIGN KEY ("author_id") REFERENCES "schema_authors" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
@@ -108,6 +109,10 @@ SQL;
                 'TIME',
                 ['type' => 'time', 'length' => null]
             ],
+            [
+                'TIME WITHOUT TIME ZONE',
+                ['type' => 'time', 'length' => null]
+            ],
             // Integer
             [
                 'SMALLINT',
@@ -330,6 +335,14 @@ SQL;
                 'comment' => null,
                 'autoIncrement' => null,
             ],
+            'readingtime' => [
+                'type' => 'time',
+                'null' => true,
+                'default' => null,
+                'length' => null,
+                'precision' => null,
+                'comment' => null,
+            ],
             'created' => [
                 'type' => 'timestamp',
                 'null' => true,

+ 25 - 0
tests/TestCase/View/StringTemplateTest.php

@@ -118,6 +118,31 @@ class StringTemplateTest extends TestCase
     }
 
     /**
+     * Formatting array data should not trigger errors.
+     *
+     * @return void
+     */
+    public function testFormatArrayData()
+    {
+        $templates = [
+            'link' => '<a href="{{url}}">{{text}}</a>'
+        ];
+        $this->template->add($templates);
+
+        $result = $this->template->format('link', [
+            'url' => '/',
+            'text' => ['example', 'text']
+        ]);
+        $this->assertEquals('<a href="/">exampletext</a>', $result);
+
+        $result = $this->template->format('link', [
+            'url' => '/',
+            'text' => ['key' => 'example', 'text']
+        ]);
+        $this->assertEquals('<a href="/">exampletext</a>', $result);
+    }
+
+    /**
      * Test loading templates files in the app.
      *
      * @return void

+ 42 - 0
tests/TestCase/View/Widget/SelectBoxWidgetTest.php

@@ -353,6 +353,48 @@ class SelectBoxWidgetTest extends TestCase
     }
 
     /**
+     * test rendering with numeric option group keys
+     *
+     * @return void
+     */
+    public function testRenderOptionGroupsIntegerKeys()
+    {
+        $select = new SelectBoxWidget($this->templates);
+        $data = [
+            'name' => 'Year[key]',
+            'options' => [
+                2014 => [
+                    'key' => 'value'
+                ],
+                2013 => [
+                    'text' => '2013-text',
+                    'options' => [
+                        'key2' => 'value2'
+                    ]
+                ]
+            ]
+        ];
+        $result = $select->render($data, $this->context);
+        $expected = [
+            'select' => [
+                'name' => 'Year[key]',
+            ],
+            ['optgroup' => ['label' => '2014']],
+            ['option' => ['value' => 'key']],
+            'value',
+            '/option',
+            '/optgroup',
+            ['optgroup' => ['label' => '2013-text']],
+            ['option' => ['value' => 'key2']],
+            'value2',
+            '/option',
+            '/optgroup',
+            '/select'
+        ];
+        $this->assertHtml($expected, $result);
+    }
+
+    /**
      * test rendering with option groups and escaping
      *
      * @return void