Add test for BadTitleError exception
authoraddshore <addshorewiki@gmail.com>
Tue, 25 Feb 2014 19:09:17 +0000 (20:09 +0100)
committeraddshore <addshorewiki@gmail.com>
Tue, 25 Feb 2014 21:35:48 +0000 (22:35 +0100)
Change-Id: Ib7c5b9f385aa3fc3e68c55927b0cd5adc82ac1d1

tests/phpunit/includes/exception/BadTitleErrorTest.php [new file with mode: 0644]

diff --git a/tests/phpunit/includes/exception/BadTitleErrorTest.php b/tests/phpunit/includes/exception/BadTitleErrorTest.php
new file mode 100644 (file)
index 0000000..6f9804d
--- /dev/null
@@ -0,0 +1,44 @@
+<?php
+/**
+ * @covers BadTitleError
+ * @author Adam Shorland
+ */
+class BadTitleErrorTest extends MediaWikiTestCase {
+
+       protected $wgOut;
+
+       protected function setUp() {
+               parent::setUp();
+               global $wgOut;
+               $this->wgOut = clone $wgOut;
+       }
+
+       protected function tearDown() {
+               parent::tearDown();
+               global $wgOut;
+               $wgOut = $this->wgOut;
+       }
+
+       public function testExceptionSetsStatusCode() {
+               global $wgOut;
+               $wgOut = $this->getMockWgOut();
+               try{
+                       throw new BadTitleError();
+               }
+               catch( BadTitleError $e ) {
+                       $e->report();
+                       $this->assertTrue( true );
+               }
+       }
+
+       private function getMockWgOut() {
+               $mock = $this->getMockBuilder( 'OutputPage' )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+               $mock->expects( $this->once() )
+                       ->method( 'setStatusCode' )
+                       ->with( 400 );
+               return $mock;
+       }
+
+}