Add tests exceptions
authoraddshore <addshorewiki@gmail.com>
Thu, 27 Feb 2014 00:00:17 +0000 (01:00 +0100)
committeraddshore <addshorewiki@gmail.com>
Thu, 27 Feb 2014 00:07:03 +0000 (01:07 +0100)
- ErrorPageError
- ReadOnlyError
- UserNotLoggedIn

Change-Id: I9d0088d38e26a6b77e371288f1fa72dbe481cf66

tests/phpunit/includes/exception/ErrorPageErrorTest.php [new file with mode: 0644]
tests/phpunit/includes/exception/ReadOnlyErrorTest.php [new file with mode: 0644]
tests/phpunit/includes/exception/UserNotLoggedInTest.php [new file with mode: 0644]

diff --git a/tests/phpunit/includes/exception/ErrorPageErrorTest.php b/tests/phpunit/includes/exception/ErrorPageErrorTest.php
new file mode 100644 (file)
index 0000000..4cfcd83
--- /dev/null
@@ -0,0 +1,67 @@
+<?php
+
+/**
+ * @covers ErrorPageError
+ * @author Adam Shorland
+ */
+class ErrorPageErrorTest extends MediaWikiTestCase {
+
+       private $wgOut;
+
+       protected function setUp() {
+               parent::setUp();
+               global $wgOut;
+               $this->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 (file)
index 0000000..352ec65
--- /dev/null
@@ -0,0 +1,16 @@
+<?php
+
+/**
+ * @covers ReadOnlyError
+ * @author Adam Shorland
+ */
+class ReadOnlyErrorTest extends MediaWikiTestCase {
+
+       public function testConstruction() {
+               $e = new ReadOnlyError();
+               $this->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 (file)
index 0000000..591a0fa
--- /dev/null
@@ -0,0 +1,16 @@
+<?php
+
+/**
+ * @covers UserNotLoggedIn
+ * @author Adam Shorland
+ */
+class UserNotLoggedInTest extends MediaWikiTestCase {
+
+       public function testConstruction() {
+               $e = new UserNotLoggedIn();
+               $this->assertEquals( 'exception-nologin', $e->title );
+               $this->assertEquals( 'exception-nologin-text', $e->msg );
+               $this->assertEquals( array(), $e->params );
+       }
+
+}