Skip to content
Permalink
Browse files

Add URL generation tests for multiple pagination.

Add tests similar tests to what we have for routing prefixes.
  • Loading branch information...
markstory committed Jul 2, 2016
1 parent 066f155 commit f5164aa0c87aacbcb89c0d97baf85c32f0b2fcc5
Showing with 91 additions and 1 deletion.
  1. +91 −1 tests/TestCase/View/Helper/PaginatorHelperTest.php
@@ -423,6 +423,42 @@ public function testSortLinksUsingDotNotation()
$this->assertHtml($expected, $result);
}
/**
* test multiple pagination sort links
*
* @return void
*/
public function testSortLinksMultiplePagination()
{
Router::setRequestInfo([
['plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => [], 'url' => ['url' => 'accounts/']],
['base' => '', 'here' => '/accounts/', 'webroot' => '/']
]);
$this->Paginator->options(['model' => 'Articles']);
$this->Paginator->request['paging'] = [
'Articles' => [
'current' => 9,
'count' => 62,
'prevPage' => false,
'nextPage' => true,
'pageCount' => 7,
'sort' => 'date',
'direction' => 'asc',
'page' => 1,
'prefix' => 'article',
]
];
$result = $this->Paginator->sort('title');
$expected = [
'a' => ['href' => '/accounts/index?article%5Bsort%5D=title&article%5Bdirection%5D=asc'],
'Title',
'/a'
];
$this->assertHtml($expected, $result);
}
/**
* Test creating paging links for missing models.
*
@@ -677,7 +713,7 @@ public function testUrlGeneration()
*
* @return void
*/
public function testUrlGenerationWithPrefixes()
public function testGenerateUrlWithPrefixes()
{
Configure::write('Routing.prefixes', ['members']);
Router::reload();
@@ -736,6 +772,60 @@ public function testUrlGenerationWithPrefixes()
$this->assertEquals($expected, $result);
}
/**
* test generateUrl with multiple pagination
*
* @return void
*/
public function testGenerateUrlMultiplePagination()
{
Router::setRequestInfo([
['controller' => 'posts', 'action' => 'index', 'plugin' => null],
['base' => '', 'here' => 'posts/index', 'webroot' => '/']
]);
$this->Paginator->request->params['paging']['Article']['prefix'] = 'article';
$this->Paginator->request->params['paging']['Article']['page'] = 3;
$this->Paginator->request->params['paging']['Article']['prevPage'] = true;
$this->Paginator->options(['model' => 'Article']);
$result = $this->Paginator->generateUrl([]);
$expected = '/posts/index?article%5Bpage%5D=3';
$this->assertEquals($expected, $result);
$result = $this->Paginator->sort('name');
$expected = [
'a' => ['href' => '/posts/index?article%5Bpage%5D=3&article%5Bsort%5D=name&article%5Bdirection%5D=asc'],
'Name',
'/a'
];
$this->assertHtml($expected, $result);
$result = $this->Paginator->next('next');
$expected = [
'li' => ['class' => 'next'],
'a' => ['href' => '/posts/index?article%5Bpage%5D=4', 'rel' => 'next'],
'next',
'/a',
'/li'
];
$this->assertHtml($expected, $result);
$result = $this->Paginator->prev('prev');
$expected = [
'li' => ['class' => 'prev'],
'a' => ['href' => '/posts/index?article%5Bpage%5D=2', 'rel' => 'prev'],
'prev',
'/a',
'/li'
];
$this->assertHtml($expected, $result);
$result = $this->Paginator->generateUrl(['sort' => 'name']);
$expected = '/posts/index?article%5Bpage%5D=3&article%5Bsort%5D=name';
$this->assertEquals($expected, $result);
}
/**
* testOptions method
*

0 comments on commit f5164aa

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