Skip to content

Commit

Permalink
pach fix + test
Browse files Browse the repository at this point in the history
  • Loading branch information
ch0c4 committed Feb 15, 2014
1 parent e587faf commit 0d6a6e5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/View/Helper/PaginatorHelper.php
Expand Up @@ -427,8 +427,8 @@ public function url($options = array(), $model = null) {
$url['page'] = null;
}
if (isset($paging['sortDefault'], $paging['directionDefault'], $url['sort'], $url['direction']) && $url['sort'] === $paging['sortDefault'] && $url['direction'] === $paging['directionDefault'] ) {
$url['sort'] = $url['direction'] = null;
}
$url['sort'] = $url['direction'] = null;
}
return parent::url($url);
}

Expand Down
33 changes: 33 additions & 0 deletions tests/TestCase/View/Helper/PaginatorHelperTest.php
Expand Up @@ -543,6 +543,35 @@ public function testSortAdminLinks() {
$this->assertTags($result, $expected);
}

/**
* Test that generated URLs work without sort defined within the request
*
* @return void
*/
public function testDefaultSortAndNoSort() {
Router::setRequestInfo(array(
array('plugin' => null, 'controller' => 'articles', 'action' => 'index'),
array('base' => '/', 'here' => '/articles/', 'webroot' => '/')
));
$this->Paginator->request->params['paging'] = array(
'Article' => array(
'page' => 1, 'current' => 3, 'count' => 13,
'prevPage' => false, 'nextPage' => true, 'pageCount' => 8,
'sortDefault' => 'Article.title', 'directionDefault' => 'ASC',
'sort' => null
)
);
$result = $this->Paginator->next('Next');
$expected = array(
'li' => array('class' => 'next'),
'a' => array('rel' => 'next', 'href' => '/articles/index?page=2'),
'Next',
'/a',
'/li'
);
$this->assertTags($result, $expected);
}

/**
* testUrlGeneration method
*
Expand All @@ -560,6 +589,10 @@ public function testUrlGeneration() {
$result = $this->Paginator->url();
$this->assertEquals('/index', $result);

$file = fopen('/home/johan/test/log.txt', 'r+');

fwrite($file, $result);

$this->Paginator->request->params['paging']['Article']['page'] = 2;
$result = $this->Paginator->url();
$this->assertEquals('/index?page=2', $result);
Expand Down

0 comments on commit 0d6a6e5

Please sign in to comment.