[MediaWiki-commits] [Gerrit] mediawiki...Quiz[master]: Basic Unit Tests for Quiz Extension

2017-07-14 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/362264 )

Change subject: Basic Unit Tests for Quiz Extension
..


Basic Unit Tests for Quiz Extension

Initial tests class for Quiz.class.php and Question.php is added.

Bug:T159691
Change-Id: Ide874476812dba70c1d2a56aa8a27dfbb99f
---
M Question.php
M Quiz.class.php
A tests/phpunit/QuestionTest.php
A tests/phpunit/QuizTest.php
4 files changed, 301 insertions(+), 5 deletions(-)

Approvals:
  jenkins-bot: Verified
  Mvolz: Looks good to me, approved



diff --git a/Question.php b/Question.php
index c73a33d..9065c3f 100644
--- a/Question.php
+++ b/Question.php
@@ -80,9 +80,10 @@
);
$splitHeaderPattern = '`\n\|\|`';
$unparsedHeader = preg_split( $splitHeaderPattern, $input );
-$output = $this->mParser->recursiveTagParse( trim( 
$unparsedHeader[0] ) . "\n" );
+$output = $this->mParser->recursiveTagParse( trim( 
$unparsedHeader[0] ) );
if ( array_key_exists( 1, $unparsedHeader ) && 
$this->mBeingCorrected ) {
-$output .= '';
+   $output .="\n";
+   $output .= '';
$output .= '';
$output .= $this->mParser->recursiveTagParse( trim( 
$unparsedHeader[1] ) );
$output .= '';
@@ -326,7 +327,6 @@
$this->mProposalPattern .= '([+-])? ?';
}
}
-   $output .= '';
$output .= '' . "\n";
$this->mProposalPattern .= '(.*)`';
return $output;
@@ -509,7 +509,6 @@
}
}
$name = $wqInputId;
-
$temp = $templateParser->processTemplate(
'Answer',
[
diff --git a/Quiz.class.php b/Quiz.class.php
index 0a1aadd..0a43cfa 100644
--- a/Quiz.class.php
+++ b/Quiz.class.php
@@ -26,7 +26,7 @@
$this->mParser = $parser;
$this->mRequest = &$wgRequest;
// Allot a unique identifier to the quiz.
-   $this->mQuizId = self::$sQuizId;
+   $this->mQuizId = $this->getQuizId();
self::$sQuizId++;
// Reset the unique identifier of the questions.
$this->mQuestionId = 0;
@@ -95,6 +95,13 @@
}
 
/**
+* @return int Quiz Id
+*/
+   public function getQuizId() {
+   return self::$sQuizId;
+   }
+
+   /**
 * Accessor for the color array
 * Displays an error message if the colorId doesn't exists.
 *
diff --git a/tests/phpunit/QuestionTest.php b/tests/phpunit/QuestionTest.php
new file mode 100644
index 000..1761954
--- /dev/null
+++ b/tests/phpunit/QuestionTest.php
@@ -0,0 +1,234 @@
+getParser();
+   $title = $wgParser->getTitle();
+   $this->parser = &$wgParser;
+   $this->parser->startExternalParse( $title, $options, 'text', 
true );
+   }
+
+   protected function tearDown() {
+   parent::tearDown();
+   unset( $this->parser );
+   }
+
+   private function getParser() {
+   return new StubObject(
+   'wgParser', $GLOBALS['wgParserConf']['class'],
+   [ $GLOBALS['wgParserConf'] ]
+   );
+   }
+
+   private function getQuestion( $beingCorrected, $caseSensitive, 
$questionId ) {
+   return new Question( $beingCorrected, $caseSensitive, 
$questionId, $this->parser );
+   }
+
+   private function getRequest() {
+   global $wgRequest;
+   return $wgRequest;
+   }
+   public function testGetState() {
+   $this->question = $this->getQuestion( 1, 1, 2 );
+   $state = $this->question->getState();
+   $this->assertThat(
+   $state,
+   $this->logicalOr(
+   $this->equalTo( 'right' ),
+   $this->equalTo( 'error' ),
+   $this->equalTo( 'NA' ),
+   $this->equalTo( 'wrong' )
+   )
+   );
+   }
+
+   public function provideSetState() {
+   return [
+   [ 'NA', 'error', 'error' ],
+   [ 'NA', 'na_wrong', 'na_wrong' ],
+   [ 'na_right', 'na_wrong', 'na_wrong' ],
+   [ 'na_wrong', 'na_right', 'na_wrong' ],
+   [ 'right', 'na_wrong', 'wrong' ],
+   [ 'na_wrong', 'right', 'wrong' ],
+   [ 'error', 'na_wrong', 'error' ]
+   ];
+   }
+
+   /**
+* @dataProvider 

[MediaWiki-commits] [Gerrit] mediawiki...Quiz[master]: Basic Unit Tests for Quiz Extension [WIP]

2017-06-29 Thread Harjotsingh (Code Review)
Harjotsingh has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/362264 )

Change subject: Basic Unit Tests for Quiz Extension [WIP]
..

Basic Unit Tests for Quiz Extension [WIP]

Initial test class for Quiz.class is added to check getColor method.

Bug:T159691
Change-Id: Ide874476812dba70c1d2a56aa8a27dfbb99f
---
A tests/phpunit/QuizTest.php
1 file changed, 46 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Quiz 
refs/changes/64/362264/1

diff --git a/tests/phpunit/QuizTest.php b/tests/phpunit/QuizTest.php
new file mode 100644
index 000..0970382
--- /dev/null
+++ b/tests/phpunit/QuizTest.php
@@ -0,0 +1,46 @@
+getParser();
+   $this->parser = &$wgParser;
+   $this->quiz = new Quiz([], $this->parser );
+   }
+
+   protected function tearDown() {
+   parent::tearDown();
+   }
+
+   private function getParser() {
+   return new StubObject(
+   'wgParser', $GLOBALS['wgParserConf']['class'],
+   array( $GLOBALS['wgParserConf'] )
+   );
+   }
+
+   public function provideGetColor() {
+   return [
+   [ 'right', '#1FF72D' ],
+   [ 'wrong', '#F74245' ],
+   [ 'correction', '#F9F9F9' ],
+   [ 'NA', '#2834FF' ],
+   [ 'error', '#D700D7' ],
+   ];
+   }
+
+   /**
+* @dataProvider provideGetColor
+* @covers Question::getColor
+*/
+   public function testGetColor( $colorId, $expected ) {
+   $color = $this->quiz->getColor( $colorId );
+   $this->assertEquals( $color, $expected );
+   }
+
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/362264
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ide874476812dba70c1d2a56aa8a27dfbb99f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Quiz
Gerrit-Branch: master
Gerrit-Owner: Harjotsingh 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits