Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added tests

  • Loading branch information...
commit 7bdfa54569aaa41a35fb3fc627fdbab3d97cc727 1 parent 673638a
@Grafikart Grafikart authored
View
2  src/View/Helper/PaginatorHelper.php
@@ -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);
View
30 tests/TestCase/Controller/Component/PaginatorComponentTest.php
@@ -186,6 +186,36 @@ public function testDefaultPaginateParams() {
}
/**
+ * 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
*
* @return void
View
29 tests/TestCase/View/Helper/PaginatorHelperTest.php
@@ -735,6 +735,35 @@ public function testPassedArgsMergingWithUrlOptions() {
}
/**
+ * 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.
*
* @return void
Please sign in to comment.
Something went wrong with that request. Please try again.