Browse Source

Comments updated
Removed sort and set defaults to limit if not in array checking
Break $out options

Iftekhar Eather 9 years ago
parent
commit
63770aa6a4

+ 10 - 11
src/View/Helper/PaginatorHelper.php

@@ -1172,12 +1172,11 @@ class PaginatorHelper extends Helper
     }
 
     /**
-     * dropdown array for Select limit
+     * Dropdown select for pagination limit
      *
-     * @param array $limits This is array of options.
-     * @param int|null $default Default limit for option selecting. Default value is $this->param('perPage').
+     * @param array $limits The options array.
+     * @param int|null $default Default option for pagination limit. Defaults to `$this->param('perPage')`.
      * @param array $options Options for Select tag attributes like class, id or event
-     *
      * @return string html output.
      */
     public function limitControl(array $limits = [], $default = null, array $options = [])
@@ -1196,13 +1195,13 @@ class PaginatorHelper extends Helper
             ];
         }
 
-        if (!in_array($default, $limits)) {
-            $limits += [$default => $default];
-        }
-
-        ksort($limits);
-
-        $out .= $this->Form->control('limit', ($options + ['type' => 'select', 'label' => __('View'), 'value' => $default, 'options' => $limits, 'onChange' => 'this.form.submit()']));
+        $out .= $this->Form->control('limit', $options + [
+                'type' => 'select',
+                'label' => __('View'),
+                'value' => $default,
+                'options' => $limits,
+                'onChange' => 'this.form.submit()'
+            ]);
         $out .= $this->Form->end();
 
         return $out;

+ 22 - 5
tests/TestCase/View/Helper/PaginatorHelperTest.php

@@ -2562,8 +2562,6 @@ class PaginatorHelperTest extends TestCase
             'View',
             '/label',
             ['select' => ['name' => 'limit', 'id' => 'limit', 'onChange' => 'this.form.submit()']],
-            ['option' => ['value' => '']],
-            '/option',
             ['option' => ['value' => '1']],
             '1',
             '/option',
@@ -2581,8 +2579,6 @@ class PaginatorHelperTest extends TestCase
             'View',
             '/label',
             ['select' => ['name' => 'limit', 'id' => 'limit', 'onChange' => 'this.form.submit()', 'class' => 'form-control']],
-            ['option' => ['value' => '']],
-            '/option',
             ['option' => ['value' => '1']],
             '1',
             '/option',
@@ -2603,8 +2599,29 @@ class PaginatorHelperTest extends TestCase
             'View',
             '/label',
             ['select' => ['name' => 'limit', 'id' => 'limit', 'onChange' => 'this.form.submit()', 'class' => 'form-control']],
-            ['option' => ['value' => '']],
+            ['option' => ['value' => '20']],
+            '20',
+            '/option',
+            ['option' => ['value' => '50']],
+            '50',
+            '/option',
+            ['option' => ['value' => '100']],
+            '100',
             '/option',
+            '/select',
+            '/div',
+            '/form'
+        ];
+        $this->assertHtml($expected, $out);
+
+        $out = $this->Paginator->limitControl();
+        $expected = [
+            ['form' => ['method' => 'get', 'accept-charset' => 'utf-8', 'action' => '/']],
+            ['div' => ['class' => 'input select']],
+            ['label' => ['for' => 'limit']],
+            'View',
+            '/label',
+            ['select' => ['name' => 'limit', 'id' => 'limit', 'onChange' => 'this.form.submit()']],
             ['option' => ['value' => '20']],
             '20',
             '/option',