From c7bc4931c3026061c30904a1a054242062abab29 Mon Sep 17 00:00:00 2001 From: Angelia Dela Cruz Date: Fri, 12 Jan 2024 17:05:52 +0800 Subject: [PATCH 1/2] MDL-80589 qtype_numerical: Behat to add, edit, preview numeric question --- .../type/numerical/tests/behat/add.feature | 24 ++++++++++- .../type/numerical/tests/behat/edit.feature | 29 +++++++++++++ .../numerical/tests/behat/preview.feature | 42 +++++++++++++++++++ 3 files changed, 94 insertions(+), 1 deletion(-) diff --git a/question/type/numerical/tests/behat/add.feature b/question/type/numerical/tests/behat/add.feature index 6444da83c6a..140b2d13665 100644 --- a/question/type/numerical/tests/behat/add.feature +++ b/question/type/numerical/tests/behat/add.feature @@ -37,7 +37,7 @@ Feature: Test creating a Numerical question Then I should see "Numerical-001" @javascript - Scenario: Create a Numerical question with units + Scenario: Create a Numerical question with required units When I am on the "Course 1" "core_question > course question bank" page logged in as teacher And I add a "Numerical" question filling the form with: | Question name | Numerical-002 | @@ -70,3 +70,25 @@ Feature: Test creating a Numerical question | id_unitgradingtypes | as a fraction (0-1) of the question grade | | id_multichoicedisplay | a drop-down menu | | id_unitsleft | on the right, for example 1.00cm or 1.00km | + + @javascript + Scenario: Create a Numerical question with optional units + When I am on the "Course 1" "core_question > course question bank" page logged in as teacher + # Add the numerical question with optional units. + And I add a "Numerical" question filling the form with: + | Question name | Numerical Question 1 | + | Question text | What is the sum of $8 + $9? | + | Default mark | 1 | + | General feedback | The correct answer is $17 | + | id_answer_0 | 17 | + | id_tolerance_0 | 0 | + | id_fraction_0 | 100% | + | id_answer_1 | * | + | id_tolerance_1 | 0 | + | id_fraction_1 | 0% | + | id_unitrole | Units are optional. If a unit is entered, it is used to convert the response to Unit 1 before grading. | + | id_unitsleft | on the left, for example $1.00 or £1.00 | + | id_unit_0 | $ | + | id_multiplier_0 | 1 | + # Confirm that the numerical question with optional units is added successfully. + Then I should see "Numerical Question 1" diff --git a/question/type/numerical/tests/behat/edit.feature b/question/type/numerical/tests/behat/edit.feature index a70da10c6ed..e1c97c18f11 100644 --- a/question/type/numerical/tests/behat/edit.feature +++ b/question/type/numerical/tests/behat/edit.feature @@ -55,3 +55,32 @@ Feature: Test editing a Numerical question Then the following fields match these values: | id_answer_0 | 0.00000123456789 | | id_tolerance_1 | 0.0000123456789 | + + Scenario: Edit a Numerical question with optional units + When I am on the "Numerical for editing" "core_question > edit" page logged in as teacher + # Edit the existing numerical question, add in the optional units. + And I set the following fields to these values: + | Question text | What's $500 in Php? aaa | + | Default mark | 1 | + | General feedback | The correct answer is Php27950 aaa | + | id_unitrole | Units are optional. If a unit is entered, it is used to convert the response to Unit 1 before grading. | + | id_unitsleft | on the left, for example $1.00 or £1.00 | + | id_answer_0 | 27950 | + | id_tolerance_0 | 0 | + | id_fraction_0 | 100% | + | id_unit_0 | Php | + | id_multiplier_0 | 55.9 | + And I press "submitbutton" + And I choose "Edit question" action for "Numerical for editing" in the question bank + # Confirm that the numerical question is updated accordingly. + Then the following fields match these values: + | Question text | What's $500 in Php? aaa | + | Default mark | 1 | + | General feedback | The correct answer is Php27950 aaa | + | id_unitrole | Units are optional. If a unit is entered, it is used to convert the response to Unit 1 before grading. | + | id_unitsleft | on the left, for example $1.00 or £1.00 | + | id_answer_0 | 27950 | + | id_tolerance_0 | 0 | + | id_fraction_0 | 100% | + | id_unit_0 | Php | + | id_multiplier_0 | 55.9 | diff --git a/question/type/numerical/tests/behat/preview.feature b/question/type/numerical/tests/behat/preview.feature index 6538a411284..02ca6393992 100644 --- a/question/type/numerical/tests/behat/preview.feature +++ b/question/type/numerical/tests/behat/preview.feature @@ -45,3 +45,45 @@ Feature: Preview a Numerical question And I press "Check" And I should see "Very good." And I should see "Mark 1#00 out of 1#00" + + Scenario: Preview a Numerical question with optional units + Given I am on the "Course 1" "core_question > course question bank" page logged in as teacher + # Add the numerical question with optional units + And I add a "Numerical" question filling the form with: + | Question name | Numerical 1 | + | Question text | What's $500 in Php? img1 | + | Default mark | 1 | + | General feedback | The correct answer is Php27950 img1 | + | id_answer_0 | 27950 | + | id_tolerance_0 | 0 | + | id_fraction_0 | 100% | + | id_feedback_0 | Correct! | + | id_answer_1 | * | + | id_tolerance_1 | 0 | + | id_fraction_1 | 0% | + | id_feedback_1 | Wrong! | + | id_unitrole | Units are optional. If a unit is entered, it is used to convert the response to Unit 1 before grading. | + | id_unitsleft | on the left, for example $1.00 or £1.00 | + | id_unit_0 | Php | + | id_multiplier_0 | 1 | + # Confirm numerical question can be previewed. + When I am on the "Numerical 1" "core_question > preview" page logged in as teacher + Then I should see "Numerical 1" + And I should see "What's $500 in Php?" + # Answer question correctly. + And I set the following fields to these values: + | Answer | 27950 | + And I press "Submit and finish" + # Confirm that corresponding feedback is displayed. + And I should see "The correct answer is Php27950" + And I should see "Correct!" + And "//img[contains(@src, 'gd-logo.png')]" "xpath_element" should exist + And I press "Start again" + # Answer question incorrectly. + And I set the following fields to these values: + | Answer | 27961 | + And I press "Submit and finish" + # Confirm that corresponding feedback is displayed. + And I should see "The correct answer is Php27950" + And I should see "Wrong!" + And "//img[contains(@src, 'gd-logo.png')]" "xpath_element" should exist From 9d54d9a6c3474047e414ab76b758a0fd5fe6a475 Mon Sep 17 00:00:00 2001 From: Simey Lameze Date: Thu, 2 May 2024 12:28:25 +0800 Subject: [PATCH 2/2] MDL-80589 behat: fixes and improvements to new tests --- .../type/numerical/tests/behat/add.feature | 40 +++++++------ .../type/numerical/tests/behat/edit.feature | 48 +++++++-------- .../numerical/tests/behat/preview.feature | 58 ++++++------------- 3 files changed, 66 insertions(+), 80 deletions(-) diff --git a/question/type/numerical/tests/behat/add.feature b/question/type/numerical/tests/behat/add.feature index 140b2d13665..5318ad02136 100644 --- a/question/type/numerical/tests/behat/add.feature +++ b/question/type/numerical/tests/behat/add.feature @@ -71,24 +71,30 @@ Feature: Test creating a Numerical question | id_multichoicedisplay | a drop-down menu | | id_unitsleft | on the right, for example 1.00cm or 1.00km | - @javascript Scenario: Create a Numerical question with optional units - When I am on the "Course 1" "core_question > course question bank" page logged in as teacher + Given I am on the "Course 1" "core_question > course question bank" page logged in as teacher # Add the numerical question with optional units. And I add a "Numerical" question filling the form with: - | Question name | Numerical Question 1 | - | Question text | What is the sum of $8 + $9? | - | Default mark | 1 | - | General feedback | The correct answer is $17 | - | id_answer_0 | 17 | - | id_tolerance_0 | 0 | - | id_fraction_0 | 100% | - | id_answer_1 | * | - | id_tolerance_1 | 0 | - | id_fraction_1 | 0% | - | id_unitrole | Units are optional. If a unit is entered, it is used to convert the response to Unit 1 before grading. | - | id_unitsleft | on the left, for example $1.00 or £1.00 | - | id_unit_0 | $ | - | id_multiplier_0 | 1 | + | Question name | Numerical Question (optional) | + | Question text | How many meter is 1m + 20cm + 50mm? | + | Default mark | 1 | + | General feedback | The correct answer is 1.25m | + | id_answer_0 | 1.25 | + | id_tolerance_0 | 0 | + | id_fraction_0 | 100% | + | id_answer_1 | 125 | + | id_tolerance_1 | 0 | + | id_fraction_1 | 0% | + | id_unitrole | Units are optional. | + | id_unitsleft | on the right, for example 1.00cm or 1.00km | + | id_unit_0 | m | # Confirm that the numerical question with optional units is added successfully. - Then I should see "Numerical Question 1" + When I choose "Edit question" action for "Numerical Question (optional)" in the question bank + Then the following fields match these values: + | Question name | Numerical Question (optional) | + | Question text | How many meter is 1m + 20cm + 50mm? | + | Default mark | 1 | + | General feedback | The correct answer is 1.25m | + | id_unitrole | Units are optional. If a unit is entered, it is used to convert the response to Unit 1 before grading. | + | id_unitsleft | on the right, for example 1.00cm or 1.00km | + | id_unit_0 | m | diff --git a/question/type/numerical/tests/behat/edit.feature b/question/type/numerical/tests/behat/edit.feature index e1c97c18f11..63de4496ceb 100644 --- a/question/type/numerical/tests/behat/edit.feature +++ b/question/type/numerical/tests/behat/edit.feature @@ -57,30 +57,30 @@ Feature: Test editing a Numerical question | id_tolerance_1 | 0.0000123456789 | Scenario: Edit a Numerical question with optional units - When I am on the "Numerical for editing" "core_question > edit" page logged in as teacher - # Edit the existing numerical question, add in the optional units. + Given I am on the "Numerical for editing" "core_question > edit" page logged in as teacher + # Edit the existing numerical question, changing the unit to optional. And I set the following fields to these values: - | Question text | What's $500 in Php? aaa | - | Default mark | 1 | - | General feedback | The correct answer is Php27950 aaa | - | id_unitrole | Units are optional. If a unit is entered, it is used to convert the response to Unit 1 before grading. | - | id_unitsleft | on the left, for example $1.00 or £1.00 | - | id_answer_0 | 27950 | - | id_tolerance_0 | 0 | - | id_fraction_0 | 100% | - | id_unit_0 | Php | - | id_multiplier_0 | 55.9 | + | Question name | Numerical Question (optional) | + | Question text | How many meter is 1m + 20cm + 50mm? | + | Default mark | 1 | + | General feedback | The correct answer is 1.25m | + | id_answer_0 | 1.25 | + | id_tolerance_0 | 0 | + | id_fraction_0 | 100% | + | id_answer_1 | 125 | + | id_tolerance_1 | 0 | + | id_fraction_1 | 0% | + | id_unitrole | Units are optional. | + | id_unitsleft | on the right, for example 1.00cm or 1.00km | + | id_unit_0 | m | And I press "submitbutton" - And I choose "Edit question" action for "Numerical for editing" in the question bank - # Confirm that the numerical question is updated accordingly. + When I choose "Edit question" action for "Numerical Question (optional)" in the question bank + # Confirm that the numerical question with optional unit is updated accordingly. Then the following fields match these values: - | Question text | What's $500 in Php? aaa | - | Default mark | 1 | - | General feedback | The correct answer is Php27950 aaa | - | id_unitrole | Units are optional. If a unit is entered, it is used to convert the response to Unit 1 before grading. | - | id_unitsleft | on the left, for example $1.00 or £1.00 | - | id_answer_0 | 27950 | - | id_tolerance_0 | 0 | - | id_fraction_0 | 100% | - | id_unit_0 | Php | - | id_multiplier_0 | 55.9 | + | Question name | Numerical Question (optional) | + | Question text | How many meter is 1m + 20cm + 50mm? | + | Default mark | 1 | + | General feedback | The correct answer is 1.25m | + | id_unitrole | Units are optional. If a unit is entered, it is used to convert the response to Unit 1 before grading. | + | id_unitsleft | on the right, for example 1.00cm or 1.00km | + | id_unit_0 | m | diff --git a/question/type/numerical/tests/behat/preview.feature b/question/type/numerical/tests/behat/preview.feature index 02ca6393992..445d8f0d6bf 100644 --- a/question/type/numerical/tests/behat/preview.feature +++ b/question/type/numerical/tests/behat/preview.feature @@ -47,43 +47,23 @@ Feature: Preview a Numerical question And I should see "Mark 1#00 out of 1#00" Scenario: Preview a Numerical question with optional units - Given I am on the "Course 1" "core_question > course question bank" page logged in as teacher - # Add the numerical question with optional units - And I add a "Numerical" question filling the form with: - | Question name | Numerical 1 | - | Question text | What's $500 in Php? img1 | - | Default mark | 1 | - | General feedback | The correct answer is Php27950 img1 | - | id_answer_0 | 27950 | - | id_tolerance_0 | 0 | - | id_fraction_0 | 100% | - | id_feedback_0 | Correct! | - | id_answer_1 | * | - | id_tolerance_1 | 0 | - | id_fraction_1 | 0% | - | id_feedback_1 | Wrong! | - | id_unitrole | Units are optional. If a unit is entered, it is used to convert the response to Unit 1 before grading. | - | id_unitsleft | on the left, for example $1.00 or £1.00 | - | id_unit_0 | Php | - | id_multiplier_0 | 1 | - # Confirm numerical question can be previewed. - When I am on the "Numerical 1" "core_question > preview" page logged in as teacher - Then I should see "Numerical 1" - And I should see "What's $500 in Php?" - # Answer question correctly. + Given I am on the "Numerical-001" "core_question > edit" page logged in as teacher + # Edit the existing numerical question, add in the optional units. And I set the following fields to these values: - | Answer | 27950 | - And I press "Submit and finish" - # Confirm that corresponding feedback is displayed. - And I should see "The correct answer is Php27950" - And I should see "Correct!" - And "//img[contains(@src, 'gd-logo.png')]" "xpath_element" should exist - And I press "Start again" - # Answer question incorrectly. - And I set the following fields to these values: - | Answer | 27961 | - And I press "Submit and finish" - # Confirm that corresponding feedback is displayed. - And I should see "The correct answer is Php27950" - And I should see "Wrong!" - And "//img[contains(@src, 'gd-logo.png')]" "xpath_element" should exist + | Question name | Numerical Question (optional) | + | Question text | How many meter is 1m + 20cm + 50mm? | + | Default mark | 1 | + | General feedback | The correct answer is 1.25m | + | id_answer_0 | 1.25 | + | id_tolerance_0 | 0 | + | id_fraction_0 | 100% | + | id_answer_1 | 125 | + | id_tolerance_1 | 0 | + | id_fraction_1 | 0% | + | id_unitrole | Units are optional. | + | id_unitsleft | on the right, for example 1.00cm or 1.00km | + | id_unit_0 | m | + And I press "submitbutton" + When I choose "Preview" action for "Numerical Question (optional)" in the question bank + # Unit is optional, so the unit select box should not be exist. + Then "Select one unit" "select" should not exist