Skip to content
Permalink
Browse files

Added tests

  • Loading branch information...
Grafikart committed Jan 31, 2014
1 parent 673638a commit 7bdfa54569aaa41a35fb3fc627fdbab3d97cc727
@@ -440,7 +440,7 @@ public function url($options = array(), $model = null) {
if (!empty($url['page']) && $url['page'] == 1) {
$url['page'] = null;
}
if (isset($paging['sortDefault']) && isset($paging['directionDefault']) && $url['sort'] == $paging['sortDefault'] && $url['direction'] == $paging['directionDefault'] ) {
if (isset($paging['sortDefault']) && isset($paging['directionDefault']) && $url['sort'] === $paging['sortDefault'] && $url['direction'] === $paging['directionDefault'] ) {
$url['sort'] = $url['direction'] = null;
}
return parent::url($url);
@@ -185,6 +185,36 @@ public function testDefaultPaginateParams() {
$this->Paginator->paginate($table, $settings);
}
/**
* test that default sort and default direction are injectect into request
*
* @return void
*/
public function testDefaultPaginateParamsIntoRequest() {
$settings = array(
'order' => ['PaginatorPosts.id' => 'DESC'],
'maxLimit' => 10,
);
$table = $this->_getMockPosts(['find']);
$query = $this->_getMockFindQuery();
$table->expects($this->once())
->method('find')
->with('all', [
'conditions' => [],
'fields' => null,
'limit' => 10,
'page' => 1,
'order' => ['PaginatorPosts.id' => 'DESC']
])
->will($this->returnValue($query));
$this->Paginator->paginate($table, $settings);
$this->assertEquals('PaginatorPosts.id', $this->request->params['paging']['PaginatorPosts']['sortDefault']);
$this->assertEquals('DESC', $this->request->params['paging']['PaginatorPosts']['directionDefault']);
}
/**
* test that option merging prefers specific models
*
@@ -734,6 +734,35 @@ public function testPassedArgsMergingWithUrlOptions() {
$this->assertTags($result, $expected);
}
/**
* Test that url generated doesn't include default sort & direction
*
* @return void
*/
public function testDefaultSortRemovedFromUrl() {
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,
'sort' => 'Article.title', 'direction' => 'ASC',
'sortDefault' => 'Article.title', 'directionDefault' => 'ASC'
)
);
$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);
}
/**
* Test the prev() method.
*

0 comments on commit 7bdfa54

Please sign in to comment.
You can’t perform that action at this time.