From acfff1bff15f1fe225425c4d8908d5c2a8522062 Mon Sep 17 00:00:00 2001 From: aude Date: Mon, 1 Jun 2015 20:19:19 +0200 Subject: [PATCH] Add tests for HttpError Still missing tests for HttpError::report, but would have caught the issue that Ie216d19 fixed. Change-Id: Ic35d70af52c3a2d2a25fc3b9952383198db31fb1 --- includes/exception/HttpError.php | 2 +- .../includes/exception/HttpErrorTest.php | 65 +++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 tests/phpunit/includes/exception/HttpErrorTest.php diff --git a/includes/exception/HttpError.php b/includes/exception/HttpError.php index aba9176c6e..d3ee9b95ba 100644 --- a/includes/exception/HttpError.php +++ b/includes/exception/HttpError.php @@ -35,7 +35,7 @@ class HttpError extends MWException { * * @param int $httpCode HTTP status code to send to the client * @param string|Message $content Content of the message - * @param string|Message $header Content of the header (\ and \) + * @param string|Message|null $header Content of the header (\ and \) */ public function __construct( $httpCode, $content, $header = null ) { parent::__construct( $content ); diff --git a/tests/phpunit/includes/exception/HttpErrorTest.php b/tests/phpunit/includes/exception/HttpErrorTest.php new file mode 100644 index 0000000000..66fe90c955 --- /dev/null +++ b/tests/phpunit/includes/exception/HttpErrorTest.php @@ -0,0 +1,65 @@ +assertFalse( $httpError->isLoggable(), 'http error is not loggable' ); + } + + public function testGetStatusCode() { + $httpError = new HttpError( 500, 'server error!' ); + $this->assertEquals( 500, $httpError->getStatusCode() ); + } + + /** + * @dataProvider getHtmlProvider + */ + public function testGetHtml( array $expected, $content, $header ) { + $httpError = new HttpError( 500, $content, $header ); + $errorHtml = $httpError->getHtml(); + + foreach ( $expected as $key => $html ) { + $this->assertContains( $html, $errorHtml, $key ); + } + } + + public function getHtmlProvider() { + return array( + array( + array( + 'head html' => 'Server Error 123', + 'body html' => '

Server Error 123

' + . '

a server error!

' + ), + 'a server error!', + 'Server Error 123' + ), + array( + array( + 'head html' => 'loginerror', + 'body html' => '

loginerror

' + . '

suspicious-userlogout

' + ), + new RawMessage( 'suspicious-userlogout' ), + new RawMessage( 'loginerror' ) + ), + array( + array( + 'head html' => 'Internal Server Error', + 'body html' => '

Internal Server Error

' + . '

a server error!

' + ), + 'a server error!', + null + ) + ); + } + + +} -- 2.20.1