Browse Source

Add tests for mergeOptions with custom prefix

Jose Diaz-Gonzalez 10 years ago
parent
commit
8ded571b48
1 changed files with 70 additions and 0 deletions
  1. 70 0
      tests/TestCase/Controller/Component/PaginatorComponentTest.php

+ 70 - 0
tests/TestCase/Controller/Component/PaginatorComponentTest.php

@@ -292,6 +292,76 @@ class PaginatorComponentTest extends TestCase
     }
 
     /**
+     * test mergeOptions with custom prefix
+     *
+     * @return void
+     */
+    public function testMergeOptionsCustomPrefix()
+    {
+        $this->request->query = [
+            'page' => 10,
+            'limit' => 10,
+            'prefix' => [
+                'page' => 2,
+                'limit' => 5,
+            ]
+        ];
+
+        $settings = [
+            'page' => 1,
+            'limit' => 20,
+            'maxLimit' => 100,
+            'finder' => 'myCustomFind',
+        ];
+        $result = $this->Paginator->mergeOptions('Post', $settings);
+        $expected = [
+            'page' => 10,
+            'limit' => 10,
+            'maxLimit' => 100,
+            'finder' => 'myCustomFind',
+            'whitelist' => ['limit', 'sort', 'page', 'direction'],
+        ];
+        $this->assertEquals($expected, $result);
+
+        $settings = [
+            'page' => 1,
+            'limit' => 20,
+            'maxLimit' => 100,
+            'finder' => 'myCustomFind',
+            'prefix' => 'non-existent',
+        ];
+        $result = $this->Paginator->mergeOptions('Post', $settings);
+        $expected = [
+            'page' => 1,
+            'limit' => 20,
+            'maxLimit' => 100,
+            'finder' => 'myCustomFind',
+            'whitelist' => ['limit', 'sort', 'page', 'direction'],
+            'prefix' => 'non-existent',
+        ];
+        $this->assertEquals($expected, $result);
+
+
+        $settings = [
+            'page' => 1,
+            'limit' => 20,
+            'maxLimit' => 100,
+            'finder' => 'myCustomFind',
+            'prefix' => 'prefix',
+        ];
+        $result = $this->Paginator->mergeOptions('Post', $settings);
+        $expected = [
+            'page' => 2,
+            'limit' => 5,
+            'maxLimit' => 100,
+            'finder' => 'myCustomFind',
+            'whitelist' => ['limit', 'sort', 'page', 'direction'],
+            'prefix' => 'prefix',
+        ];
+        $this->assertEquals($expected, $result);
+    }
+
+    /**
      * test mergeOptions with customFind key
      *
      * @return void