Skip to content

Commit

Permalink
Fix deprecated method use in View tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Nov 16, 2017
1 parent 7f4245e commit 32ef626
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/View/JsonView.php
Expand Up @@ -113,7 +113,7 @@ public function render($view = null, $layout = null)
}
if ($this->request->getQuery($jsonpParam)) {
$return = sprintf('%s(%s)', h($this->request->getQuery($jsonpParam)), $return);
$this->response->type('js');
$this->response = $this->response->withType('js');
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/View/SerializedView.php
Expand Up @@ -46,11 +46,10 @@ public function __construct(
EventManager $eventManager = null,
array $viewOptions = []
) {
parent::__construct($request, $response, $eventManager, $viewOptions);

if ($response && $response instanceof Response) {
$response->type($this->_responseType);
$response = $response->withType($this->_responseType);
}
parent::__construct($request, $response, $eventManager, $viewOptions);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/TestCase/View/JsonViewTest.php
Expand Up @@ -293,13 +293,13 @@ public function testJsonpResponse()
$output = $View->render(false);

$this->assertSame(json_encode($data), $output);
$this->assertSame('application/json', $Response->type());
$this->assertSame('application/json', $View->response->getType());

$View->request->query = ['callback' => 'jfunc'];
$output = $View->render(false);
$expected = 'jfunc(' . json_encode($data) . ')';
$this->assertSame($expected, $output);
$this->assertSame('application/javascript', $Response->type());
$this->assertSame('application/javascript', $View->response->getType());

$View->request->query = ['jsonCallback' => 'jfunc'];
$View->viewVars['_jsonp'] = 'jsonCallback';
Expand Down Expand Up @@ -337,6 +337,6 @@ public function testRenderWithView()

$expected = json_encode(['user' => 'fake', 'list' => ['item1', 'item2'], 'paging' => null]);
$this->assertSame($expected, $output);
$this->assertSame('application/json', $Response->type());
$this->assertSame('application/json', $View->response->getType());
}
}
10 changes: 5 additions & 5 deletions tests/TestCase/View/XmlViewTest.php
Expand Up @@ -52,7 +52,7 @@ public function testRenderWithoutView()
$output = $View->render(false);

$this->assertSame(Xml::build($data)->asXML(), $output);
$this->assertSame('application/xml', $Response->type());
$this->assertSame('application/xml', $View->response->getType());

$data = [
[
Expand Down Expand Up @@ -191,7 +191,7 @@ public function testRenderWithoutViewMultiple()
$Controller->set('_serialize', ['no', 'user']);
$Controller->viewClass = 'Xml';
$View = $Controller->createView();
$this->assertSame('application/xml', $Response->type());
$this->assertSame('application/xml', $View->response->getType());
$output = $View->render(false);
$expected = [
'response' => ['no' => $data['no'], 'user' => $data['user']]
Expand Down Expand Up @@ -223,7 +223,7 @@ public function testRenderWithoutViewMultipleAndAlias()
$Controller->set('_serialize', ['new_name' => 'original_name', 'user']);
$Controller->viewClass = 'Xml';
$View = $Controller->createView();
$this->assertSame('application/xml', $Response->type());
$this->assertSame('application/xml', $View->response->getType());
$output = $View->render(false);
$expected = [
'response' => ['new_name' => $data['original_name'], 'user' => $data['user']]
Expand Down Expand Up @@ -257,7 +257,7 @@ public function testRenderWithSerializeTrue()
$output = $View->render();

$this->assertSame(Xml::build($data)->asXML(), $output);
$this->assertSame('application/xml', $Response->type());
$this->assertSame('application/xml', $View->response->getType());

$data = ['no' => 'nope', 'user' => 'fake', 'list' => ['item1', 'item2']];
$Controller->viewVars = [];
Expand Down Expand Up @@ -306,7 +306,7 @@ public function testRenderWithView()
];
$expected = Xml::build($expected)->asXML();
$this->assertSame($expected, $output);
$this->assertSame('application/xml', $Response->type());
$this->assertSame('application/xml', $View->response->getType());
$this->assertInstanceOf('Cake\View\HelperRegistry', $View->helpers());
}
}

0 comments on commit 32ef626

Please sign in to comment.