Addshore has uploaded a new change for review.
https://gerrit.wikimedia.org/r/91783
Change subject: add basic Status unit test
......................................................................
add basic Status unit test
Adds unit tests for some of the more basic
parts of the Status class
has todos at the bottom of the file for all other
methods that need to be tested
Change-Id: Ic2f2abafb44ef86af207c7595e440672dfcf4f1e
---
A tests/phpunit/includes/StatusTest.php
1 file changed, 177 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/83/91783/1
diff --git a/tests/phpunit/includes/StatusTest.php
b/tests/phpunit/includes/StatusTest.php
new file mode 100644
index 0000000..da1e5fb
--- /dev/null
+++ b/tests/phpunit/includes/StatusTest.php
@@ -0,0 +1,177 @@
+<?php
+
+/**
+ * @author Adam Shorland
+ */
+class StatusTest extends MediaWikiTestCase {
+
+ public function testCanConstruct(){
+ new Status();
+ $this->assertTrue( true );
+ }
+
+ /**
+ * @dataProvider provideValues
+ * @covers Status::newGood
+ * @covers Status::getValue
+ * @covers Status::isGood
+ * @covers Status::isOK
+ */
+ public function testNewGood( $value = null ){
+ $status = Status::newGood( $value );
+ $this->assertTrue( $status->isGood() );
+ $this->assertTrue( $status->isOK() );
+ $this->assertEquals( $value, $status->getValue() );
+ }
+
+ public static function provideValues(){
+ return array(
+ array(),
+ array( 'foo' ),
+ array( array( 'foo' => 'bar' ) ),
+ array( new Exception() ),
+ array( 1234 ),
+ );
+ }
+
+ /**
+ * @covers Status:newFatal
+ * @covers Status::isGood
+ * @covers Status::isOK
+ * @covers Status:getMessage
+ */
+ public function testNewFatalWithMessage() {
+ $message = $this->getMockBuilder( 'Message' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $status = Status::newFatal( $message );
+ $this->assertFalse( $status->isGood() );
+ $this->assertFalse( $status->isOK() );
+ $this->assertEquals( $message, $status->getMessage() );
+ }
+
+ /**
+ * @covers Status:newFatal
+ * @covers Status::isGood
+ * @covers Status::isOK
+ * @covers Status:getMessage
+ */
+ public function testNewFatalWithString() {
+ $message = 'foo';
+ $status = Status::newFatal( $message );
+ $this->assertFalse( $status->isGood() );
+ $this->assertFalse( $status->isOK() );
+ $newMessage = $status->getMessage();
+ $this->assertEquals( $message, $newMessage->getKey() );
+ }
+
+ /**
+ * @dataProvider provideSetResult
+ * @covers Status::getValue
+ * @covers Status::isOK
+ */
+ public function testSetResult( $ok, $value = null ) {
+ $status = new Status();
+ $status->setResult( $ok, $value );
+ $this->assertEquals( $ok, $status->isOK() );
+ $this->assertEquals( $value, $status->getValue() );
+ }
+
+ public static function provideSetResult() {
+ return array(
+ array( true ),
+ array( false ),
+ array( true, 'value' ),
+ array( false, 'value' ),
+ );
+ }
+
+ /**
+ * @dataProvider provideMockMessageDetails
+ * @covers Status::warning
+ * @covers Status::getWarningsArray
+ */
+ public function testWarningWithMessage( $mockDetails ) {
+ $status = new Status();
+ $messages = $this->getMockMessages( $mockDetails );
+
+ foreach( $messages as $message ){
+ $status->warning( $message );
+ }
+ $warnings = $status->getWarningsArray();
+
+ $this->assertEquals( count( $messages ), count( $warnings ) );
+ foreach( $messages as $key => $message ) {
+ $expectedArray = array_merge( array( $message->getKey()
), $message->getParams() );
+ $this->assertEquals( $warnings[$key], $expectedArray );
+ }
+ }
+
+ /**
+ * @dataProvider provideMockMessageDetails
+ * @covers Status::error
+ * @covers Status::getErrorsArray
+ */
+ public function testErrorWithMessage( $mockDetails ) {
+ $status = new Status();
+ $messages = $this->getMockMessages( $mockDetails );
+
+ foreach( $messages as $message ){
+ $status->error( $message );
+ }
+ $errors = $status->getErrorsArray();
+
+ $this->assertEquals( count( $messages ), count( $errors ) );
+ foreach( $messages as $key => $message ) {
+ $expectedArray = array_merge( array( $message->getKey()
), $message->getParams() );
+ $this->assertEquals( $errors[$key], $expectedArray );
+ }
+ }
+
+ protected function getMockMessage( $key = 'key', $params = array() ) {
+ $message = $this->getMockBuilder( 'Message' )
+ ->disableOriginalConstructor()
+ ->getMock();
+ $message->expects( $this->atLeastOnce() )
+ ->method( 'getKey' )
+ ->will( $this->returnValue( $key ) );
+ $message->expects( $this->atLeastOnce() )
+ ->method( 'getParams' )
+ ->will( $this->returnValue( $params ) );
+ return $message;
+ }
+
+ /**
+ * @param array $messageDetails eg. array( 'KEY' => array(/PARAMS/) )
+ * @return Message[]
+ */
+ protected function getMockMessages( $messageDetails ){
+ $messages = array();
+ foreach( $messageDetails as $key => $paramsArray ){
+ $messages[] = $this->getMockMessage( $key, $paramsArray
);
+ }
+ return $messages;
+ }
+
+ public static function provideMockMessageDetails(){
+ return array(
+ array( array( 'key1' => array( 'foo' => 'bar' ) ) ),
+ array( array( 'key1' => array( 'foo' => 'bar' ), 'key2'
=> array( 'foo2' => 'bar2' ) ) ),
+ );
+ }
+
+ //todo test cleanParams
+ //todo test getWikiText
+ //todo test getMessage
+ //todo test getErrorMessage
+ //todo test getHTML
+ //todo test getErrorMessageArray
+ //todo test merge
+ //todo test getStatusArray
+ //todo test getErrorsByType
+ //todo test hasMessage
+ //todo test replaceMessage
+ //todo test replaceMessage
+
+}
\ No newline at end of file
--
To view, visit https://gerrit.wikimedia.org/r/91783
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic2f2abafb44ef86af207c7595e440672dfcf4f1e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits