Browse Source

Add URL generation tests for multiple pagination.

Add tests similar tests to what we have for routing prefixes.
Mark Story 9 years ago
parent
commit
f5164aa0c8
1 changed files with 91 additions and 1 deletions
  1. 91 1
      tests/TestCase/View/Helper/PaginatorHelperTest.php

+ 91 - 1
tests/TestCase/View/Helper/PaginatorHelperTest.php

@@ -424,6 +424,42 @@ class PaginatorHelperTest extends TestCase
     }
 
     /**
+     * test multiple pagination sort links
+     *
+     * @return void
+     */
+    public function testSortLinksMultiplePagination()
+    {
+        Router::setRequestInfo([
+            ['plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => [], 'url' => ['url' => 'accounts/']],
+            ['base' => '', 'here' => '/accounts/', 'webroot' => '/']
+        ]);
+
+        $this->Paginator->options(['model' => 'Articles']);
+        $this->Paginator->request['paging'] = [
+            'Articles' => [
+                'current' => 9,
+                'count' => 62,
+                'prevPage' => false,
+                'nextPage' => true,
+                'pageCount' => 7,
+                'sort' => 'date',
+                'direction' => 'asc',
+                'page' => 1,
+                'prefix' => 'article',
+            ]
+        ];
+
+        $result = $this->Paginator->sort('title');
+        $expected = [
+            'a' => ['href' => '/accounts/index?article%5Bsort%5D=title&article%5Bdirection%5D=asc'],
+            'Title',
+            '/a'
+        ];
+        $this->assertHtml($expected, $result);
+    }
+
+    /**
      * Test creating paging links for missing models.
      *
      * @return void
@@ -677,7 +713,7 @@ class PaginatorHelperTest extends TestCase
      *
      * @return void
      */
-    public function testUrlGenerationWithPrefixes()
+    public function testGenerateUrlWithPrefixes()
     {
         Configure::write('Routing.prefixes', ['members']);
         Router::reload();
@@ -737,6 +773,60 @@ class PaginatorHelperTest extends TestCase
     }
 
     /**
+     * test generateUrl with multiple pagination
+     *
+     * @return void
+     */
+    public function testGenerateUrlMultiplePagination()
+    {
+        Router::setRequestInfo([
+            ['controller' => 'posts', 'action' => 'index', 'plugin' => null],
+            ['base' => '', 'here' => 'posts/index', 'webroot' => '/']
+        ]);
+
+        $this->Paginator->request->params['paging']['Article']['prefix'] = 'article';
+        $this->Paginator->request->params['paging']['Article']['page'] = 3;
+        $this->Paginator->request->params['paging']['Article']['prevPage'] = true;
+        $this->Paginator->options(['model' => 'Article']);
+
+        $result = $this->Paginator->generateUrl([]);
+        $expected = '/posts/index?article%5Bpage%5D=3';
+        $this->assertEquals($expected, $result);
+
+        $result = $this->Paginator->sort('name');
+        $expected = [
+            'a' => ['href' => '/posts/index?article%5Bpage%5D=3&article%5Bsort%5D=name&article%5Bdirection%5D=asc'],
+            'Name',
+            '/a'
+        ];
+        $this->assertHtml($expected, $result);
+
+        $result = $this->Paginator->next('next');
+        $expected = [
+            'li' => ['class' => 'next'],
+            'a' => ['href' => '/posts/index?article%5Bpage%5D=4', 'rel' => 'next'],
+            'next',
+            '/a',
+            '/li'
+        ];
+        $this->assertHtml($expected, $result);
+
+        $result = $this->Paginator->prev('prev');
+        $expected = [
+            'li' => ['class' => 'prev'],
+            'a' => ['href' => '/posts/index?article%5Bpage%5D=2', 'rel' => 'prev'],
+            'prev',
+            '/a',
+            '/li'
+        ];
+        $this->assertHtml($expected, $result);
+
+        $result = $this->Paginator->generateUrl(['sort' => 'name']);
+        $expected = '/posts/index?article%5Bpage%5D=3&article%5Bsort%5D=name';
+        $this->assertEquals($expected, $result);
+    }
+
+    /**
      * testOptions method
      *
      * @return void