Behat add test to check exercises with questions by categories

pull/2624/head
Angel Fernando Quiroz Campos 7 years ago
parent 26dfc5d0d9
commit 407536472f
  1. 2
      main/exercise/TestCategory.php
  2. 5
      main/exercise/overview.php
  3. 97
      tests/behat/features/bootstrap/FeatureContext.php
  4. 71
      tests/behat/features/toolExercise.feature
  5. BIN
      tests/behat/uploadable_files/exercise.xls

@ -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'));

@ -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.

@ -1,5 +1,6 @@
<?php
use Behat\Gherkin\Node\TableNode;
use Behat\MinkExtension\Context\MinkContext;
/**
@ -141,7 +142,7 @@ class FeatureContext extends MinkContext
{
$this->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++;
}
}
}

@ -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"

Loading…
Cancel
Save