diff --git a/main/exercise/TestCategory.php b/main/exercise/TestCategory.php index 8ae87f2983..fa138bcd42 100644 --- a/main/exercise/TestCategory.php +++ b/main/exercise/TestCategory.php @@ -801,7 +801,7 @@ class TestCategory } $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, 1, get_lang('AbsoluteScore')); $table->setHeaderContents(0, 2, get_lang('RelativeScore')); diff --git a/main/exercise/overview.php b/main/exercise/overview.php index c3c605c904..68f1930a6b 100755 --- a/main/exercise/overview.php +++ b/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), 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); // Exercise name. diff --git a/tests/behat/features/bootstrap/FeatureContext.php b/tests/behat/features/bootstrap/FeatureContext.php index 5b9c6a4206..4e0fa9cd5c 100644 --- a/tests/behat/features/bootstrap/FeatureContext.php +++ b/tests/behat/features/bootstrap/FeatureContext.php @@ -1,5 +1,6 @@ visit('/index.php?logout=logout'); $this->iAmOnHomepage(); - $this->fillFields(new \Behat\Gherkin\Node\TableNode([ + $this->fillFields(new TableNode([ ['login', $username], ['password', $username] ])); @@ -181,7 +182,7 @@ class FeatureContext extends MinkContext public function iHaveAPublicPasswordProtectedCourse($code, $password) { $this->visit('/main/admin/course_add.php'); - $this->fillFields(new \Behat\Gherkin\Node\TableNode([ + $this->fillFields(new TableNode([ ['title', 'Password Protected'], ['visual_code', $code], ['visibility', 3] @@ -471,4 +472,96 @@ class FeatureContext extends MinkContext } 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++; + } + } } diff --git a/tests/behat/features/toolExercise.feature b/tests/behat/features/toolExercise.feature index 706c93b795..c689d8ae4b 100644 --- a/tests/behat/features/toolExercise.feature +++ b/tests/behat/features/toolExercise.feature @@ -310,6 +310,77 @@ Feature: Exercise tool Then I should see "Exercise copied" 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 Given I am on "/main/exercise/exercise.php?cidReq=TEMP" And I follow "Delete" diff --git a/tests/behat/uploadable_files/exercise.xls b/tests/behat/uploadable_files/exercise.xls new file mode 100644 index 0000000000..59b79bcf50 Binary files /dev/null and b/tests/behat/uploadable_files/exercise.xls differ