From: addshore Date: Thu, 27 Feb 2014 00:00:17 +0000 (+0100) Subject: Add tests exceptions X-Git-Tag: 1.31.0-rc.0~16736^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/ajouter.php?a=commitdiff_plain;h=9e975c4a248bb0d626747dccef064745b6840abd;p=lhc%2Fweb%2Fwiklou.git Add tests exceptions - ErrorPageError - ReadOnlyError - UserNotLoggedIn Change-Id: I9d0088d38e26a6b77e371288f1fa72dbe481cf66 --- 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 ); + } + +}