<commit_before><?php
/**
 * Test the SerializerExceptionRenderer class
 *
 * @package SerializersErrors.Test.Case.Lib.Error
 */
App::uses('Controller', 'Controller');
App::uses('CakeRequest', 'Network');
App::uses('CakeResponse', 'Network');
App::uses('SerializerExceptionRenderer', 'SerializersErrors.Error');
App::uses('ConnectionManager', 'Model');

/**
 * TestSerializerExceptionRenderer - used to override protected methods and
 * call directly
 */
class TestSerializerExceptionRenderer extends SerializerExceptionRenderer {

	/**
	 * calls parent method
	 *
	 * @param HttpException $error the HttpException error to render
	 * @return void
	 */
	public function renderHttpException(HttpException $error) {
		return parent::renderHttpException($error);
	}

	/**
	 * calls parent method
	 *
	 * @param CakeException $error the CakeException error to render
	 * @return void
	 */
	public function renderCakeException(CakeException $error) {
		return parent::renderCakeException($error);
	}

	/**
	 * calls parent method
	 *
	 * @param BaseSerializerException $error the BaseSerializerException error to render
	 * @return void
	 */
	public function renderSerializerException(BaseSerializerException $error) {
		return parent::renderSerializerException($error);
	}

	/**
	 * calls parent method
	 *
	 * @param ValidationBaseSerializerException $error the ValidationBaseSerializerException error to render
	 * @return void
	 */
	public function renderValidationSerializerException(ValidationBaseSerializerException $error) {
		return parent::renderValidationSerializerException($error);
	}

	/**
	 * calls parent method
	 *
	 * @param HttpException $error an instance of HttpException
	 * @return void
	 */
	public function renderHttpAsJson(HttpException $error) {
		return parent::renderHttpAsJson($error);
	}

	/**
	 * calls parent method
	 *
	 * @param HttpException $error an instance of HttpException
	 * @return void
	 */
	public function renderHttpAsJsonApi(HttpException $error) {
		return parent::renderHttpAsJsonApi($error);
	}

	/**
	 * calls parent method
	 *
	 * @param HttpException $error an instance of HttpException
	 * @return void
	 */
	public function defaultHttpRender(HttpException $error) {
		return parent::defaultHttpRender($error);
	}

	/**
	 * calls parent method
	 *
	 * @param CakeException $error an instance of CakeException
	 * @return void
	 */
	public function renderCakeAsJson(CakeException $error) {
		return parent::renderCakeAsJson($error);
	}

	/**
	 * calls parent method
	 *
	 * @param CakeException $error an instance of CakeException
	 * @return void
	 */
	public function renderCakeAsJsonApi(CakeException $error) {
		return parent::renderCakeAsJsonApi($error);
	}

	/**
	 * calls parent method
	 *
	 * @param CakeException $error an instance of CakeException
	 * @return void
	 */
	public function defaultCakeRender(CakeException $error) {
		return parent::defaultCakeRender($error);
	}

	/**
	 * calls parent method
	 *
	 * @param BaseSerializerException $error an instance of BaseSerializerException
	 * @return void
	 */
	public function defaultSerializerRender(BaseSerializerException $error) {
		return parent::defaultSerializerRender($error);
	}

	/**
	 * calls parent method
	 *
	 * @param BaseSerializerException $error an instance of BaseSerializerException
	 * @return void
	 */
	public function renderSerializerAsJson(BaseSerializerException $error) {
		return parent::renderSerializerAsJson($error);
	}

	/**
	 * calls parent method
	 *
	 * @param BaseSerializerException $error an instance of BaseSerializerException
	 * @return void
	 */
	public function renderSerializerAsJsonApi(BaseSerializerException $error) {
		return parent::renderSerializerAsJsonApi($error);
	}

	/**
	 * calls parent method
	 *
	 * @param ValidationBaseSerializerException $error an instance of ValidationBaseSerializerException
	 * @return void
	 */
	public function defaultValidationSerializerRender(ValidationBaseSerializerException $error) {
		return parent::defaultValidationSerializerRender($error);
	}

	/**
	 * calls parent method
	 *
	 * @param ValidationBaseSerializerException $error an instance of ValidationBaseSerializerException
	 * @return void
	 */
	public function renderValidationSerializerAsJson(ValidationBaseSerializerException $error) {
		return parent::renderValidationSerializerAsJson($error);
	}

	/**
	 * calls parent method
	 *
	 * @param ValidationBaseSerializerException $error an instance of ValidationBaseSerializerException
	 * @return void
	 */
	public function renderValidationSerializerAsJsonApi(ValidationBaseSerializerException $error) {
		return parent::renderValidationSerializerAsJsonApi($error);
	}

	/**
	 * calls parent method
	 *
	 * @return void
	 */
	public function addHttpCodes() {
		return parent::addHttpCodes();
	}

	/**
	 * calls parent method
	 *
	 * @return bool returns true if JsonApi media request, false otherwise
	 */
	public function isJsonApiRequest() {
		return parent::isJsonApiRequest();
	}

	/**
	 * calls parent method
	 *
	 * @return bool returns true if Json media request, false otherwise
	 */
	public function isJsonRequest() {
		return parent::isJsonRequest();
	}

}

/**
 * SerializerExceptionRendererTest
 */
class SerializerExceptionRendererTest extends CakeTestCase {

	/**
	 * setUp
	 *
	 * @return void
	 */
	public function setUp() {
		parent::setUp();
	}

	/**
	 * tearDown
	 *
	 * @return void
	 */
	public function tearDown() {
		parent::tearDown();
	}

	/**
	 * return a Render object with some properties
	 *
	 * @param string $acceptsMockReturn the accepts header to mock return true for
	 * @param Exception $exception the exception to build the ExceptionRenderer around
	 * @return TestSerializerExceptionRenderer with a mocked Controller->Request
	 */
	protected function returnRenderer($acceptsMockReturn, $exception) {
		$mockController = $this->getMock('Controller', array('render'));
		$mockController->expects($this->any())
			->method('render')
			->will($this->returnValue("cake-controller-render"));

		$mockController->request = $this->getMock('CakeRequest', array('accepts', 'here'));
		$mockController->request->expects($this->any())
			->method('accepts')
			->with($acceptsMockReturn)
			->will($this->returnValue(true));
		$mockController->request->expects($this->any())
			->method('here')
			->will($this->returnValue("/this/is/faked/url"));

		$mockController->response = $this->getMock('CakeResponse', array('send'));
		$mockController->response->expects($this->any())
			->method('send')
			->will($this->returnValue("cake-response-send"));

		$exceptionRenderer = new TestSerializerExceptionRenderer($exception);
		$exceptionRenderer->controller = $mockController;

		return $exceptionRenderer;
	}

	/**
	 * test the render method, in all the various cases
	 *
	 * @return void
	 */
	public function testRender() {
		$exception = new ValidationBaseSerializerException();
		$mockRenderer = $this->getMock('TestSerializerExceptionRenderer',
			array('renderValidationSerializerException'),
			array($exception)
		);
		$mockRenderer->expects($this->once())
			->method('renderValidationSerializerException')
			->with($exception)
			->will($this->returnValue("renderValidationSerializerException"));
		$mockRenderer->error = $exception;

		$this->assertEquals(
			"renderValidationSerializerException",
			$mockRenderer->render(),
			"render did not return our mocked value `renderValidationSerializerException` for a ValidationBaseSerializerException"
		);

		$exception = new BaseSerializerException();
		$mockRenderer = $this->getMock('TestSerializerExceptionRenderer',
			array('renderSerializerException'),
			array($exception)
		);
		$mockRenderer->expects($this->once())
			->method('renderSerializerException')
			->with($exception)
			->will($this->returnValue("renderSerializerException"));
		$mockRenderer->error = $exception;

		$this->assertEquals(
			"renderSerializerException",
			$mockRenderer->render(),
			"render did not return our mocked value `renderSerializerException` for a BaseSerializerException"
		);

		$exception = new CakeException("Message", 400);
		$mockRenderer = $this->getMock('TestSerializerExceptionRenderer',
			array('renderCakeException'),
			array($exception)
		);
		$mockRenderer->expects($this->once())
			->method('renderCakeException')
			->with($exception)
			->will($this->returnValue("renderCakeException"));
		$mockRenderer->error = $exception;

		$this->assertEquals(
			"renderCakeException",
			$mockRenderer->render(),
			"render did not return our mocked value `renderCakeException` for a CakeException"
		);

		$exception = new HttpException("Message", 400);
		$mockRenderer = $this->getMock('TestSerializerExceptionRenderer',
			array('renderHttpException'),
			array($exception)
		);
		$mockRenderer->expects($this->once())
			->method('renderHttpException')
			->with($exception)
			->will($this->returnValue("renderHttpException"));
		$mockRenderer->error = $exception;

		$this->assertEquals(
			"renderHttpException",
			$mockRenderer->render(),
			"render did not return our mocked value `renderHttpException` for a HttpException"
		);

		$exception = new Exception("Default Exception", 400);
		$mockRenderer = $this->getMock('TestSerializerExceptionRenderer',
			array('error500'),
			array($exception)
		);
		$mockRenderer->expects($this->once())
			->method('error500')
			->with($exception)
			->will($this->returnValue("error500"));
		$mockRenderer->error = $exception;
		$this->assertEquals(
			"error500",
			$mockRenderer->render(),
			"render did not return our mocked value `error500` for a standard Exception"
		);
	}

	/**
	 * test the renderHttpException method when calling renderHttpAsJsonApi
	 *
	 * @return void
	 */
	public function testRenderHttpExceptionJsonApiRequest() {
		$httpException = new HttpException("Message", 400);
		$mockRenderer = $this->getMock('TestSerializerExceptionRenderer',
			array('isJsonApiRequest', 'renderHttpAsJsonApi'),
			array($httpException)
		);
		$mockRenderer->expects($this->once())
			->method('isJsonApiRequest')
			->will($this->returnValue(true));
		$mockRenderer->expects($this->once())
			->method('renderHttpAsJsonApi')
			->with($httpException)
			->will($this->returnValue("renderHttpAsJsonApi"));

		$this->assertEquals(
			"renderHttpAsJsonApi",
			$mockRenderer->renderHttpException($httpException),
			"renderHttpException did not return our mocked value"
		);
	}

	/**
	 * test the renderHttpException method when calling renderHttpAsJson
	 *
	 * @return void
	 */
	public function testRenderHttpExceptionJsonRequest() {
		$httpException = new HttpException("Message", 400);
		$mockRenderer = $this->getMock('TestSerializerExceptionRenderer',
			array('isJsonApiRequest', 'isJsonRequest', 'renderHttpAsJson'),
			array($httpException)
		);
		$mockRenderer->expects($this->once())
			->method('isJsonApiRequest')
			->will($this->returnValue(false));
		$mockRenderer->expects($this->once())
			->method('isJsonRequest')
			->will($this->returnValue(true));
		$mockRenderer->expects($this->once())
			->method('renderHttpAsJson')
			->with($httpException)
			->will($this->returnValue("renderHttpAsJson"));

		$this->assertEquals(
			"renderHttpAsJson",
			$mockRenderer->renderHttpException($httpException),
			"renderHttpException did not return our mocked value"
		);
	}

	/**
	 * test the renderHttpException method when calling defaultHttpRender
	 *
	 * @return void
	 */
	public function testRenderHttpExceptionDefaultRequest() {
		$httpException = new HttpException("Message", 400);
		$mockRenderer = $this->getMock('TestSerializerExceptionRenderer',
			array('isJsonApiRequest', 'isJsonRequest', 'defaultHttpRender'),
			array($httpException)
		);
		$mockRenderer->expects($this->once())
			->method('isJsonApiRequest')
			->will($this->returnValue(false));
		$mockRenderer->expects($this->once())
			->method('isJsonRequest')
			->will($this->returnValue(false));
		$mockRenderer->expects($this->once())
			->method('defaultHttpRender')
			->with($httpException)
			->will($this->returnValue("defaultHttpRender"));

		$this->assertEquals(
			"defaultHttpRender",
			$mockRenderer->renderHttpException($httpException),
			"renderHttpException did not return our mocked value"
		);
	}

	/**
	 * test the renderCakeException method when calling renderCakeAsJsonApi
	 *
	 * @return void
	 */
	public function testRenderCakeExceptionJsonApiRequest() {
		$exception = new CakeException("Message", 400);
		$mockRenderer = $this->getMock('TestSerializerExceptionRenderer',
			array('isJsonApiRequest', 'renderCakeAsJsonApi'),
			array($exception)
		);
		$mockRenderer->expects($this->once())
			->method('isJsonApiRequest')
			->will($this->returnValue(true));
		$mockRenderer->expects($this->once())
			->method('renderCakeAsJsonApi')
			->with($exception)
			->will($this->returnValue("renderCakeAsJsonApi"));

		$this->assertEquals(
			"renderCakeAsJsonApi",
			$mockRenderer->renderCakeException($exception),
			"renderCakeException did not return our mocked value"
		);
	}

	/**
	 * test the renderCakeException method when calling renderCakeAsJson
	 *
	 * @return void
	 */
	public function testRenderCakeExceptionJsonRequest() {
		$exception = new CakeException("Message", 400);
		$mockRenderer = $this->getMock('TestSerializerExceptionRenderer',
			array('isJsonApiRequest', 'isJsonRequest', 'renderCakeAsJson'),
			array($exception)
		);
		$mockRenderer->expects($this->once())
			->method('isJsonApiRequest')
			->will($this->returnValue(false));
		$mockRenderer->expects($this->once())
			->method('isJsonRequest')
			->will($this->returnValue(true));
		$mockRenderer->expects($this->once())
			->method('renderCakeAsJson')
			->with($exception)
			->will($this->returnValue("renderCakeAsJson"));

		$this->assertEquals(
			"renderCakeAsJson",
			$mockRenderer->renderCakeException($exception),
			"renderCakeException did not return our mocked value"
		);
	}

	/**
	 * test the renderCakeException method when calling defaultCakeRender
	 *
	 * @return void
	 */
	public function testRenderCakeExceptionDefaultRequest() {
		$exception = new CakeException("Message", 400);
		$mockRenderer = $this->getMock('TestSerializerExceptionRenderer',
			array('isJsonApiRequest', 'isJsonRequest', 'defaultCakeRender'),
			array($exception)
		);
		$mockRenderer->expects($this->once())
			->method('isJsonApiRequest')
			->will($this->returnValue(false));
		$mockRenderer->expects($this->once())
			->method('isJsonRequest')
			->will($this->returnValue(false));
		$mockRenderer->expects($this->once())
			->method('defaultCakeRender')
			->with($exception)
			->will($this->returnValue("defaultCakeRender"));

		$this->assertEquals(
			"defaultCakeRender",
			$mockRenderer->renderCakeException($exception),
			"renderCakeException did not return our mocked value"
		);
	}

	/**
	 * test the renderSerializerException method when calling renderSerializerAsJsonApi
	 *
	 * @return void
	 */
	public function testRenderSerializerExceptionJsonApiRequest() {
		$exception = new BaseSerializerException();
		$mockRenderer = $this->getMock('TestSerializerExceptionRenderer',
			array('isJsonApiRequest', 'renderSerializerAsJsonApi'),
			array($exception)
		);
		$mockRenderer->expects($this->once())
			->method('isJsonApiRequest')
			->will($this->returnValue(true));
		$mockRenderer->expects($this->once())
			->method('renderSerializerAsJsonApi')
			->with($exception)
			->will($this->returnValue("renderSerializerAsJsonApi"));

		$this->assertEquals(
			"renderSerializerAsJsonApi",
			$mockRenderer->renderSerializerException($exception),
			"renderSerializerException did not return our mocked value"
		);
	}

	/**
	 * test the renderSerializerException method when calling renderSerializerAsJson
	 *
	 * @return void
	 */
	public function testRenderSerializerExceptionJsonRequest() {
		$exception = new BaseSerializerException();
		$mockRenderer = $this->getMock('TestSerializerExceptionRenderer',
			array('isJsonApiRequest', 'isJsonRequest', 'renderSerializerAsJson'),
			array($exception)
		);
		$mockRenderer->expects($this->once())
			->method('isJsonApiRequest')
			->will($this->returnValue(false));
		$mockRenderer->expects($this->once())
			->method('isJsonRequest')
			->will($this->returnValue(true));
		$mockRenderer->expects($this->once())
			->method('renderSerializerAsJson')
			->with($exception)
			->will($this->returnValue("renderSerializerAsJson"));

		$this->assertEquals(
			"renderSerializerAsJson",
			$mockRenderer->renderSerializerException($exception),
			"renderSerializerException did not return our mocked value"
		);
	}

	/**
	 * test the renderSerializerException method when calling defaultSerializerRender
	 *
	 * @return void
	 */
	public function testRenderSerializerExceptionDefaultRequest() {
		$exception = new BaseSerializerException();
		$mockRenderer = $this->getMock('TestSerializerExceptionRenderer',
			array('isJsonApiRequest', 'isJsonRequest', 'defaultSerializerRender'),
			array($exception)
		);
		$mockRenderer->expects($this->once())
			->method('isJsonApiRequest')
			->will($this->returnValue(false));
		$mockRenderer->expects($this->once())
			->method('isJsonRequest')
			->will($this->returnValue(false));
		$mockRenderer->expects($this->once())
			->method('defaultSerializerRender')
			->with($exception)
			->will($this->returnValue("defaultSerializerRender"));

		$this->assertEquals(
			"defaultSerializerRender",
			$mockRenderer->renderSerializerException($exception),
			"renderSerializerException did not return our mocked value"
		);
	}

	/**
	 * test the renderValidationSerializerException method when calling renderValidationSerializerAsJsonApi
	 *
	 * @return void
	 */
	public function testRenderValidationSerializerExceptionJsonApiRequest() {
		$exception = new ValidationBaseSerializerException();
		$mockRenderer = $this->getMock('TestSerializerExceptionRenderer',
			array('isJsonApiRequest', 'renderValidationSerializerAsJsonApi'),
			array($exception)
		);
		$mockRenderer->expects($this->once())
			->method('isJsonApiRequest')
			->will($this->returnValue(true));
		$mockRenderer->expects($this->once())
			->method('renderValidationSerializerAsJsonApi')
			->with($exception)
			->will($this->returnValue("renderValidationSerializerAsJsonApi"));

		$this->assertEquals(
			"renderValidationSerializerAsJsonApi",
			$mockRenderer->renderValidationSerializerException($exception),
			"renderValidationSerializerException did not return our mocked value"
		);
	}

	/**
	 * test the renderValidationSerializerException method when calling renderValidationSerializerAsJson
	 *
	 * @return void
	 */
	public function testRenderValidationSerializerExceptionJsonRequest() {
		$exception = new ValidationBaseSerializerException();
		$mockRenderer = $this->getMock('TestSerializerExceptionRenderer',
			array('isJsonApiRequest', 'isJsonRequest', 'renderValidationSerializerAsJson'),
			array($exception)
		);
		$mockRenderer->expects($this->once())
			->method('isJsonApiRequest')
			->will($this->returnValue(false));
		$mockRenderer->expects($this->once())
			->method('isJsonRequest')
			->will($this->returnValue(true));
		$mockRenderer->expects($this->once())
			->method('renderValidationSerializerAsJson')
			->with($exception)
			->will($this->returnValue("renderValidationSerializerAsJson"));

		$this->assertEquals(
			"renderValidationSerializerAsJson",
			$mockRenderer->renderValidationSerializerException($exception),
			"renderValidationSerializerException did not return our mocked value"
		);
	}

	/**
	 * test the renderValidationSerializerException method when calling defaultValidationSerializerRender
	 *
	 * @return void
	 */
	public function testRenderValidationSerializerExceptionDefaultRequest() {
		$exception = new ValidationBaseSerializerException();
		$mockRenderer = $this->getMock('TestSerializerExceptionRenderer',
			array('isJsonApiRequest', 'isJsonRequest', 'defaultValidationSerializerRender'),
			array($exception)
		);
		$mockRenderer->expects($this->once())
			->method('isJsonApiRequest')
			->will($this->returnValue(false));
		$mockRenderer->expects($this->once())
			->method('isJsonRequest')
			->will($this->returnValue(false));
		$mockRenderer->expects($this->once())
			->method('defaultValidationSerializerRender')
			->with($exception)
			->will($this->returnValue("defaultValidationSerializerRender"));

		$this->assertEquals(
			"defaultValidationSerializerRender",
			$mockRenderer->renderValidationSerializerException($exception),
			"renderValidationSerializerException did not return our mocked value"
		);
	}

	/**
	 * test the defaultHttpRender method
	 *
	 * @return void
	 */
	public function testDefaultHttpRender() {
		$httpException = new HttpException("Message", 400);
		$exceptionRenderer = $this->returnRenderer('text/html', $httpException);

		$response = $exceptionRenderer->defaultHttpRender($httpException);

		$this->assertEquals(
			"400",
			$exceptionRenderer->controller->response->statusCode(),
			"Our Controller Response Status Code does not equal 400"
		);
		$this->assertEquals(
			'text/html',
			$exceptionRenderer->controller->response->type(),
			"Our Response Type does not equal text/html"
		);
		$this->assertArrayHasKey(
			"code",
			$exceptionRenderer->controller->viewVars,
			"We do not have an code viewVars"
		);
		$this->assertArrayHasKey(
			"name",
			$exceptionRenderer->controller->viewVars,
			"We do not have an name viewVars"
		);
		$this->assertArrayHasKey(
			"message",
			$exceptionRenderer->controller->viewVars,
			"We do not have an message viewVars"
		);
		$this->assertArrayHasKey(
			"url",
			$exceptionRenderer->controller->viewVars,
			"We do not have an url viewVars"
		);
		$this->assertArrayHasKey(
			"error",
			$exceptionRenderer->controller->viewVars,
			"We do not have an error viewVars"
		);
		$this->assertSame(
			null,
			$response,
			"Our response does not match null"
		);
	}

	/**
	 * test the renderHttpAsJson method
	 *
	 * @return void
	 */
	public function testRenderHttpAsJson() {
		$httpException = new HttpException("Message", 400);
		$exceptionRenderer = $this->returnRenderer('application/json', $httpException);

		$response = $exceptionRenderer->renderHttpAsJson($httpException);

		$this->assertEquals(
			"400",
			$exceptionRenderer->controller->response->statusCode(),
			"Our Controller Response Status Code does not equal 400"
		);
		$this->assertEquals(
			"application/json",
			$exceptionRenderer->controller->response->type(),
			"Our Response Type does not equal application/json"
		);
		$this->assertArrayHasKey(
			"code",
			$exceptionRenderer->controller->viewVars,
			"We do not have an code viewVars"
		);
		$this->assertArrayHasKey(
			"name",
			$exceptionRenderer->controller->viewVars,
			"We do not have an name viewVars"
		);
		$this->assertArrayHasKey(
			"message",
			$exceptionRenderer->controller->viewVars,
			"We do not have an message viewVars"
		);
		$this->assertArrayHasKey(
			"url",
			$exceptionRenderer->controller->viewVars,
			"We do not have an url viewVars"
		);
		$this->assertArrayHasKey(
			"error",
			$exceptionRenderer->controller->viewVars,
			"We do not have an error viewVars"
		);
		$this->assertSame(
			null,
			$response,
			"Our response does not match null"
		);
	}

	/**
	 * test the renderHttpAsJsonApi method
	 *
	 * @return void
	 */
	public function testRenderHttpAsJsonApi() {
		$httpException = new HttpException("Message", 400);
		$exceptionRenderer = $this->returnRenderer('application/vnd.api+json', $httpException);

		$response = $exceptionRenderer->renderHttpAsJsonApi($httpException);

		$this->assertEquals(
			"400",
			$exceptionRenderer->controller->response->statusCode(),
			"Our Controller Response Status Code does not equal 400"
		);
		$this->assertEquals(
			"application/vnd.api+json",
			$exceptionRenderer->controller->response->type(),
			"Our Response Type does not equal application/vnd.api+json"
		);
		$this->assertInternalType(
			"string",
			$exceptionRenderer->controller->response->body(),
			"Our body is not a string"
		);
		$this->assertInstanceOf(
			"stdClass",
			json_decode($exceptionRenderer->controller->response->body()),
			"Our body is not a json_encoded array"
		);
		$this->assertSame(
			'{"errors":{"id":null,"href":null,"status":"400","code":"HttpException","title":"Message","detail":"Message","links":[],"paths":[]}}',
			$exceptionRenderer->controller->response->body(),
			"Our body does not match the expected string"
		);
		$this->assertSame(
			'cake-response-send',
			$response,
			"Our response does not match the expected string"
		);
	}

	/**
	 * test the defaultCakeRender method
	 *
	 * @return void
	 */
	public function testDefaultCakeRender() {
		$cakeException = new CakeException("Message");
		$exceptionRenderer = $this->returnRenderer('text/html', $cakeException);

		$response = $exceptionRenderer->defaultCakeRender($cakeException);

		$this->assertEquals(
			"500",
			$exceptionRenderer->controller->response->statusCode(),
			"Our Controller Response Status Code does not equal 500"
		);
		$this->assertEquals(
			'text/html',
			$exceptionRenderer->controller->response->type(),
			"Our Response Type does not equal text/html"
		);
		$this->assertArrayHasKey(
			"code",
			$exceptionRenderer->controller->viewVars,
			"We do not have an code viewVars"
		);
		$this->assertArrayHasKey(
			"name",
			$exceptionRenderer->controller->viewVars,
			"We do not have an name viewVars"
		);
		$this->assertArrayHasKey(
			"message",
			$exceptionRenderer->controller->viewVars,<commit_msg>Improved Tests to Match Improved HttpException Default Render<commit_after><?php
/**
 * Test the SerializerExceptionRenderer class
 *
 * @package SerializersErrors.Test.Case.Lib.Error
 */
App::uses('Controller', 'Controller');
App::uses('CakeRequest', 'Network');
App::uses('CakeResponse', 'Network');
App::uses('SerializerExceptionRenderer', 'SerializersErrors.Error');
App::uses('ConnectionManager', 'Model');

/**
 * TestSerializerExceptionRenderer - used to override protected methods and
 * call directly
 */
class TestSerializerExceptionRenderer extends SerializerExceptionRenderer {

	/**
	 * calls parent method
	 *
	 * @param HttpException $error the HttpException error to render
	 * @return void
	 */
	public function renderHttpException(HttpException $error) {
		return parent::renderHttpException($error);
	}

	/**
	 * calls parent method
	 *
	 * @param CakeException $error the CakeException error to render
	 * @return void
	 */
	public function renderCakeException(CakeException $error) {
		return parent::renderCakeException($error);
	}

	/**
	 * calls parent method
	 *
	 * @param BaseSerializerException $error the BaseSerializerException error to render
	 * @return void
	 */
	public function renderSerializerException(BaseSerializerException $error) {
		return parent::renderSerializerException($error);
	}

	/**
	 * calls parent method
	 *
	 * @param ValidationBaseSerializerException $error the ValidationBaseSerializerException error to render
	 * @return void
	 */
	public function renderValidationSerializerException(ValidationBaseSerializerException $error) {
		return parent::renderValidationSerializerException($error);
	}

	/**
	 * calls parent method
	 *
	 * @param HttpException $error an instance of HttpException
	 * @return void
	 */
	public function renderHttpAsJson(HttpException $error) {
		return parent::renderHttpAsJson($error);
	}

	/**
	 * calls parent method
	 *
	 * @param HttpException $error an instance of HttpException
	 * @return void
	 */
	public function renderHttpAsJsonApi(HttpException $error) {
		return parent::renderHttpAsJsonApi($error);
	}

	/**
	 * calls parent method
	 *
	 * @param HttpException $error an instance of HttpException
	 * @return void
	 */
	public function defaultHttpRender(HttpException $error) {
		return parent::defaultHttpRender($error);
	}

	/**
	 * calls parent method
	 *
	 * @param CakeException $error an instance of CakeException
	 * @return void
	 */
	public function renderCakeAsJson(CakeException $error) {
		return parent::renderCakeAsJson($error);
	}

	/**
	 * calls parent method
	 *
	 * @param CakeException $error an instance of CakeException
	 * @return void
	 */
	public function renderCakeAsJsonApi(CakeException $error) {
		return parent::renderCakeAsJsonApi($error);
	}

	/**
	 * calls parent method
	 *
	 * @param CakeException $error an instance of CakeException
	 * @return void
	 */
	public function defaultCakeRender(CakeException $error) {
		return parent::defaultCakeRender($error);
	}

	/**
	 * calls parent method
	 *
	 * @param BaseSerializerException $error an instance of BaseSerializerException
	 * @return void
	 */
	public function defaultSerializerRender(BaseSerializerException $error) {
		return parent::defaultSerializerRender($error);
	}

	/**
	 * calls parent method
	 *
	 * @param BaseSerializerException $error an instance of BaseSerializerException
	 * @return void
	 */
	public function renderSerializerAsJson(BaseSerializerException $error) {
		return parent::renderSerializerAsJson($error);
	}

	/**
	 * calls parent method
	 *
	 * @param BaseSerializerException $error an instance of BaseSerializerException
	 * @return void
	 */
	public function renderSerializerAsJsonApi(BaseSerializerException $error) {
		return parent::renderSerializerAsJsonApi($error);
	}

	/**
	 * calls parent method
	 *
	 * @param ValidationBaseSerializerException $error an instance of ValidationBaseSerializerException
	 * @return void
	 */
	public function defaultValidationSerializerRender(ValidationBaseSerializerException $error) {
		return parent::defaultValidationSerializerRender($error);
	}

	/**
	 * calls parent method
	 *
	 * @param ValidationBaseSerializerException $error an instance of ValidationBaseSerializerException
	 * @return void
	 */
	public function renderValidationSerializerAsJson(ValidationBaseSerializerException $error) {
		return parent::renderValidationSerializerAsJson($error);
	}

	/**
	 * calls parent method
	 *
	 * @param ValidationBaseSerializerException $error an instance of ValidationBaseSerializerException
	 * @return void
	 */
	public function renderValidationSerializerAsJsonApi(ValidationBaseSerializerException $error) {
		return parent::renderValidationSerializerAsJsonApi($error);
	}

	/**
	 * calls parent method
	 *
	 * @return void
	 */
	public function addHttpCodes() {
		return parent::addHttpCodes();
	}

	/**
	 * calls parent method
	 *
	 * @return bool returns true if JsonApi media request, false otherwise
	 */
	public function isJsonApiRequest() {
		return parent::isJsonApiRequest();
	}

	/**
	 * calls parent method
	 *
	 * @return bool returns true if Json media request, false otherwise
	 */
	public function isJsonRequest() {
		return parent::isJsonRequest();
	}

}

/**
 * SerializerExceptionRendererTest
 */
class SerializerExceptionRendererTest extends CakeTestCase {

	/**
	 * setUp
	 *
	 * @return void
	 */
	public function setUp() {
		parent::setUp();
	}

	/**
	 * tearDown
	 *
	 * @return void
	 */
	public function tearDown() {
		parent::tearDown();
	}

	/**
	 * return a Render object with some properties
	 *
	 * @param string $acceptsMockReturn the accepts header to mock return true for
	 * @param Exception $exception the exception to build the ExceptionRenderer around
	 * @return TestSerializerExceptionRenderer with a mocked Controller->Request
	 */
	protected function returnRenderer($acceptsMockReturn, $exception) {
		$mockController = $this->getMock('Controller', array('render'));
		$mockController->expects($this->any())
			->method('render')
			->will($this->returnValue("cake-controller-render"));

		$mockController->request = $this->getMock('CakeRequest', array('accepts', 'here'));
		$mockController->request->expects($this->any())
			->method('accepts')
			->with($acceptsMockReturn)
			->will($this->returnValue(true));
		$mockController->request->expects($this->any())
			->method('here')
			->will($this->returnValue("/this/is/faked/url"));

		$mockController->response = $this->getMock('CakeResponse', array('send'));
		$mockController->response->expects($this->any())
			->method('send')
			->will($this->returnValue("cake-response-send"));

		$exceptionRenderer = new TestSerializerExceptionRenderer($exception);
		$exceptionRenderer->controller = $mockController;

		return $exceptionRenderer;
	}

	/**
	 * test the render method, in all the various cases
	 *
	 * @return void
	 */
	public function testRender() {
		$exception = new ValidationBaseSerializerException();
		$mockRenderer = $this->getMock('TestSerializerExceptionRenderer',
			array('renderValidationSerializerException'),
			array($exception)
		);
		$mockRenderer->expects($this->once())
			->method('renderValidationSerializerException')
			->with($exception)
			->will($this->returnValue("renderValidationSerializerException"));
		$mockRenderer->error = $exception;

		$this->assertEquals(
			"renderValidationSerializerException",
			$mockRenderer->render(),
			"render did not return our mocked value `renderValidationSerializerException` for a ValidationBaseSerializerException"
		);

		$exception = new BaseSerializerException();
		$mockRenderer = $this->getMock('TestSerializerExceptionRenderer',
			array('renderSerializerException'),
			array($exception)
		);
		$mockRenderer->expects($this->once())
			->method('renderSerializerException')
			->with($exception)
			->will($this->returnValue("renderSerializerException"));
		$mockRenderer->error = $exception;

		$this->assertEquals(
			"renderSerializerException",
			$mockRenderer->render(),
			"render did not return our mocked value `renderSerializerException` for a BaseSerializerException"
		);

		$exception = new CakeException("Message", 400);
		$mockRenderer = $this->getMock('TestSerializerExceptionRenderer',
			array('renderCakeException'),
			array($exception)
		);
		$mockRenderer->expects($this->once())
			->method('renderCakeException')
			->with($exception)
			->will($this->returnValue("renderCakeException"));
		$mockRenderer->error = $exception;

		$this->assertEquals(
			"renderCakeException",
			$mockRenderer->render(),
			"render did not return our mocked value `renderCakeException` for a CakeException"
		);

		$exception = new HttpException("Message", 400);
		$mockRenderer = $this->getMock('TestSerializerExceptionRenderer',
			array('renderHttpException'),
			array($exception)
		);
		$mockRenderer->expects($this->once())
			->method('renderHttpException')
			->with($exception)
			->will($this->returnValue("renderHttpException"));
		$mockRenderer->error = $exception;

		$this->assertEquals(
			"renderHttpException",
			$mockRenderer->render(),
			"render did not return our mocked value `renderHttpException` for a HttpException"
		);

		$exception = new Exception("Default Exception", 400);
		$mockRenderer = $this->getMock('TestSerializerExceptionRenderer',
			array('error500'),
			array($exception)
		);
		$mockRenderer->expects($this->once())
			->method('error500')
			->with($exception)
			->will($this->returnValue("error500"));
		$mockRenderer->error = $exception;
		$this->assertEquals(
			"error500",
			$mockRenderer->render(),
			"render did not return our mocked value `error500` for a standard Exception"
		);
	}

	/**
	 * test the renderHttpException method when calling renderHttpAsJsonApi
	 *
	 * @return void
	 */
	public function testRenderHttpExceptionJsonApiRequest() {
		$httpException = new HttpException("Message", 400);
		$mockRenderer = $this->getMock('TestSerializerExceptionRenderer',
			array('isJsonApiRequest', 'renderHttpAsJsonApi'),
			array($httpException)
		);
		$mockRenderer->expects($this->once())
			->method('isJsonApiRequest')
			->will($this->returnValue(true));
		$mockRenderer->expects($this->once())
			->method('renderHttpAsJsonApi')
			->with($httpException)
			->will($this->returnValue("renderHttpAsJsonApi"));

		$this->assertEquals(
			"renderHttpAsJsonApi",
			$mockRenderer->renderHttpException($httpException),
			"renderHttpException did not return our mocked value"
		);
	}

	/**
	 * test the renderHttpException method when calling renderHttpAsJson
	 *
	 * @return void
	 */
	public function testRenderHttpExceptionJsonRequest() {
		$httpException = new HttpException("Message", 400);
		$mockRenderer = $this->getMock('TestSerializerExceptionRenderer',
			array('isJsonApiRequest', 'isJsonRequest', 'renderHttpAsJson'),
			array($httpException)
		);
		$mockRenderer->expects($this->once())
			->method('isJsonApiRequest')
			->will($this->returnValue(false));
		$mockRenderer->expects($this->once())
			->method('isJsonRequest')
			->will($this->returnValue(true));
		$mockRenderer->expects($this->once())
			->method('renderHttpAsJson')
			->with($httpException)
			->will($this->returnValue("renderHttpAsJson"));

		$this->assertEquals(
			"renderHttpAsJson",
			$mockRenderer->renderHttpException($httpException),
			"renderHttpException did not return our mocked value"
		);
	}

	/**
	 * test the renderHttpException method when calling defaultHttpRender
	 *
	 * @return void
	 */
	public function testRenderHttpExceptionDefaultRequest() {
		$httpException = new HttpException("Message", 400);
		$mockRenderer = $this->getMock('TestSerializerExceptionRenderer',
			array('isJsonApiRequest', 'isJsonRequest', 'defaultHttpRender'),
			array($httpException)
		);
		$mockRenderer->expects($this->once())
			->method('isJsonApiRequest')
			->will($this->returnValue(false));
		$mockRenderer->expects($this->once())
			->method('isJsonRequest')
			->will($this->returnValue(false));
		$mockRenderer->expects($this->once())
			->method('defaultHttpRender')
			->with($httpException)
			->will($this->returnValue("defaultHttpRender"));

		$this->assertEquals(
			"defaultHttpRender",
			$mockRenderer->renderHttpException($httpException),
			"renderHttpException did not return our mocked value"
		);
	}

	/**
	 * test the renderCakeException method when calling renderCakeAsJsonApi
	 *
	 * @return void
	 */
	public function testRenderCakeExceptionJsonApiRequest() {
		$exception = new CakeException("Message", 400);
		$mockRenderer = $this->getMock('TestSerializerExceptionRenderer',
			array('isJsonApiRequest', 'renderCakeAsJsonApi'),
			array($exception)
		);
		$mockRenderer->expects($this->once())
			->method('isJsonApiRequest')
			->will($this->returnValue(true));
		$mockRenderer->expects($this->once())
			->method('renderCakeAsJsonApi')
			->with($exception)
			->will($this->returnValue("renderCakeAsJsonApi"));

		$this->assertEquals(
			"renderCakeAsJsonApi",
			$mockRenderer->renderCakeException($exception),
			"renderCakeException did not return our mocked value"
		);
	}

	/**
	 * test the renderCakeException method when calling renderCakeAsJson
	 *
	 * @return void
	 */
	public function testRenderCakeExceptionJsonRequest() {
		$exception = new CakeException("Message", 400);
		$mockRenderer = $this->getMock('TestSerializerExceptionRenderer',
			array('isJsonApiRequest', 'isJsonRequest', 'renderCakeAsJson'),
			array($exception)
		);
		$mockRenderer->expects($this->once())
			->method('isJsonApiRequest')
			->will($this->returnValue(false));
		$mockRenderer->expects($this->once())
			->method('isJsonRequest')
			->will($this->returnValue(true));
		$mockRenderer->expects($this->once())
			->method('renderCakeAsJson')
			->with($exception)
			->will($this->returnValue("renderCakeAsJson"));

		$this->assertEquals(
			"renderCakeAsJson",
			$mockRenderer->renderCakeException($exception),
			"renderCakeException did not return our mocked value"
		);
	}

	/**
	 * test the renderCakeException method when calling defaultCakeRender
	 *
	 * @return void
	 */
	public function testRenderCakeExceptionDefaultRequest() {
		$exception = new CakeException("Message", 400);
		$mockRenderer = $this->getMock('TestSerializerExceptionRenderer',
			array('isJsonApiRequest', 'isJsonRequest', 'defaultCakeRender'),
			array($exception)
		);
		$mockRenderer->expects($this->once())
			->method('isJsonApiRequest')
			->will($this->returnValue(false));
		$mockRenderer->expects($this->once())
			->method('isJsonRequest')
			->will($this->returnValue(false));
		$mockRenderer->expects($this->once())
			->method('defaultCakeRender')
			->with($exception)
			->will($this->returnValue("defaultCakeRender"));

		$this->assertEquals(
			"defaultCakeRender",
			$mockRenderer->renderCakeException($exception),
			"renderCakeException did not return our mocked value"
		);
	}

	/**
	 * test the renderSerializerException method when calling renderSerializerAsJsonApi
	 *
	 * @return void
	 */
	public function testRenderSerializerExceptionJsonApiRequest() {
		$exception = new BaseSerializerException();
		$mockRenderer = $this->getMock('TestSerializerExceptionRenderer',
			array('isJsonApiRequest', 'renderSerializerAsJsonApi'),
			array($exception)
		);
		$mockRenderer->expects($this->once())
			->method('isJsonApiRequest')
			->will($this->returnValue(true));
		$mockRenderer->expects($this->once())
			->method('renderSerializerAsJsonApi')
			->with($exception)
			->will($this->returnValue("renderSerializerAsJsonApi"));

		$this->assertEquals(
			"renderSerializerAsJsonApi",
			$mockRenderer->renderSerializerException($exception),
			"renderSerializerException did not return our mocked value"
		);
	}

	/**
	 * test the renderSerializerException method when calling renderSerializerAsJson
	 *
	 * @return void
	 */
	public function testRenderSerializerExceptionJsonRequest() {
		$exception = new BaseSerializerException();
		$mockRenderer = $this->getMock('TestSerializerExceptionRenderer',
			array('isJsonApiRequest', 'isJsonRequest', 'renderSerializerAsJson'),
			array($exception)
		);
		$mockRenderer->expects($this->once())
			->method('isJsonApiRequest')
			->will($this->returnValue(false));
		$mockRenderer->expects($this->once())
			->method('isJsonRequest')
			->will($this->returnValue(true));
		$mockRenderer->expects($this->once())
			->method('renderSerializerAsJson')
			->with($exception)
			->will($this->returnValue("renderSerializerAsJson"));

		$this->assertEquals(
			"renderSerializerAsJson",
			$mockRenderer->renderSerializerException($exception),
			"renderSerializerException did not return our mocked value"
		);
	}

	/**
	 * test the renderSerializerException method when calling defaultSerializerRender
	 *
	 * @return void
	 */
	public function testRenderSerializerExceptionDefaultRequest() {
		$exception = new BaseSerializerException();
		$mockRenderer = $this->getMock('TestSerializerExceptionRenderer',
			array('isJsonApiRequest', 'isJsonRequest', 'defaultSerializerRender'),
			array($exception)
		);
		$mockRenderer->expects($this->once())
			->method('isJsonApiRequest')
			->will($this->returnValue(false));
		$mockRenderer->expects($this->once())
			->method('isJsonRequest')
			->will($this->returnValue(false));
		$mockRenderer->expects($this->once())
			->method('defaultSerializerRender')
			->with($exception)
			->will($this->returnValue("defaultSerializerRender"));

		$this->assertEquals(
			"defaultSerializerRender",
			$mockRenderer->renderSerializerException($exception),
			"renderSerializerException did not return our mocked value"
		);
	}

	/**
	 * test the renderValidationSerializerException method when calling renderValidationSerializerAsJsonApi
	 *
	 * @return void
	 */
	public function testRenderValidationSerializerExceptionJsonApiRequest() {
		$exception = new ValidationBaseSerializerException();
		$mockRenderer = $this->getMock('TestSerializerExceptionRenderer',
			array('isJsonApiRequest', 'renderValidationSerializerAsJsonApi'),
			array($exception)
		);
		$mockRenderer->expects($this->once())
			->method('isJsonApiRequest')
			->will($this->returnValue(true));
		$mockRenderer->expects($this->once())
			->method('renderValidationSerializerAsJsonApi')
			->with($exception)
			->will($this->returnValue("renderValidationSerializerAsJsonApi"));

		$this->assertEquals(
			"renderValidationSerializerAsJsonApi",
			$mockRenderer->renderValidationSerializerException($exception),
			"renderValidationSerializerException did not return our mocked value"
		);
	}

	/**
	 * test the renderValidationSerializerException method when calling renderValidationSerializerAsJson
	 *
	 * @return void
	 */
	public function testRenderValidationSerializerExceptionJsonRequest() {
		$exception = new ValidationBaseSerializerException();
		$mockRenderer = $this->getMock('TestSerializerExceptionRenderer',
			array('isJsonApiRequest', 'isJsonRequest', 'renderValidationSerializerAsJson'),
			array($exception)
		);
		$mockRenderer->expects($this->once())
			->method('isJsonApiRequest')
			->will($this->returnValue(false));
		$mockRenderer->expects($this->once())
			->method('isJsonRequest')
			->will($this->returnValue(true));
		$mockRenderer->expects($this->once())
			->method('renderValidationSerializerAsJson')
			->with($exception)
			->will($this->returnValue("renderValidationSerializerAsJson"));

		$this->assertEquals(
			"renderValidationSerializerAsJson",
			$mockRenderer->renderValidationSerializerException($exception),
			"renderValidationSerializerException did not return our mocked value"
		);
	}

	/**
	 * test the renderValidationSerializerException method when calling defaultValidationSerializerRender
	 *
	 * @return void
	 */
	public function testRenderValidationSerializerExceptionDefaultRequest() {
		$exception = new ValidationBaseSerializerException();
		$mockRenderer = $this->getMock('TestSerializerExceptionRenderer',
			array('isJsonApiRequest', 'isJsonRequest', 'defaultValidationSerializerRender'),
			array($exception)
		);
		$mockRenderer->expects($this->once())
			->method('isJsonApiRequest')
			->will($this->returnValue(false));
		$mockRenderer->expects($this->once())
			->method('isJsonRequest')
			->will($this->returnValue(false));
		$mockRenderer->expects($this->once())
			->method('defaultValidationSerializerRender')
			->with($exception)
			->will($this->returnValue("defaultValidationSerializerRender"));

		$this->assertEquals(
			"defaultValidationSerializerRender",
			$mockRenderer->renderValidationSerializerException($exception),
			"renderValidationSerializerException did not return our mocked value"
		);
	}

	/**
	 * test the defaultHttpRender method
	 *
	 * @param string $exceptionCode Exception Code to test for.
	 * @return void
	 * @dataProvider providerHttpExceptions
	 */
	public function testDefaultHttpRender($exceptionCode) {
		$httpException = new HttpException('ExceptionMessage', $exceptionCode);
		$exceptionRenderer = $this->returnRenderer('text/html', $httpException);

		$response = $exceptionRenderer->defaultHttpRender($httpException);

		$this->assertEquals(
			$exceptionCode,
			$exceptionRenderer->controller->response->statusCode(),
			"Our Controller Response Status Code should equal the passed in ErrorCode of {$exceptionCode}"
		);
		$this->assertEquals(
			'text/html',
			$exceptionRenderer->controller->response->type(),
			"Our Response Type should equal text/html"
		);
		$this->assertArrayHasKey(
			"code",
			$exceptionRenderer->controller->viewVars,
			"We should have a code viewVars"
		);
		$this->assertArrayHasKey(
			"name",
			$exceptionRenderer->controller->viewVars,
			"We should have a name viewVars"
		);
		$this->assertArrayHasKey(
			"message",
			$exceptionRenderer->controller->viewVars,
			"We should have a message viewVars"
		);
		$this->assertArrayHasKey(
			"url",
			$exceptionRenderer->controller->viewVars,
			"We should have a url viewVars"
		);
		$this->assertArrayHasKey(
			"error",
			$exceptionRenderer->controller->viewVars,
			"We should have an error viewVars"
		);
		$this->assertSame(
			null,
			$response,
			"Our response should equal null"
		);
	}

	/**
	 * DataProvider for testDefaultHttpRender.
	 *
	 * @return void Return Data inputs for testDefaultHttpRender.
	 */
	public function providerHttpExceptions() {
		return array(
			'400 Exception' => array(
				'400',
			),
			'500 Exception' => array(
				'500',
			),
		);
	}

	/**
	 * test the renderHttpAsJson method
	 *
	 * @return void
	 */
	public function testRenderHttpAsJson() {
		$httpException = new HttpException("Message", 400);
		$exceptionRenderer = $this->returnRenderer('application/json', $httpException);

		$response = $exceptionRenderer->renderHttpAsJson($httpException);

		$this->assertEquals(
			"400",
			$exceptionRenderer->controller->response->statusCode(),
			"Our Controller Response Status Code does not equal 400"
		);
		$this->assertEquals(
			"application/json",
			$exceptionRenderer->controller->response->type(),
			"Our Response Type does not equal application/json"
		);
		$this->assertArrayHasKey(
			"code",
			$exceptionRenderer->controller->viewVars,
			"We do not have an code viewVars"
		);
		$this->assertArrayHasKey(
			"name",
			$exceptionRenderer->controller->viewVars,
			"We do not have an name viewVars"
		);
		$this->assertArrayHasKey(
			"message",
			$exceptionRenderer->controller->viewVars,
			"We do not have an message viewVars"
		);
		$this->assertArrayHasKey(
			"url",
			$exceptionRenderer->controller->viewVars,
			"We do not have an url viewVars"
		);
		$this->assertArrayHasKey(
			"error",
			$exceptionRenderer->controller->viewVars,
			"We do not have an error viewVars"
		);
		$this->assertSame(
			null,
			$response,
			"Our response does not match null"
		);
	}

	/**
	 * test the renderHttpAsJsonApi method
	 *
	 * @return void
	 */
	public function testRenderHttpAsJsonApi() {
		$httpException = new HttpException("Message", 400);
		$exceptionRenderer = $this->returnRenderer('application/vnd.api+json', $httpException);

		$response = $exceptionRenderer->renderHttpAsJsonApi($httpException);

		$this->assertEquals(
			"400",
			$exceptionRenderer->controller->response->statusCode(),
			"Our Controller Response Status Code does not equal 400"
		);
		$this->assertEquals(
			"application/vnd.api+json",
			$exceptionRenderer->controller->response->type(),
			"Our Response Type does not equal application/vnd.api+json"
		);
		$this->assertInternalType(
			"string",
			$exceptionRenderer->controller->response->body(),
			"Our body is not a string"
		);
		$this->assertInstanceOf(
			"stdClass",
			json_decode($exceptionRenderer->controller->response->body()),
			"Our body is not a json_encoded array"
		);
		$this->assertSame(
			'{"errors":{"id":null,"href":null,"status":"400","code":"HttpException","title":"Message","detail":"Message","links":[],"paths":[]}}',
			$exceptionRenderer->controller->response->body(),
			"Our body does not match the expected string"
		);
		$this->assertSame(
			'cake-response-send',
			$response,
			"Our response does not match the expected string"
		);
	}

	/**
	 * test the defaultCakeRender method
	 *
	 * @param string $exceptionCode Exception Code to test for.
	 * @return void
	 * @dataProvider providerHttpExceptions
	 */
	public function testDefaultCakeRender($exceptionCode) {
		$cakeException = new CakeException("Message", $exceptionCode);
		$exceptionRenderer = $this->returnRenderer('text/html', $cakeException);

		$response = $exceptionRenderer->defaultCakeRender($cakeException);

		$this->assertEquals(
			$exceptionCode,
			$exceptionRenderer->controller->response->statusCode(),
			"Our Controller Response Status Code should equal the passed in code of {$exceptionCode}"
		);
		$this->assertEquals(
			'text/html',
			$exceptionRenderer->controller->response->type(),
			"Our Response Type does not equal text/html"
		);
		$this->assertArrayHasKey(
			"code",
			$exceptionRenderer->controller->viewVars,
			"We do not have an code viewVars"
		);
		$this->assertArrayHasKey(
			"name",
			$exceptionRenderer->controller->viewVars,
			"We do not have an name viewVars"
		);
		$this->assertArrayHasKey(
			"message",
			$exceptionRenderer->controller->viewVars,
{'fraction_non_alphanumeric': 0.13883803834666153, 'fraction_numerical': 0.0029482609114558243, 'mean_word_length': 5.180302488984161, 'pattern_counts': {'":': 18, '<': 5, '<?xml version=': 0, '>': 771, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1787330', 'n_tokens_mistral': 16281, 'n_tokens_neox': 14110, 'n_words': 2915}