Skip to content

Commit

Permalink
add test for inputTypeMap and viewClassMap options + deprecated methods
Browse files Browse the repository at this point in the history
+ reduce usage of error_reporting() and use deprecated() helper
  • Loading branch information
saeideng committed Nov 7, 2017
1 parent 6f4b701 commit 3508e27
Showing 1 changed file with 55 additions and 13 deletions.
68 changes: 55 additions & 13 deletions tests/TestCase/Controller/Component/RequestHandlerComponentTest.php
Expand Up @@ -319,25 +319,22 @@ public function testInitializeContentTypeAndExtensionMismatch()
}

/**
* testViewClassMap method
* testViewClassMap
*
* @return void
*/
public function testViewClassMap()
{
$restore = error_reporting(E_ALL & ~E_USER_DEPRECATED);

$this->RequestHandler->config(['viewClassMap' => ['json' => 'CustomJson']]);
$this->RequestHandler->initialize([]);
$result = $this->RequestHandler->viewClassMap();
$this->RequestHandler->setConfig(['viewClassMap' => ['json' => 'CustomJson']]);
$result = $this->RequestHandler->getConfig('viewClassMap');
$expected = [
'json' => 'CustomJson',
'xml' => 'Xml',
'ajax' => 'Ajax'
];
$this->assertEquals($expected, $result);

$result = $this->RequestHandler->viewClassMap('xls', 'Excel.Excel');
$this->RequestHandler->setConfig(['viewClassMap' => ['xls' => 'Excel.Excel']]);
$result = $this->RequestHandler->getConfig('viewClassMap');
$expected = [
'json' => 'CustomJson',
'xml' => 'Xml',
Expand All @@ -347,8 +344,55 @@ public function testViewClassMap()
$this->assertEquals($expected, $result);

$this->RequestHandler->renderAs($this->Controller, 'json');
$this->assertEquals('TestApp\View\CustomJsonView', $this->Controller->viewClass);
error_reporting($restore);
$this->assertEquals('TestApp\View\CustomJsonView', $this->Controller->viewBuilder()->getClassName());
}

/**
* test addInputType method
*
* @group deprecated
* @return void
*/
public function testDeprecatedAddInputType()
{
$this->deprecated(function () {
$this->RequestHandler->addInputType('csv', ['str_getcsv']);
$result = $this->RequestHandler->getConfig('inputTypeMap');
$this->assertArrayHasKey('csv', $result);
});
}

/**
* testViewClassMap method
*
* @group deprecated
* @return void
*/
public function testViewClassMapMethod()
{
$this->deprecated(function () {
$this->RequestHandler->setConfig(['viewClassMap' => ['json' => 'CustomJson']]);
$this->RequestHandler->initialize([]);
$result = $this->RequestHandler->viewClassMap();
$expected = [
'json' => 'CustomJson',
'xml' => 'Xml',
'ajax' => 'Ajax'
];
$this->assertEquals($expected, $result);

$result = $this->RequestHandler->viewClassMap('xls', 'Excel.Excel');
$expected = [
'json' => 'CustomJson',
'xml' => 'Xml',
'ajax' => 'Ajax',
'xls' => 'Excel.Excel'
];
$this->assertEquals($expected, $result);

$this->RequestHandler->renderAs($this->Controller, 'json');
$this->assertEquals('TestApp\View\CustomJsonView', $this->Controller->viewClass);
});
}

/**
Expand Down Expand Up @@ -559,11 +603,10 @@ public function testStartupIgnoreFileAsXml()
*/
public function testStartupCustomTypeProcess()
{
$restore = error_reporting(E_ALL & ~E_USER_DEPRECATED);
$this->Controller->request = new ServerRequest([
'input' => '"A","csv","string"'
]);
$this->RequestHandler->addInputType('csv', ['str_getcsv']);
$this->RequestHandler->setConfig('inputTypeMap.csv', ['str_getcsv']);
$this->Controller->request->env('REQUEST_METHOD', 'POST');
$this->Controller->request->env('CONTENT_TYPE', 'text/csv');
$event = new Event('Controller.startup', $this->Controller);
Expand All @@ -572,7 +615,6 @@ public function testStartupCustomTypeProcess()
'A', 'csv', 'string'
];
$this->assertEquals($expected, $this->Controller->request->data);
error_reporting($restore);
}

/**
Expand Down

0 comments on commit 3508e27

Please sign in to comment.