From 407536472f49e450c8e9c12db1ddb87512d629c6 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Thu, 9 Aug 2018 19:30:01 -0500 Subject: [PATCH] Behat add test to check exercises with questions by categories --- main/exercise/TestCategory.php | 2 +- main/exercise/overview.php | 5 + .../features/bootstrap/FeatureContext.php | 97 +++++++++++++++++- tests/behat/features/toolExercise.feature | 71 +++++++++++++ tests/behat/uploadable_files/exercise.xls | Bin 0 -> 14848 bytes 5 files changed, 172 insertions(+), 3 deletions(-) create mode 100644 tests/behat/uploadable_files/exercise.xls 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 0000000000000000000000000000000000000000..59b79bcf50346df75ea46c5f7be42491b4e5cd23 GIT binary patch literal 14848 zcmeHOYiu0Xb-v4&NIfZ8c5KR8-4#WOj};}7mMzJa#fM1CwnR}BT?eq;cDNjJCz{=1 zW|pRy^g%nxj{*&lG=K{tMywS6(ZE2Pq(y=vK`Z|#P@rs6vqDf0cgk(8hXEUq8j)!89Z1bcEl4|&b|LLX+Jm$g zX&(|?KMN_Aghrg22YD^XJ^wlyfwf*Zp zcucjTwo|e?UTlYdC(hmaD;l_yu9#n~|CVNq;-*IRojq$D@-p^+r0Uey8{WiSseeIw zUM(;-j9P9^|6g4r(grKVHr&P}b3WCCxuy=Y(yO@dR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