From 9e975c4a248bb0d626747dccef064745b6840abd Mon Sep 17 00:00:00 2001 From: addshore Date: Thu, 27 Feb 2014 01:00:17 +0100 Subject: [PATCH] Add tests exceptions - ErrorPageError - ReadOnlyError - UserNotLoggedIn Change-Id: I9d0088d38e26a6b77e371288f1fa72dbe481cf66 --- .../includes/exception/ErrorPageErrorTest.php | 67 +++++++++++++++++++ .../includes/exception/ReadOnlyErrorTest.php | 16 +++++ .../exception/UserNotLoggedInTest.php | 16 +++++ 3 files changed, 99 insertions(+) create mode 100644 tests/phpunit/includes/exception/ErrorPageErrorTest.php create mode 100644 tests/phpunit/includes/exception/ReadOnlyErrorTest.php create mode 100644 tests/phpunit/includes/exception/UserNotLoggedInTest.php diff --git a/tests/phpunit/includes/exception/ErrorPageErrorTest.php b/tests/phpunit/includes/exception/ErrorPageErrorTest.php new file mode 100644 index 0000000000..4cfcd83e3e --- /dev/null +++ b/tests/phpunit/includes/exception/ErrorPageErrorTest.php @@ -0,0 +1,67 @@ +wgOut = clone $wgOut; + } + + protected function tearDown() { + global $wgOut; + $wgOut = $this->wgOut; + parent::tearDown(); + } + + private function getMockMessage() { + $mockMessage = $this->getMockBuilder( 'Message' ) + ->disableOriginalConstructor() + ->getMock(); + $mockMessage->expects( $this->once() ) + ->method( 'inLanguage' ) + ->will( $this->returnValue( $mockMessage ) ); + $mockMessage->expects( $this->once() ) + ->method( 'useDatabase' ) + ->will( $this->returnValue( $mockMessage ) ); + return $mockMessage; + } + + public function testConstruction() { + $mockMessage = $this->getMockMessage(); + $title = 'Foo'; + $params = array( 'Baz' ); + $e = new ErrorPageError( $title, $mockMessage, $params ); + $this->assertEquals( $title, $e->title ); + $this->assertEquals( $mockMessage, $e->msg ); + $this->assertEquals( $params, $e->params ); + } + + public function testReport() { + $mockMessage = $this->getMockMessage(); + $title = 'Foo'; + $params = array( 'Baz' ); + + global $wgOut; + $wgOut = $this->getMockBuilder( 'OutputPage' ) + ->disableOriginalConstructor() + ->getMock(); + $wgOut->expects( $this->once() ) + ->method( 'showErrorPage' ) + ->with( $title, $mockMessage, $params ); + $wgOut->expects( $this->once() ) + ->method( 'output' ); + + $e = new ErrorPageError( $title, $mockMessage, $params ); + $e->report(); + } + + + +} diff --git a/tests/phpunit/includes/exception/ReadOnlyErrorTest.php b/tests/phpunit/includes/exception/ReadOnlyErrorTest.php new file mode 100644 index 0000000000..352ec657e9 --- /dev/null +++ b/tests/phpunit/includes/exception/ReadOnlyErrorTest.php @@ -0,0 +1,16 @@ +assertEquals( 'readonly', $e->title ); + $this->assertEquals( 'readonlytext', $e->msg ); + $this->assertEquals( wfReadOnlyReason()?: array(), $e->params ); + } + +} diff --git a/tests/phpunit/includes/exception/UserNotLoggedInTest.php b/tests/phpunit/includes/exception/UserNotLoggedInTest.php new file mode 100644 index 0000000000..591a0fa1ea --- /dev/null +++ b/tests/phpunit/includes/exception/UserNotLoggedInTest.php @@ -0,0 +1,16 @@ +assertEquals( 'exception-nologin', $e->title ); + $this->assertEquals( 'exception-nologin-text', $e->msg ); + $this->assertEquals( array(), $e->params ); + } + +} -- 2.20.1