Selaa lähdekoodia

Merge branch '1.11.x' of github.com:chamilo/chamilo-lms into 1.11.x

Yannick Warnier 6 vuotta sitten
vanhempi
commit
562de37aab

+ 1 - 1
main/exercise/TestCategory.php

@@ -801,7 +801,7 @@ class TestCategory
         }
         }
         $category_name_list = self::getListOfCategoriesNameForTest($exerciseId);
         $category_name_list = self::getListOfCategoriesNameForTest($exerciseId);
 
 
-        $table = new HTML_Table(['class' => 'table table-bordered']);
+        $table = new HTML_Table(['class' => 'table table-bordered', 'id' => 'category_results']);
         $table->setHeaderContents(0, 0, get_lang('Categories'));
         $table->setHeaderContents(0, 0, get_lang('Categories'));
         $table->setHeaderContents(0, 1, get_lang('AbsoluteScore'));
         $table->setHeaderContents(0, 1, get_lang('AbsoluteScore'));
         $table->setHeaderContents(0, 2, get_lang('RelativeScore'));
         $table->setHeaderContents(0, 2, get_lang('RelativeScore'));

+ 5 - 0
main/exercise/overview.php

@@ -83,6 +83,11 @@ if ($is_allowed_to_edit && $objExercise->sessionId == $sessionId) {
         Display::return_icon('edit.png', get_lang('Edit'), [], ICON_SIZE_SMALL),
         Display::return_icon('edit.png', get_lang('Edit'), [], ICON_SIZE_SMALL),
         api_get_path(WEB_CODE_PATH).'exercise/admin.php?'.api_get_cidreq().'&exerciseId='.$objExercise->id
         api_get_path(WEB_CODE_PATH).'exercise/admin.php?'.api_get_cidreq().'&exerciseId='.$objExercise->id
     );
     );
+} elseif (api_is_teacher()) {
+    $edit_link = Display::url(
+        Display::return_icon('test_results.png', get_lang('Results'), [], ICON_SIZE_SMALL),
+        'exercise_report.php?'.api_get_cidreq().'&exerciseId='.$objExercise->id
+    );
 }
 }
 $iconExercise = Display::return_icon('test-quiz.png', null, [], ICON_SIZE_MEDIUM);
 $iconExercise = Display::return_icon('test-quiz.png', null, [], ICON_SIZE_MEDIUM);
 // Exercise name.
 // Exercise name.

+ 95 - 2
tests/behat/features/bootstrap/FeatureContext.php

@@ -1,5 +1,6 @@
 <?php
 <?php
 
 
+use Behat\Gherkin\Node\TableNode;
 use Behat\MinkExtension\Context\MinkContext;
 use Behat\MinkExtension\Context\MinkContext;
 
 
 /**
 /**
@@ -141,7 +142,7 @@ class FeatureContext extends MinkContext
     {
     {
         $this->visit('/index.php?logout=logout');
         $this->visit('/index.php?logout=logout');
         $this->iAmOnHomepage();
         $this->iAmOnHomepage();
-        $this->fillFields(new \Behat\Gherkin\Node\TableNode([
+        $this->fillFields(new TableNode([
             ['login', $username],
             ['login', $username],
             ['password', $username]
             ['password', $username]
         ]));
         ]));
@@ -181,7 +182,7 @@ class FeatureContext extends MinkContext
     public function iHaveAPublicPasswordProtectedCourse($code, $password)
     public function iHaveAPublicPasswordProtectedCourse($code, $password)
     {
     {
         $this->visit('/main/admin/course_add.php');
         $this->visit('/main/admin/course_add.php');
-        $this->fillFields(new \Behat\Gherkin\Node\TableNode([
+        $this->fillFields(new TableNode([
             ['title', 'Password Protected'],
             ['title', 'Password Protected'],
             ['visual_code', $code],
             ['visual_code', $code],
             ['visibility', 3]
             ['visibility', 3]
@@ -471,4 +472,96 @@ class FeatureContext extends MinkContext
         }
         }
         return false;
         return false;
     }
     }
+
+    /**
+     * @Given /^I am a student subscribed to session "([^"]*)"$/
+     *
+     * @param string$sessionName
+     */
+    public function iAmStudentSubscribedToXSession($sessionName)
+    {
+        $this->iAmAPlatformAdministrator();
+        $this->visit('/main/session/session_add.php');
+        $this->fillField('name', $sessionName);
+        $this->pressButton('Next step');
+        $this->selectOption('NoSessionCoursesList[]', 'TEMP (TEMP)');
+        $this->pressButton('add_course');
+        $this->pressButton('Next step');
+        $this->assertPageContainsText('Update successful');
+        $this->fillField('user_to_add', 'acostea');
+        $this->waitForThePageToBeLoaded();
+        $this->clickLink('Costea Andrea (acostea)');
+        $this->pressButton('Finish session creation');
+        $this->assertPageContainsText('Session overview');
+        //$this->assertPageContainsText('Costea Andrea (acostea)');
+        $this->iAmAStudent();
+    }
+
+    /**
+     * Example: Then I should see the table "#category_results":
+     *               | Categories    | Absolute score | Relative score |
+     *               | Categoryname2 | 50 / 70        | 71.43%         |
+     *               | Categoryname1 | 60 / 60        | 100%           |
+     *
+     * @Then /^I should see the table "([^"]*)":$/
+     *
+     * @param string    $tableId
+     * @param TableNode $tableData
+     *
+     * @throws Exception
+     */
+    public function assertPageContainsTable($tableId, TableNode $tableData)
+    {
+        $table = $this->getSession()->getPage()->find('css', $tableId);
+        $rows = $tableData->getRowsHash();
+        $i = 1;
+
+        $right = array_keys($rows);
+
+        foreach ($right as $text) {
+            $cell = $table->find('css', 'tr:nth-child('.$i.') :nth-child(1)');
+            $i++;
+
+            if (!$cell) {
+                throw new Exception('Cell not found.');
+            }
+
+            if ($cell->getText() != $text) {
+                throw new Exception('Table text not found.');
+            }
+        }
+
+        $i = 1;
+
+        foreach ($rows as $field => $cols) {
+            if (is_array($cols)) {
+                $j = 2;
+
+                foreach ($cols as $col) {
+                    $cell = $table->find('css', 'tr:nth-child('.$i.') :nth-child('.$j.')');
+                    $j++;
+
+                    if (!$cell) {
+                        throw new Exception('Cell not found.');
+                    }
+
+                    if ($cell->getText() != $col) {
+                        throw new Exception('Table text not found. Found "'.$cell->getText().'" <> "'.$col.'"');
+                    }
+                }
+            } else {
+                $cell = $table->find('css', 'tr:nth-child('.$i.') :nth-child(2)');
+
+                if (!$cell) {
+                    throw new Exception('Cell not found.');
+                }
+
+                if ($cell->getText() != $cols) {
+                    throw new Exception('Table text not found. Found "'.$cell->getText().'" <> "'.$cols.'"');
+                }
+            }
+
+            $i++;
+        }
+    }
 }
 }

+ 71 - 0
tests/behat/features/toolExercise.feature

@@ -310,6 +310,77 @@ Feature: Exercise tool
     Then I should see "Exercise copied"
     Then I should see "Exercise copied"
     And I should see "Exercise 1 - Copy"
     And I should see "Exercise 1 - Copy"
 
 
+  Scenario: Import exercise to test questions categories
+    Given I am on "/main/exercise/upload_exercise.php?cidReq=TEMP"
+    And I should see "Import quiz from Excel"
+    And I attach the file "/tests/behat/uploadable_files/exercise.xls" to "user_upload_quiz"
+    When I press "Upload"
+    And wait for the page to be loaded
+    Then I should see "Exercise for Behat test"
+
+  Scenario: Try exercise with categorized questions as student
+    Given I am a student subscribed to session "Session Exercise"
+    And I am on "/user_portal.php"
+    And I follow "Session Exercise"
+    And wait for the page to be loaded
+    And I follow "tabs2"
+    And I follow "TEMP"
+    And I am on "/main/exercise/exercise.php?cidReq=TEMP"
+    And I follow "Exercise for Behat test"
+    And I follow "Start test"
+    When wait for the page to be loaded
+    And I press "Next question"
+    And I check "oligarchy"
+    And I check "oligopoly"
+    And I check "timocracy"
+    And I check "autocracy"
+    And I press "Next question"
+    And I check the "semantics" radio button
+    And I press "Next question"
+    And I check the "RNASL" radio button
+    And I press "Next question"
+    And I check the "10" radio button
+    And I press "Next question"
+    And fill in the following:
+      | choice_id_6_0 | words  |
+      | choice_id_6_1 | fill   |
+      | choice_id_6_2 | blanks |
+    And I press "Next question"
+    And I select "A" from "choice_id_7_1"
+    And I select "B" from "choice_id_7_2"
+    And I select "C" from "choice_id_7_3"
+    And I press "Next question"
+    And I check "1"
+    And I press "Next question"
+    And I press "End test"
+    Then I should see "Score for the test: 190 / 190"
+    And I should see the table "#category_results":
+      | Categories    | Absolute score | Relative score |
+      | Categoryname2 | 50 / 70        | 71.43%         |
+      | Categoryname1 | 60 / 60        | 100%           |
+      | none          | 80 / 60        | 133.33%        |
+      | Total         | 190 / 190      | 100%           |
+
+  Scenario: Teacher see exercise results by categories
+    Given I am on "/user_portal.php"
+    And I follow "Session Exercise"
+    And wait for the page to be loaded
+    And I follow "tabs2"
+    And I follow "TEMP"
+    And I am on "/main/exercise/exercise.php?cidReq=TEMP"
+    And I follow "Exercise for Behat test"
+    And I follow "Results and feedback"
+    Then I should see "Learner score"
+    And wait for the page to be loaded
+    And I follow "Grade activity"
+    Then I should see "Score for the test: 190 / 190"
+    And I should see the table "#category_results":
+      | Categories    | Absolute score | Relative score |
+      | Categoryname2 | 50 / 70        | 71.43%         |
+      | Categoryname1 | 60 / 60        | 100%           |
+      | none          | 80 / 60        | 133.33%        |
+      | Total         | 190 / 190      | 100%           |
+
   Scenario: Delete an exercise
   Scenario: Delete an exercise
     Given I am on "/main/exercise/exercise.php?cidReq=TEMP"
     Given I am on "/main/exercise/exercise.php?cidReq=TEMP"
     And I follow "Delete"
     And I follow "Delete"

BIN
tests/behat/uploadable_files/exercise.xls