aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/behat/add.feature6
-rw-r--r--tests/behat/backup_and_restore.feature44
-rw-r--r--tests/behat/edit.feature56
-rw-r--r--tests/behat/export.feature35
-rw-r--r--tests/behat/preview.feature55
-rw-r--r--tests/helper.php7
-rw-r--r--tests/questiontype_test.php3
7 files changed, 196 insertions, 10 deletions
diff --git a/tests/behat/add.feature b/tests/behat/add.feature
index 4b7319f..f72399e 100644
--- a/tests/behat/add.feature
+++ b/tests/behat/add.feature
@@ -30,7 +30,7 @@ Feature: Test creating an Algebra question
| id_answer_0 | 2*x |
| id_fraction_0 | 100% |
| id_feedback_0 | Well done. 2*x is correct. |
- | id_answer_1 | * |
- | id_fraction_1 | None |
- | id_feedback_1 | Your answer is incorrect. |
+ | id_answer_1 | x |
+ | id_fraction_1 | 20% |
+ | id_feedback_1 | It seems that you forgot something. |
Then I should see "algebra-001"
diff --git a/tests/behat/backup_and_restore.feature b/tests/behat/backup_and_restore.feature
new file mode 100644
index 0000000..2122cdf
--- /dev/null
+++ b/tests/behat/backup_and_restore.feature
@@ -0,0 +1,44 @@
+@qtype @qtype_algebra
+Feature: Test duplicating a quiz containing an Algebra question
+ As a teacher
+ In order re-use my courses containing Algebra questions
+ I need to be able to backup and restore them
+
+ Background:
+ And the following "courses" exist:
+ | fullname | shortname | category |
+ | Course 1 | C1 | 0 |
+ And the following "question categories" exist:
+ | contextlevel | reference | name |
+ | Course | C1 | Test questions |
+ And the following "questions" exist:
+ | questioncategory | qtype | name | template |
+ | Test questions | algebra | Algebra question | simplemath |
+ And the following "activities" exist:
+ | activity | name | course | idnumber |
+ | quiz | Test quiz | C1 | quiz1 |
+ And quiz "Test quiz" contains the following questions:
+ | Algebra question | 1 |
+ And I log in as "admin"
+ And I am on "Course 1" course homepage
+
+ @javascript
+ Scenario: Backup and restore a course containing an algebra question
+ When I backup "Course 1" course using this options:
+ | Confirmation | Filename | test_backup.mbz |
+ And I restore "test_backup.mbz" backup into a new course using this options:
+ | Schema | Course name | Course 2 |
+ And I navigate to "Question bank" node in "Course administration"
+ And I click on "Edit" "link" in the "Algebra question" "table_row"
+ Then the following fields match these values:
+ | Question name | Algebra question |
+ | Question text | P(x) = 3x and Q(x) = 4x. Calculate (P + Q)(x) |
+ | General feedback | Generalfeedback: (P + Q)(x) = 7x. |
+ | Default mark | 1 |
+ | id_variable_0 | x |
+ | id_varmin_0 | -5 |
+ | id_varmax_0 | 5 |
+ | id_answer_0 | 7*x |
+ | id_fraction_0 | 100% |
+ | id_feedback_0 | This is a very good answer. |
+
diff --git a/tests/behat/edit.feature b/tests/behat/edit.feature
new file mode 100644
index 0000000..87a2a54
--- /dev/null
+++ b/tests/behat/edit.feature
@@ -0,0 +1,56 @@
+@qtype @qtype_algebra
+Feature: Test editing an Algebra question
+ As a teacher
+ In order to be able to update my Algebra question
+ I need to edit them
+
+ Background:
+ Given the following "users" exist:
+ | username | firstname | lastname | email |
+ | teacher1 | T1 | Teacher1 | teacher1@example.com |
+ And the following "courses" exist:
+ | fullname | shortname | category |
+ | Course 1 | C1 | 0 |
+ And the following "course enrolments" exist:
+ | user | course | role |
+ | teacher1 | C1 | editingteacher |
+ And the following "question categories" exist:
+ | contextlevel | reference | name |
+ | Course | C1 | Test questions |
+ And the following "questions" exist:
+ | questioncategory | qtype | name | template |
+ | Test questions | algebra | algebra-001 for editing | simplemath |
+ And I log in as "teacher1"
+ And I am on "Course 1" course homepage
+ And I navigate to "Question bank" node in "Course administration"
+
+ @javascript @_switch_window
+ Scenario: Edit an Algebra question
+ When I click on "Edit" "link" in the "algebra-001 for editing" "table_row"
+ And I set the following fields to these values:
+ | Question name | |
+ And I press "id_submitbutton"
+ Then I should see "You must supply a value here."
+ When I set the following fields to these values:
+ | Question name | Edited algebra-001 name |
+ And I press "id_submitbutton"
+ Then I should see "Edited algebra-001 name"
+ When I click on "Edit" "link" in the "Edited algebra-001 name" "table_row"
+ And I set the following fields to these values:
+ | id_answer_1 | 6*x |
+ | id_fraction_1 | 10% |
+ | id_feedback_1 | 3x + 4x gives 7x not 6x. |
+ And I press "id_submitbutton"
+ Then I should see "Edited algebra-001 name"
+ When I click on "Preview" "link" in the "Edited algebra-001 name" "table_row"
+ And I switch to "questionpreview" window
+ Then I should see "P(x) = 3x and Q(x) = 4x. Calculate (P + Q)(x)"
+ # Set behaviour options
+ And I set the following fields to these values:
+ | behaviour | immediatefeedback |
+ And I press "Start again with these options"
+ And I set the field with xpath "//div[@class='qtext']//input[contains(@id, '1_answer')]" to "6*x"
+ And I press "Check"
+ Then I should see "3x + 4x gives 7x not 6x."
+ And I should see "Generalfeedback: (P + Q)(x) = 7x."
+ And I should see "The correct answer is: 7*x"
diff --git a/tests/behat/export.feature b/tests/behat/export.feature
new file mode 100644
index 0000000..8c92943
--- /dev/null
+++ b/tests/behat/export.feature
@@ -0,0 +1,35 @@
+@qtype @qtype_algebra
+Feature: Test exporting Short answer questions
+ As a teacher
+ In order to be able to reuse my Algebra questions
+ I need to export them
+
+ Background:
+ Given the following "users" exist:
+ | username | firstname | lastname | email |
+ | teacher1 | T1 | Teacher1 | teacher1@example.com |
+ And the following "courses" exist:
+ | fullname | shortname | category |
+ | Course 1 | C1 | 0 |
+ And the following "course enrolments" exist:
+ | user | course | role |
+ | teacher1 | C1 | editingteacher |
+ And the following "question categories" exist:
+ | contextlevel | reference | name |
+ | Course | C1 | Test questions |
+ And the following "questions" exist:
+ | questioncategory | qtype | name | template |
+ | Test questions | algebra | algebra-001 | simplemath |
+ And I log in as "teacher1"
+ And I am on "Course 1" course homepage
+
+ Scenario: Export an Algebra question
+ When I navigate to "Export" node in "Course administration > Question bank"
+ And I set the field "id_format_xml" to "1"
+ And I press "Export questions to file"
+ Then following "click here" should download between "1200" and "1300" bytes
+ # If the download step is the last in the scenario then we can sometimes run
+ # into the situation where the download page causes a http redirect but behat
+ # has already conducted its reset (generating an error). By putting a logout
+ # step we avoid behat doing the reset until we are off that page.
+ And I log out
diff --git a/tests/behat/preview.feature b/tests/behat/preview.feature
new file mode 100644
index 0000000..6b06db8
--- /dev/null
+++ b/tests/behat/preview.feature
@@ -0,0 +1,55 @@
+@qtype @qtype_algebra
+Feature: Preview a Short answer question
+ As a teacher
+ In order to check my Short answer questions will work for students
+ I need to preview them
+
+ Background:
+ Given the following "users" exist:
+ | username | firstname | lastname | email |
+ | teacher1 | T1 | Teacher1 | teacher1@moodle.com |
+ And the following "courses" exist:
+ | fullname | shortname | category |
+ | Course 1 | C1 | 0 |
+ And the following "course enrolments" exist:
+ | user | course | role |
+ | teacher1 | C1 | editingteacher |
+ And the following "question categories" exist:
+ | contextlevel | reference | name |
+ | Course | C1 | Test questions |
+ And the following "questions" exist:
+ | questioncategory | qtype | name | template |
+ | Test questions | algebra | algebra-001 | simplemath |
+ Given I log in as "teacher1"
+ And I am on "Course 1" course homepage
+ And I navigate to "Question bank" node in "Course administration"
+
+ @javascript @_switch_window
+ Scenario: Preview an Algebra question with correct answer
+ When I click on "Preview" "link" in the "algebra-001" "table_row"
+ And I switch to "questionpreview" window
+ Then I should see "P(x) = 3x and Q(x) = 4x. Calculate (P + Q)(x)"
+ # Set behaviour options
+ And I set the following fields to these values:
+ | behaviour | immediatefeedback |
+ And I press "Start again with these options"
+ And I set the field with xpath "//div[@class='qtext']//input[contains(@id, '1_answer')]" to "7*x"
+ And I press "Check"
+ Then I should see "This is a very good answer."
+ And I should see "Generalfeedback: (P + Q)(x) = 7x."
+ And I should see "The correct answer is: 7*x"
+
+ @javascript @_switch_window
+ Scenario: Preview an Algebra question with incorrect answer
+ When I click on "Preview" "link" in the "algebra-001" "table_row"
+ And I switch to "questionpreview" window
+ Then I should see "P(x) = 3x and Q(x) = 4x. Calculate (P + Q)(x)"
+ # Set behaviour options
+ And I set the following fields to these values:
+ | behaviour | immediatefeedback |
+ And I press "Start again with these options"
+ And I set the field with xpath "//div[@class='qtext']//input[contains(@id, '1_answer')]" to "6*x"
+ And I press "Check"
+ Then I should see "That is a bad answer."
+ And I should see "Generalfeedback: (P + Q)(x) = 7x."
+ And I should see "The correct answer is: 7*x" \ No newline at end of file
diff --git a/tests/helper.php b/tests/helper.php
index 5af6a9b..e0f0381 100644
--- a/tests/helper.php
+++ b/tests/helper.php
@@ -55,7 +55,6 @@ class qtype_algebra_test_helper extends question_test_helper {
$q->answerprefix = '';
$q->answers = array(
13 => new question_answer(13, '7*x', 1.0, 'This is a very good answer.', FORMAT_HTML),
- 14 => new question_answer(14, '*', 0.0, 'This is completely wrong.', FORMAT_HTML),
);
$q->variables = array(
7 => new qtype_algebra_variable(7, 'x', -5, 5)
@@ -88,7 +87,6 @@ class qtype_algebra_test_helper extends question_test_helper {
$qdata->options->answerprefix = '';
$qdata->options->answers = array(
13 => new question_answer(13, '7*x', 1.0, 'This is a very good answer.', FORMAT_HTML),
- 14 => new question_answer(14, '*', 0.0, 'This is completely wrong.', FORMAT_HTML),
);
$qdata->options->variables = array(
7 => new qtype_algebra_variable(7, 'x', -5, 5)
@@ -116,14 +114,13 @@ class qtype_algebra_test_helper extends question_test_helper {
$form->allowedfuncs = array('all' => 1);
$form->disallow = '';
$form->answerprefix = '';
- $form->answer = array('7*x', '*');
- $form->fraction = array('1.0', '0.0');
+ $form->answer = array('7*x');
+ $form->fraction = array('1.0');
$form->variable = array('x');
$form->varmin = array('-5');
$form->varmax = array('5');
$form->feedback = array(
array('text' => 'This is a very good answer.', 'format' => FORMAT_HTML),
- array('text' => 'This is completely wrong.', 'format' => FORMAT_HTML),
);
$form->penalty = 0.3333333;
diff --git a/tests/questiontype_test.php b/tests/questiontype_test.php
index bd53a47..ee19d6b 100644
--- a/tests/questiontype_test.php
+++ b/tests/questiontype_test.php
@@ -68,8 +68,7 @@ class qtype_algebra_test extends advanced_testcase {
public function test_get_random_guess_score() {
$q = test_question_maker::get_question_data('algebra');
- $q->options->answers[14]->fraction = 0.1;
- $this->assertEquals(0.1, $this->qtype->get_random_guess_score($q));
+ $this->assertEquals(0, $this->qtype->get_random_guess_score($q));
}
public function test_get_possible_responses() {