Debian Codegraph @

tests/phpunit/unit/includes/exception/HttpErrorTest.php

raw symbols SCIP
1 <?php
2
3 use MediaWiki\Message\Message;
4
5 /**
6 * @todo tests for HttpError::report
7 *
8 * @covers \HttpError
9 */
10 class HttpErrorTest extends MediaWikiUnitTestCase {
11
12 public function testIsLoggable() {
13 $httpError = new HttpError( 500, 'server error!' );
14 $this->assertFalse( $httpError->isLoggable(), 'http error is not loggable' );
15 }
16
17 public function testGetStatusCode() {
18 $httpError = new HttpError( 500, 'server error!' );
19 $this->assertEquals( 500, $httpError->getStatusCode() );
20 }
21
22 /**
23 * @dataProvider getHtmlProvider
24 */
25 public function testGetHtml( array $expected, $content, $header ) {
26 $httpError = new HttpError( 500, $content, $header );
27 $errorHtml = $httpError->getHTML();
28
29 foreach ( $expected as $key => $html ) {
30 $this->assertStringContainsString( $html, $errorHtml, $key );
31 }
32 }
33
34 public function getHtmlProvider() {
35 // Avoid parsing logic in real Message class which includes text transformations
36 // that require MediaWikiServices
37 $content = $this->createMock( Message::class );
38 $content->method( 'escaped' )->willReturn( 'suspicious-userlogout' );
39 $header = $this->createMock( Message::class );
40 $header->method( 'escaped' )->willReturn( 'loginerror' );
41
42 return [
43 [
44 [
45 'head html' => '<head><title>Server Error 123</title>',
46 'body html' => '<body><h1>Server Error 123</h1>'
47 . '<p>a server error!</p></body>'
48 ],
49 'a server error!',
50 'Server Error 123'
51 ],
52 [
53 [
54 'head html' => '<head><title>loginerror</title>',
55 'body html' => '<body><h1>loginerror</h1>'
56 . '<p>suspicious-userlogout</p></body>'
57 ],
58 $content,
59 $header
60 ],
61 [
62 [
63 'head html' => '<html><head><title>Internal Server Error</title>',
64 'body html' => '<body><h1>Internal Server Error</h1>'
65 . '<p>a server error!</p></body></html>'
66 ],
67 'a server error!',
68 null
69 ]
70 ];
71 }
72 }