Browse Source

Fix changing direction on non-default models.

Merge branch 'issue-10442' into master
Mark Story 9 years ago
parent
commit
376e64b51b

+ 2 - 2
src/View/Helper/PaginatorHelper.php

@@ -451,8 +451,8 @@ class PaginatorHelper extends Helper
         }
         $isSorted = (
             $sortKey === $table . '.' . $field ||
-            $sortKey === $defaultModel . '.' . $key ||
-            $table . '.' . $field === $defaultModel . '.' . $sortKey
+            $sortKey === $model . '.' . $key ||
+            $table . '.' . $field === $model . '.' . $sortKey
         );
 
         $template = 'sort';

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

@@ -457,16 +457,35 @@ class PaginatorHelperTest extends TestCase
                 'direction' => 'asc',
                 'page' => 1,
                 'scope' => 'article',
+            ],
+            'Tags' => [
+                'current' => 1,
+                'count' => 100,
+                'prevPage' => false,
+                'nextPage' => true,
+                'pageCount' => 5,
+                'sort' => 'tag',
+                'direction' => 'asc',
+                'page' => 1,
+                'scope' => 'tags',
             ]
         ];
 
-        $result = $this->Paginator->sort('title');
+        $result = $this->Paginator->sort('title', 'Title', ['model' => 'Articles']);
         $expected = [
             'a' => ['href' => '/accounts/index?article%5Bsort%5D=title&article%5Bdirection%5D=asc'],
             'Title',
             '/a'
         ];
         $this->assertHtml($expected, $result);
+
+        $result = $this->Paginator->sort('tag', 'Tag', ['model' => 'Tags']);
+        $expected = [
+            'a' => ['class' => 'asc', 'href' => '/accounts/index?tags%5Bsort%5D=tag&tags%5Bdirection%5D=desc'],
+            'Tag',
+            '/a'
+        ];
+        $this->assertHtml($expected, $result);
     }
 
     /**