From dbff1b73274c86849ea7b35e107a6a2f42297234 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Tue, 5 Dec 2017 21:10:47 -0500 Subject: [PATCH] Fix more tests using deprecated request features. --- tests/TestCase/View/Form/ArrayContextTest.php | 4 +- .../TestCase/View/Form/EntityContextTest.php | 4 +- tests/TestCase/View/Form/FormContextTest.php | 4 +- .../View/Helper/PaginatorHelperTest.php | 41 +++++++++---------- 4 files changed, 26 insertions(+), 27 deletions(-) diff --git a/tests/TestCase/View/Form/ArrayContextTest.php b/tests/TestCase/View/Form/ArrayContextTest.php index 8a64720bfe6..9acb758680a 100644 --- a/tests/TestCase/View/Form/ArrayContextTest.php +++ b/tests/TestCase/View/Form/ArrayContextTest.php @@ -135,12 +135,12 @@ public function testIsCreate() */ public function testValPresent() { - $this->request->data = [ + $this->request = $this->request->withParsedBody([ 'Articles' => [ 'title' => 'New title', 'body' => 'My copy', ] - ]; + ]); $context = new ArrayContext($this->request, [ 'defaults' => [ 'Articles' => [ diff --git a/tests/TestCase/View/Form/EntityContextTest.php b/tests/TestCase/View/Form/EntityContextTest.php index 1a53cda714a..d2a77d6e13f 100644 --- a/tests/TestCase/View/Form/EntityContextTest.php +++ b/tests/TestCase/View/Form/EntityContextTest.php @@ -516,10 +516,10 @@ public function testValGetArrayValue() */ public function testValReadsRequest() { - $this->request->data = [ + $this->request = $this->request->withParsedBody([ 'title' => 'New title', 'notInEntity' => 'yes', - ]; + ]); $row = new Article([ 'title' => 'Test entity', 'body' => 'Something new' diff --git a/tests/TestCase/View/Form/FormContextTest.php b/tests/TestCase/View/Form/FormContextTest.php index d97a4d5292f..0efc59d8cad 100644 --- a/tests/TestCase/View/Form/FormContextTest.php +++ b/tests/TestCase/View/Form/FormContextTest.php @@ -81,12 +81,12 @@ public function testIsCreate() */ public function testValPresent() { - $this->request->data = [ + $this->request = $this->request->withParsedBody([ 'Articles' => [ 'title' => 'New title', 'body' => 'My copy', ] - ]; + ]); $context = new FormContext($this->request, ['entity' => new Form()]); $this->assertEquals('New title', $context->val('Articles.title')); $this->assertEquals('My copy', $context->val('Articles.body')); diff --git a/tests/TestCase/View/Helper/PaginatorHelperTest.php b/tests/TestCase/View/Helper/PaginatorHelperTest.php index 8c23c5a22b4..152a8423cee 100644 --- a/tests/TestCase/View/Helper/PaginatorHelperTest.php +++ b/tests/TestCase/View/Helper/PaginatorHelperTest.php @@ -124,9 +124,8 @@ public function testTemplates() public function testHasPrevious() { $this->assertFalse($this->Paginator->hasPrev()); - $this->Paginator->request->params['paging']['Article']['prevPage'] = true; + $this->Paginator->request = $this->Paginator->withParam('paging.Article.prevPage', true); $this->assertTrue($this->Paginator->hasPrev()); - $this->Paginator->request->params['paging']['Article']['prevPage'] = false; } /** @@ -137,9 +136,8 @@ public function testHasPrevious() public function testHasNext() { $this->assertTrue($this->Paginator->hasNext()); - $this->Paginator->request->params['paging']['Article']['nextPage'] = false; + $this->Paginator->request = $this->Paginator->withParam('paging.Article.nextPage', false); $this->assertFalse($this->Paginator->hasNext()); - $this->Paginator->request->params['paging']['Article']['nextPage'] = true; } /** @@ -160,7 +158,7 @@ public function testSortLinks() Router::setRequestInfo($request); $this->Paginator->options(['url' => ['param']]); - $this->Paginator->request->params['paging'] = [ + $this->Paginator->request = $this->Paginator->request->withParam('paging', [ 'Article' => [ 'current' => 9, 'count' => 62, @@ -171,7 +169,7 @@ public function testSortLinks() 'direction' => 'asc', 'page' => 1, ] - ]; + ]); $result = $this->Paginator->sort('title'); $expected = [ @@ -2611,7 +2609,7 @@ public function testLastNonDefaultModel() */ public function testCounter() { - $this->Paginator->request->params['paging'] = [ + $this->Paginator->request = $this->Paginator->request->withParam('paging', [ 'Client' => [ 'page' => 1, 'current' => 3, @@ -2624,7 +2622,7 @@ public function testCounter() 'sort' => 'Client.name', 'order' => 'DESC', ] - ]; + ]); $input = 'Page {{page}} of {{pages}}, showing {{current}} records out of {{count}} total, '; $input .= 'starting on record {{start}}, ending on {{end}}'; @@ -2652,7 +2650,7 @@ public function testCounter() */ public function testCounterBigNumbers() { - $this->Paginator->request->params['paging'] = [ + $this->Paginator->request = $this->Paginator->withParam('paging', [ 'Client' => [ 'page' => 1523, 'current' => 1230, @@ -2665,7 +2663,7 @@ public function testCounterBigNumbers() 'sort' => 'Client.name', 'order' => 'DESC', ] - ]; + ]); $input = 'Page {{page}} of {{pages}}, showing {{current}} records out of {{count}} total, '; $input .= 'starting on record {{start}}, ending on {{end}}'; @@ -2717,9 +2715,10 @@ public function testNextLinkUsingDotNotation() ]); Router::setRequestInfo($request); - $this->Paginator->request->params['paging']['Article']['sort'] = 'Article.title'; - $this->Paginator->request->params['paging']['Article']['direction'] = 'asc'; - $this->Paginator->request->params['paging']['Article']['page'] = 1; + $this->Paginator->request = $this->Paginator->request + ->withParam('paging.Article.sort', 'Article.title') + ->withParam('paging.Article.direction', 'asc') + ->withParam('paging.Article.page', 1); $test = ['url' => [ 'page' => '1', @@ -2750,7 +2749,7 @@ public function testNextLinkUsingDotNotation() public function testCurrent() { $result = $this->Paginator->current(); - $this->assertEquals($this->Paginator->request->params['paging']['Article']['page'], $result); + $this->assertEquals($this->Paginator->request->getParam('paging.Article.page'), $result); $result = $this->Paginator->current('Incorrect'); $this->assertEquals(1, $result); @@ -2764,7 +2763,7 @@ public function testCurrent() public function testTotal() { $result = $this->Paginator->total(); - $this->assertSame($this->Paginator->request->params['paging']['Article']['pageCount'], $result); + $this->assertSame($this->Paginator->request->getParam('paging.Article.pageCount'), $result); $result = $this->Paginator->total('Incorrect'); $this->assertSame(0, $result); @@ -2794,7 +2793,7 @@ public function testNoDefaultModel() */ public function testWithOnePage() { - $this->Paginator->request->params['paging'] = [ + $this->Paginator->request = $this->Paginator->request->withParam('paging', [ 'Article' => [ 'page' => 1, 'current' => 2, @@ -2803,7 +2802,7 @@ public function testWithOnePage() 'nextPage' => true, 'pageCount' => 1, ] - ]; + ]); $this->assertFalse($this->Paginator->numbers()); $this->assertFalse($this->Paginator->first()); $this->assertFalse($this->Paginator->last()); @@ -2816,7 +2815,7 @@ public function testWithOnePage() */ public function testWithZeroPages() { - $this->Paginator->request->params['paging'] = [ + $this->Paginator->request = $this->Paginator->request->withParam('paging', [ 'Article' => [ 'page' => 0, 'current' => 0, @@ -2827,7 +2826,7 @@ public function testWithZeroPages() 'pageCount' => 0, 'limit' => 10, ] - ]; + ]); $result = $this->Paginator->counter(['format' => 'pages']); $expected = '0 of 1'; @@ -2891,14 +2890,14 @@ public function dataMetaProvider() */ public function testMeta($page, $prevPage, $nextPage, $pageCount, $options, $expected) { - $this->Paginator->request->params['paging'] = [ + $this->Paginator->request = $this->Paginator->request->withParam('paging', [ 'Article' => [ 'page' => $page, 'prevPage' => $prevPage, 'nextPage' => $nextPage, 'pageCount' => $pageCount, ] - ]; + ]); $result = $this->Paginator->meta($options); $this->assertSame($expected, $result);