Skip to content

Commit

Permalink
Fix deprecated method usage in PaginatorHelper.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Nov 16, 2017
1 parent c1f6c93 commit 94b395c
Showing 1 changed file with 107 additions and 47 deletions.
154 changes: 107 additions & 47 deletions tests/TestCase/View/Helper/PaginatorHelperTest.php
Expand Up @@ -147,10 +147,15 @@ public function testHasNext()
*/
public function testSortLinks()
{
Router::setRequestInfo([
['plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => [], 'url' => ['url' => 'accounts/']],
['base' => '', 'here' => '/accounts/', 'webroot' => '/']
$request = new ServerRequest([
'url' => '/accounts/',
'params' => [
'plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => []
],
'base' => '',
'webroot' => '/'
]);
Router::setRequestInfo($request);

$this->Paginator->options(['url' => ['param']]);
$this->Paginator->request->params['paging'] = [
Expand Down Expand Up @@ -307,10 +312,16 @@ public function testSortEscape()
*/
public function testSortLinkWithVirtualField()
{
Router::setRequestInfo([
['plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => [], 'form' => [], 'url' => ['url' => 'accounts/']],
['base' => '', 'here' => '/accounts/', 'webroot' => '/']
$request = new ServerRequest([
'url' => '/accounts/',
'params' => [
'plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => []
],
'base' => '',
'webroot' => '/'
]);
Router::setRequestInfo($request);

$this->Paginator->request->params['paging']['Article']['sort'] = 'full_name';
$this->Paginator->request->params['paging']['Article']['direction'] = 'asc';

Expand Down Expand Up @@ -356,11 +367,16 @@ public function testSortLinkWithVirtualField()
*/
public function testSortLinksUsingDirectionOption()
{
Router::setRequestInfo([
['plugin' => null, 'controller' => 'accounts', 'action' => 'index',
'url' => ['url' => 'accounts/', 'mod_rewrite' => 'true']],
['base' => '/', 'here' => '/accounts/', 'webroot' => '/']
$request = new ServerRequest([
'url' => '/accounts/',
'params' => [
'plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => []
],
'base' => '',
'webroot' => '/'
]);
Router::setRequestInfo($request);

$this->Paginator->options(['url' => ['param']]);

$result = $this->Paginator->sort('title', 'TestTitle', ['direction' => 'desc']);
Expand All @@ -387,10 +403,15 @@ public function testSortLinksUsingDirectionOption()
*/
public function testSortLinksUsingDotNotation()
{
Router::setRequestInfo([
['plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => []],
['base' => '', 'here' => '/accounts/', 'webroot' => '/']
$request = new ServerRequest([
'url' => '/accounts/',
'params' => [
'plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => []
],
'base' => '',
'webroot' => '/'
]);
Router::setRequestInfo($request);

$this->Paginator->request->params['paging']['Article']['sort'] = 'Article.title';
$this->Paginator->request->params['paging']['Article']['direction'] = 'desc';
Expand Down Expand Up @@ -440,10 +461,15 @@ public function testSortLinksUsingDotNotation()
*/
public function testSortLinksMultiplePagination()
{
Router::setRequestInfo([
['plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => [], 'url' => ['url' => 'accounts/']],
['base' => '', 'here' => '/accounts/', 'webroot' => '/']
$request = new ServerRequest([
'url' => '/accounts/',
'params' => [
'plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => []
],
'base' => '',
'webroot' => '/'
]);
Router::setRequestInfo($request);

$this->Paginator->options(['model' => 'Articles']);
$this->Paginator->request = $this->Paginator->request->withParam('paging', [
Expand Down Expand Up @@ -641,10 +667,17 @@ public function testSortAdminLinks()
Configure::write('Routing.prefixes', ['admin']);
Router::reload();
Router::connect('/admin/:controller/:action/*', ['prefix' => 'admin']);
Router::setRequestInfo([
['controller' => 'users', 'plugin' => null, 'action' => 'index', 'prefix' => 'admin'],
['base' => '', 'here' => '/admin/users', 'webroot' => '/']

$request = new ServerRequest([
'url' => '/admin/users',
'params' => [
'plugin' => null, 'controller' => 'users', 'action' => 'index', 'prefix' => 'admin'
],
'base' => '',
'webroot' => '/'
]);
Router::setRequestInfo($request);

$this->Paginator->request->params['paging']['Article']['page'] = 1;
$result = $this->Paginator->next('Next');
$expected = [
Expand Down Expand Up @@ -682,10 +715,16 @@ public function testSortAdminLinks()
*/
public function testDefaultSortAndNoSort()
{
Router::setRequestInfo([
['plugin' => null, 'controller' => 'articles', 'action' => 'index'],
['base' => '/', 'here' => '/articles/', 'webroot' => '/']
$request = new ServerRequest([
'url' => '/articles/',
'params' => [
'plugin' => null, 'controller' => 'articles', 'action' => 'index'
],
'base' => '',
'webroot' => '/'
]);
Router::setRequestInfo($request);

$this->Paginator->request->params['paging'] = [
'Article' => [
'page' => 1, 'current' => 3, 'count' => 13,
Expand Down Expand Up @@ -765,10 +804,15 @@ public function testGenerateUrlWithPrefixes()
Router::connect('/members/:controller/:action/*', ['prefix' => 'members']);
Router::connect('/:controller/:action/*');

Router::setRequestInfo([
['controller' => 'posts', 'action' => 'index', 'plugin' => null],
['base' => '', 'here' => 'posts/index', 'webroot' => '/']
$request = new ServerRequest([
'url' => '/posts/index/',
'params' => [
'plugin' => null, 'controller' => 'posts', 'action' => 'index', 'pass' => []
],
'base' => '',
'webroot' => '/'
]);
Router::setRequestInfo($request);

$this->Paginator->request->params['paging']['Article']['page'] = 2;
$this->Paginator->request->params['paging']['Article']['prevPage'] = true;
Expand Down Expand Up @@ -824,10 +868,15 @@ public function testGenerateUrlWithPrefixes()
*/
public function testGenerateUrlMultiplePagination()
{
Router::setRequestInfo([
['controller' => 'posts', 'action' => 'index', 'plugin' => null],
['base' => '', 'here' => 'posts/index', 'webroot' => '/']
$request = new ServerRequest([
'url' => '/posts/index/',
'params' => [
'plugin' => null, 'controller' => 'posts', 'action' => 'index', 'pass' => []
],
'base' => '',
'webroot' => '/'
]);
Router::setRequestInfo($request);

$this->Paginator->request->params['paging']['Article']['scope'] = 'article';
$this->Paginator->request->params['paging']['Article']['page'] = 3;
Expand Down Expand Up @@ -878,10 +927,14 @@ public function testGenerateUrlMultiplePagination()
*/
public function testGenerateUrlMultiplePaginationQueryStringData()
{
Router::setRequestInfo([
['controller' => 'posts', 'action' => 'index', 'plugin' => null],
['base' => '', 'here' => 'posts/index', 'webroot' => '/']
$request = new ServerRequest([
'url' => '/posts/index/',
'params' => [
'plugin' => null, 'controller' => 'posts', 'action' => 'index'
]
]);
Router::setRequestInfo($request);

$this->View->request->params['paging']['Article']['scope'] = 'article';
$this->View->request->params['paging']['Article']['page'] = 3;
$this->View->request->params['paging']['Article']['prevPage'] = true;
Expand Down Expand Up @@ -955,10 +1008,14 @@ public function testOptions()
*/
public function testPassedArgsMergingWithUrlOptions()
{
Router::setRequestInfo([
['plugin' => null, 'controller' => 'articles', 'action' => 'index', 'pass' => ['2']],
['base' => '/', 'here' => '/articles/', 'webroot' => '/']
$request = new ServerRequest([
'url' => '/articles/',
'params' => [
'plugin' => null, 'controller' => 'articles', 'action' => 'index', 'pass' => []
],
]);
Router::setRequestInfo($request);

$this->Paginator->request->params['paging'] = [
'Article' => [
'page' => 1, 'current' => 3, 'count' => 13,
Expand Down Expand Up @@ -1010,10 +1067,14 @@ public function testPassedArgsMergingWithUrlOptions()
*/
public function testDefaultSortRemovedFromUrl()
{
Router::setRequestInfo([
['plugin' => null, 'controller' => 'articles', 'action' => 'index'],
['base' => '/', 'here' => '/articles/', 'webroot' => '/']
$request = new ServerRequest([
'url' => '/articles/',
'params' => [
'plugin' => null, 'controller' => 'articles', 'action' => 'index'
]
]);
Router::setRequestInfo($request);

$this->Paginator->request->params['paging'] = [
'Article' => [
'page' => 1, 'current' => 3, 'count' => 13,
Expand Down Expand Up @@ -2167,14 +2228,10 @@ public function testNumbersRouting()
]
];

$request = new ServerRequest();
$request->addParams([
'controller' => 'clients', 'action' => 'index', 'plugin' => null
$request = new ServerRequest([
'params' => ['controller' => 'clients', 'action' => 'index', 'plugin' => null],
'url' => '/clients/index?page=2'
]);
$request->base = '';
$request->here = '/clients/index?page=2';
$request->webroot = '/';

Router::setRequestInfo($request);

$result = $this->Paginator->numbers();
Expand Down Expand Up @@ -2650,10 +2707,13 @@ public function testHasPage()
*/
public function testNextLinkUsingDotNotation()
{
Router::setRequestInfo([
['plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => []],
['base' => '', 'here' => '/accounts/', 'webroot' => '/']
$request = new ServerRequest([
'url' => '/accounts/',
'params' => [
'plugin' => null, 'controller' => 'accounts', 'action' => 'index'
]
]);
Router::setRequestInfo($request);

$this->Paginator->request->params['paging']['Article']['sort'] = 'Article.title';
$this->Paginator->request->params['paging']['Article']['direction'] = 'asc';
Expand Down

0 comments on commit 94b395c

Please sign in to comment.