Browse files

Applying patch from 'kuja' to give default class names to links gener…

…ated by Paginator::sort().

Fixes #6239
  • Loading branch information...
1 parent 38a4b61 commit 4f2d4156634c219726e012e9dd7008fd989641b2 @markstory markstory committed Aug 26, 2009
Showing with 16 additions and 9 deletions.
  1. +10 −3 cake/libs/view/helpers/paginator.php
  2. +6 −6 cake/tests/cases/libs/view/helpers/paginator.test.php
View
13 cake/libs/view/helpers/paginator.php
@@ -237,10 +237,17 @@ function sort($title, $key = null, $options = array()) {
$sortKey = $this->sortKey($options['model']);
$isSorted = ($sortKey === $key || $sortKey === $this->defaultModel() . '.' . $key);
- if ($isSorted && $this->sortDir($options['model']) === 'asc') {
- $dir = 'desc';
+ if ($isSorted) {
+ if ($this->sortDir($options['model']) === 'asc') {
+ $dir = 'desc';
+ }
+ $class = $dir === 'asc' ? 'desc' : 'asc';
+ if (!empty($options['class'])) {
+ $options['class'] .= $class;
+ } else {
+ $options['class'] = $class;
+ }
}
-
if (is_array($title) && array_key_exists($dir, $title)) {
$title = $title[$dir];
}
View
12 cake/tests/cases/libs/view/helpers/paginator.test.php
@@ -152,7 +152,7 @@ function testSortLinks() {
$result = $this->Paginator->sort('date');
$expected = array(
- 'a' => array('href' => '/officespace/accounts/index/param/page:1/sort:date/direction:desc'),
+ 'a' => array('href' => '/officespace/accounts/index/param/page:1/sort:date/direction:desc', 'class' => 'asc'),
'Date',
'/a'
);
@@ -181,7 +181,7 @@ function testSortLinks() {
$this->Paginator->params['paging']['Article']['options']['sort'] = 'title';
$result = $this->Paginator->sort(array('asc' => 'ascending', 'desc' => 'descending'), 'title');
$expected = array(
- 'a' => array('href' => '/officespace/accounts/index/param/page:1/sort:title/direction:desc'),
+ 'a' => array('href' => '/officespace/accounts/index/param/page:1/sort:title/direction:desc', 'class' => 'asc'),
'descending',
'/a'
);
@@ -190,13 +190,13 @@ function testSortLinks() {
$this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc');
$this->Paginator->params['paging']['Article']['options']['sort'] = null;
$result = $this->Paginator->sort('title');
- $this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:asc">Title<\/a>$/', $result);
+ $this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:asc" class="desc">Title<\/a>$/', $result);
$this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
$this->Paginator->params['paging']['Article']['options']['sort'] = null;
$result = $this->Paginator->sort('title');
- $this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:desc">Title<\/a>$/', $result);
+ $this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:desc" class="asc">Title<\/a>$/', $result);
}
/**
@@ -216,7 +216,7 @@ function testSortLinksUsingDotNotation() {
$this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc');
$result = $this->Paginator->sort('Title','Article.title');
$expected = array(
- 'a' => array('href' => '/officespace/accounts/index/page:1/sort:Article.title/direction:asc'),
+ 'a' => array('href' => '/officespace/accounts/index/page:1/sort:Article.title/direction:asc', 'class' => 'desc'),
'Title',
'/a'
);
@@ -225,7 +225,7 @@ function testSortLinksUsingDotNotation() {
$this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
$result = $this->Paginator->sort('Title','Article.title');
$expected = array(
- 'a' => array('href' => '/officespace/accounts/index/page:1/sort:Article.title/direction:desc'),
+ 'a' => array('href' => '/officespace/accounts/index/page:1/sort:Article.title/direction:desc', 'class' => 'asc'),
'Title',
'/a'
);

0 comments on commit 4f2d415

Please sign in to comment.