jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/367327 )

Change subject: Remove empty cell from settings table in Quiz
......................................................................


Remove empty cell from settings table in Quiz

Currently a empty cell is seen inside settings table which is caused by
<tr></tr> tags from mustache template.This patch removes the tags and alters
the template.It also adds tests for setting template.

Bug: T171154
Change-Id: Idb35c7a6aa95ad7bf9d4e9a13d42d7088f33567e
---
M Quiz.class.php
M templates/Setting.mustache
M tests/phpunit/QuizTest.php
3 files changed, 117 insertions(+), 21 deletions(-)

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



diff --git a/Quiz.class.php b/Quiz.class.php
index ffa930d..d139c24 100644
--- a/Quiz.class.php
+++ b/Quiz.class.php
@@ -94,27 +94,13 @@
        }
 
        /**
-        * Convert the input text to an HTML output.
+        * Get HTML from template using TemplateParser
         *
-        * @param $input String: text between <quiz> and </quiz> tags, in quiz 
syntax.
+        * @param $templateParser TemplateParser
         * @return string
         */
-       function parseQuiz( $input ) {
-               // Ouput the style and the script to the header once for all.
-               if ( $this->mQuizId == 0 ) {
-                       $this->mParser->getOutput()->addModules( 'ext.quiz' );
-                       $this->mParser->getOutput()->addModuleStyles( 
'ext.quiz.styles' );
-               }
-
-               // Process the input
-               $input = $this->parseQuestions( $this->parseIncludes( $input ) 
);
-
-               // Generates the output.
-
-               $templateParser = new TemplateParser( __DIR__ . '/templates' );
-               $checked = '';
-               // Determine the content of the settings table.
-               $settingsTable = '';
+       function getSettingsTable( $templateParser ) {
+               $checked = $this->mIgnoringCoef ? 'checked="checked"' : '';
                $settingsTable = $templateParser->processTemplate(
                        'Setting',
                        [
@@ -122,8 +108,10 @@
                                        $this->mState === 'error' ),
                                'isSettingOtherRow' => ( !$this->mDisplaySimple 
|| $this->mBeingCorrected ),
                                'notSimple' => !$this->mDisplaySimple,
-                               'corrected' => $this->mBeingCorrected,
+                               'corrected' => ( $this->mBeingCorrected && 
$this->mBeingCorrected ),
                                'shuffle' => $this->mShuffle,
+                               'shuffleOrError' => ( $this->mShuffle && 
$this->numberQuestions > 1 ) ||
+                                       $this->mState === 'error',
                                'error' => $this->mState === 'error',
                                'wfMessage' => [
                                        'quiz_added' => wfMessage( 
'quiz_addedPoints', $this->mAddedPoints )->text(),
@@ -141,6 +129,30 @@
                                'shuffleDisplay' => $this->numberQuestions > 1
                        ]
                );
+               return $settingsTable;
+       }
+
+       /**
+        * Convert the input text to an HTML output.
+        *
+        * @param $input String: text between <quiz> and </quiz> tags, in quiz 
syntax.
+        * @return string
+        */
+       function parseQuiz( $input ) {
+               // Ouput the style and the script to the header once for all.
+               if ( $this->mQuizId == 0 ) {
+                       $this->mParser->getOutput()->addModules( 'ext.quiz' );
+                       $this->mParser->getOutput()->addModules( 
'ext.quiz.styles' );
+               }
+
+               // Process the input
+               $input = $this->parseQuestions( $this->parseIncludes( $input ) 
);
+
+               // Generates the output.
+               $templateParser = new TemplateParser( __DIR__ . '/templates' );
+               // Determine the content of the settings table.
+               $settingsTable = '';
+               $settingsTable = $this->getSettingsTable( $templateParser );
 
                $quiz_score = wfMessage( 'quiz_score' )->rawParams(
                        '<span class="score">' . $this->mScore . '</span>',
diff --git a/templates/Setting.mustache b/templates/Setting.mustache
index 41f0add..47b8c95 100644
--- a/templates/Setting.mustache
+++ b/templates/Setting.mustache
@@ -41,14 +41,15 @@
        </tr>
 {{/ isSettingOtherRow}}
 {{# notSimple}}
+       {{# shuffleOrError}}
        <tr>
-               {{# shuffle}}
+               {{#if shuffle}}
                        {{^ corrected}}
                                {{# shuffleDisplay}}
                                        <td><input class="shuffle" 
name="shuffleButton" type="button" value="{{ wfMessage.quiz_shuffle }}"/></td>
                                {{/ shuffleDisplay}}
                        {{/ corrected}}
-               {{/ shuffle}}
+               {{/if}}
                {{^ shuffle}}
                        <td></td>
                {{/ shuffle}}
@@ -62,4 +63,5 @@
                        {{/ corrected}}
                {{/ error}}
        </tr>
+       {{/ shuffleOrError}}
 {{/ notSimple}}
diff --git a/tests/phpunit/QuizTest.php b/tests/phpunit/QuizTest.php
index 5c9e68f..da5669d 100644
--- a/tests/phpunit/QuizTest.php
+++ b/tests/phpunit/QuizTest.php
@@ -26,6 +26,7 @@
        protected function tearDown() {
                parent::tearDown();
                unset( $this->parser );
+               unset( $this->quiz );
        }
 
        private function getParser() {
@@ -85,4 +86,85 @@
                $this->assertEquals( $output, $expected );
        }
 
+       public function provideGetSettingsTable() {
+               return [
+                       // Test case when simple display is disabled, it is not 
being corrected, state is NA
+                       // added and cutoff points are 3 and -1 respectively 
with 4 questions in quiz
+                       [ [ '0', '0', 'NA', '1', '3', '-1', '1', '4' ],
+                        "\n\t" . '<tr>' . "\n\t\n\t\t" . '<td><label 
for="addedPoints">' .
+                        'Points added for a correct answer:</label></td>' .
+                        "\n\t\t" . '<td><input class="numerical" type="number" 
' .
+                        'name="addedPoints" id="addedPoints" 
value="3"/>&#160;&#160;</td>' . "\n\t\n\t\n\t\n\t" .
+                        '</tr>' . "\n\n\n\t" . '<tr>' . "\n\t\n\t\t" . 
'<td><label for="cutoffPoints">'
+                        . 'Point for a wrong answer:</label></td>'
+                        . "\n\t\t" . '<td><input class="numerical" 
type="number" ' .
+                        'name="cutoffPoints" id="cutoffPoints" 
value="-1"/></td>' . "\n\t\n\t\n\t" .
+                        '</tr>' . "\n\n\n\t" . '<tr>' . "\n\t\n\t\t" . 
'<td><label for="ignoringCoef">'
+                        . 'Ignore the questions' . "'" . ' 
coefficients:</label></td>'
+                        . "\n\t\t" . '<td><input type="checkbox" 
name="ignoringCoef" id="ignoringCoef" ' .
+                        'checked="checked"/></td>' . "\n\t\n\t\n\t" .
+                        '</tr>' . "\n\n\n\t\n\t" . '<tr>' . 
"\n\t\t\n\t\t\t\n\t\t\t\t\n\t\t\t\t\t"
+                        . '<td><input class="shuffle" name="shuffleButton" 
type="button" ' .
+                        'value="Shuffle questions"/></td>' . 
"\n\t\t\t\t\n\t\t\t\n\t\t\n\t\t"
+                        . "\n\t\t\n\t\t\t" . '<td></td>' ."\n\t\t\n\t\t\n\t" . 
'</tr>' . "\n\t\n\n"
+                       ],
+                       // Test case when simple display is disabled, it is 
being corrected, state is NA
+                       // added and cutoff points are 1 and 0 respectively 
with 2 questions in quiz
+                       [ [ '0', '1', 'NA', '1', '1', '0', '1', '2' ],
+                        "\n\t" . '<tr>' . "\n\t\n\t\t" . '<td><label 
for="addedPoints">' .
+                        'Point added for a correct answer:</label></td>'
+                        . "\n\t\t" . '<td><input class="numerical" 
type="number" name="addedPoints" ' .
+                        'id="addedPoints" value="1"/>&#160;&#160;</td>' . 
"\n\t\n\t\n\t\t" .
+                        '<td class="margin right"></td>' . "\n\t\t\t" .
+                        '<td style="background: transparent;">Right</td>' . 
"\n\t\n\t\n\t" . '</tr>' .
+                        "\n\n\n\t" . '<tr>' . "\n\t\n\t\t" . '<td><label 
for="cutoffPoints">' .
+                        'Points for a wrong answer:</label></td>' . "\n\t\t" .
+                        '<td><input class="numerical" type="number" 
name="cutoffPoints" id="cutoffPoints"' .
+                        ' value="0"/></td>' . "\n\t\n\t\n\t\t" . '<td 
class="margin wrong"></td>' . "\n\t\t"
+                        . '<td style="background: transparent;">Wrong</td>' . 
"\n\t\n\t" . '</tr>'
+                        . "\n\n\n\t" . '<tr>' . "\n\t\n\t\t" .
+                        '<td><label for="ignoringCoef">Ignore the questions'
+                        . "'" . ' coefficients:</label></td>'
+                        . "\n\t\t" . '<td><input type="checkbox" 
name="ignoringCoef" id="ignoringCoef"' .
+                        ' checked="checked"/></td>' . "\n\t\n\t\n\t\t" .
+                        '<td class="margin NA"></td>' . "\n\t\t" .
+                        '<td style="background: transparent;">Not 
answered</td>' . "\n\t\n\t"
+                        . '</tr>' . "\n\n\n\t\n\t" . '<tr>' . 
"\n\t\t\n\t\t\t\n\t\t\n\t\t\n\t\t\n\t\t\n\t" .
+                        '</tr>' . "\n\t\n\n"
+                       ],
+                       // Test case for simple display enabled and quiz is not 
being corrected
+                       [ [ '1', '0', 'NA', '1', '1', '0', '1', '3' ],
+                        "\n\n\n\n"
+                       ],
+                       // Test case for simple display enabled and quiz is 
being corrected
+                       [ [ '1', '1', 'NA', '1', '1', '0', '1', '2' ],
+                        "\n\t" . '<tr>' . "\n\t\n\t\n\t\t" . '<td 
class="margin right"></td>'
+                        . "\n\t\t\t" . '<td style="background: 
transparent;">Right</td>' . "\n\t\n\t\n\t" . '</tr>'
+                        . "\n\n\n\t" . '<tr>' . "\n\t\n\t\n\t\t" . '<td 
class="margin wrong"></td>'
+                        . "\n\t\t" . '<td style="background: 
transparent;">Wrong</td>' . "\n\t\n\t" . '</tr>'
+                        . "\n\n\n\t" . '<tr>' . "\n\t\n\t\n\t\t" . '<td 
class="margin NA"></td>' . "\n\t\t"
+                        . '<td style="background: transparent;">Not 
answered</td>' . "\n\t\n\t" . '</tr>' . "\n\n\n"
+                       ],
+               ];
+       }
+
+       /**
+        * @dataProvider provideGetSettingsTable
+        * @covers Quiz::getSettingsTable
+        */
+       public function testGetSettingsTable( $injected = [], $expected ) {
+               // Setting quiz variables
+               $this->quiz->mDisplaySimple = $injected[0];
+               $this->quiz->mBeingCorrected = $injected[1];
+               $this->quiz->mState = $injected[2];
+               $this->quiz->mShuffle = $injected[3];
+               $this->quiz->mAddedPoints = $injected[4];
+               $this->quiz->mCutoffPoints = $injected[5];
+               $this->quiz->mIgnoringCoef = $injected[6];
+               $this->quiz->numberQuestions = $injected[7];
+               $templateParser = new TemplateParser( __DIR__ . 
'/../../templates' );
+               $settingsTable = $this->quiz->getSettingsTable( $templateParser 
);
+               $this->assertEquals( $settingsTable, $expected );
+       }
+
 }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Idb35c7a6aa95ad7bf9d4e9a13d42d7088f33567e
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/Quiz
Gerrit-Branch: master
Gerrit-Owner: Harjotsingh <harjo...@ymail.com>
Gerrit-Reviewer: Harjotsingh <harjo...@ymail.com>
Gerrit-Reviewer: Mvolz <mv...@wikimedia.org>
Gerrit-Reviewer: Reedy <re...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to