Skip to content

Commit

Permalink
fix phpunit - behat
Browse files Browse the repository at this point in the history
  • Loading branch information
ewallah committed Oct 29, 2018
1 parent eccc5ce commit d5b5739
Show file tree
Hide file tree
Showing 10 changed files with 188 additions and 114 deletions.
19 changes: 9 additions & 10 deletions questiontype.php
Expand Up @@ -120,16 +120,16 @@ public function save_question_options($formdata) {
'graderinfoformat' => $formdata->graderinfo['format'],
'responsetemplate' => $formdata->responsetemplate['text'],
'responsetemplateformat' => $formdata->responsetemplate['format'],
'enableautograde' => $formdata->enableautograde,
'itemtype' => $formdata->itemtype,
'itemcount' => $formdata->itemcount,
'showfeedback' => $formdata->showfeedback,
'showcalculation' => $formdata->showcalculation,
'showtextstats' => $formdata->showtextstats,
'enableautograde' => isset($formdata->enableautograde) ? $formdata->enableautograde : 1,
'itemtype' => isset($formdata->itemtype) ? $formdata->itemtype : self::ITEM_TYPE_CHARS,
'itemcount' => isset($formdata->itemcount) ? $formdata->itemcount : 1,
'showfeedback' => isset($formdata->showfeedback) ? $formdata->showfeedback : 1,
'showcalculation' => isset($formdata->showcalculation) ? $formdata->showcalculation : 1,
'showtextstats' => isset($formdata->showtextstats) ? $formdata->showtextstats : 1,
'textstatitems' => $textstatitems,
'showgradebands' => $formdata->showgradebands,
'addpartialgrades' => $formdata->addpartialgrades,
'showtargetphrases' => $formdata->showtargetphrases
'showgradebands' => isset($formdata->showgradebands) ? $formdata->showgradebands : 1,
'addpartialgrades' => isset($formdata->addpartialgrades) ? $formdata->addpartialgrades : 1,
'showtargetphrases' => isset($formdata->showtargetphrases) ? $formdata->showtargetphrases : 1,
);

// add options for feedback fields
Expand Down Expand Up @@ -482,7 +482,6 @@ public function export_to_xml($question, qformat_xml $format, $extra=null) {
$output .= " <$tag percent=\"$percent\">$text</$tag>\n";;
}
$output .= " </answers>\n";

return $output;
}

Expand Down
40 changes: 28 additions & 12 deletions tests/behat/add.feature
@@ -1,8 +1,8 @@
@qtype @qtype_essayautograde
Feature: Test creating an Essay question
Feature: Test creating an Essay autograde question
As a teacher
In order to test my students
I need to be able to create an Essay question
I need to be able to create an Essay autograde question

Background:
Given the following "users" exist:
Expand All @@ -15,21 +15,37 @@ Feature: Test creating an Essay question
| user | course | role |
| teacher1 | C1 | editingteacher |
And I log in as "teacher1"
And I follow "Course 1"
And I navigate to "Question bank" node in "Course administration"
And I am on "Course 1" course homepage
And I navigate to "Question bank" in current page administration

Scenario: Create an Essay question with Response format set to 'HTML editor'
When I add a "Essay" question filling the form with:
Scenario: Create an Essay autograde question with Response format set to 'HTML editor'
When I add a "Essay (auto-grade)" question filling the form with:
| Question name | essayautograde-001 |
| Question text | Write an essayautograde with 500 words. |
| General feedback | This is general feedback |
| Response format | HTML editor |
| General feedback | This is general feedback |
| Response format | HTML editor |
Then I should see "essayautograde-001"

Scenario: Create an Essay question with Response format set to 'HTML editor with the file picker'
When I add a "Essay" question filling the form with:
Scenario: Create an Essay autograde question with Response format set to 'HTML editor with file picker'
When I add a "Essay (auto-grade)" question filling the form with:
| Question name | essayautograde-002 |
| Question text | Write an essayautograde with 500 words. |
| General feedback | This is general feedback |
| Response format | HTML editor |
| General feedback | This is general feedback |
| Response format | HTML editor with file picker |
Then I should see "essayautograde-002"

Scenario: Create an Essay autograde question with Response format set to 'plain'
When I add a "Essay (auto-grade)" question filling the form with:
| Question name | essayautograde-003 |
| Question text | Write an essayautograde with 500 words. |
| General feedback | This is general feedback |
| Response format | Plain |
Then I should see "essayautograde-003"

Scenario: Create an Essay autograde question with Response format set to 'monospaced'
When I add a "Essay (auto-grade)" question filling the form with:
| Question name | essayautograde-004 |
| Question text | Write an essayautograde with 500 words. |
| General feedback | This is general feedback |
| Response format | Plain text, monospaced font |
Then I should see "essayautograde-004"
31 changes: 18 additions & 13 deletions tests/behat/backup_and_restore.feature
@@ -1,39 +1,44 @@
@qtype @qtype_essayautograde
Feature: Test duplicating a quiz containing an Assay question
As a teacher
In order re-use my courses containing Essay questions
Feature: Test duplicating a quiz containing an Essay autograde question
As andmin
In order re-use my courses containing Essay autograde questions
I need to be able to backup and restore 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 "activities" exist:
| activity | name | course | idnumber |
| quiz | Test quiz | C1 | quiz1 |
And the following "questions" exist:
| questioncategory | qtype | name | template |
| questioncategory | qtype | name | template |
| Test questions | essayautograde | essayautograde-001 | editor |
| Test questions | essayautograde | essayautograde-002 | editorfilepicker |
| Test questions | essayautograde | essayautograde-003 | plain |
And the following "activities" exist:
| activity | name | course | idnumber |
| quiz | Test quiz | C1 | quiz1 |
And quiz "Test quiz" contains the following questions:
| essayautograde-001 | 1 |
| essayautograde-002 | 1 |
| essayautograde-003 | 1 |
And I log in as "admin"
And I am on site homepage
And I follow "Course 1"

@javascript
Scenario: Backup and restore a course containing 3 Essay questions
When I backup "Course 1" course using this options:
Scenario: Backup and restore a course containing 3 Essay autograde questions
Given I log in as "admin"
And I am on "Course 1" course homepage
And 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 navigate to "Question bank" in current page administration
And I should see "essayautograde-001"
And I should see "essayautograde-002"
And I should see "essayautograde-003"
Expand Down
34 changes: 22 additions & 12 deletions tests/behat/edit.feature
@@ -1,7 +1,7 @@
@qtype @qtype_essayautograde
Feature: Test editing an Essay question
Feature: Test editing an Essay autograde question
As a teacher
In order to be able to update my Essay question
In order to be able to update my Essay autograde question
I need to edit them

Background:
Expand All @@ -17,26 +17,36 @@ Feature: Test editing an Essay question
And the following "question categories" exist:
| contextlevel | reference | name |
| Course | C1 | Test questions |
And the following "questions" exist:
| questioncategory | qtype | name | template |
| Test questions | essayautograde | essayautograde-001 | editor |
| Test questions | essayautograde | essayautograde-002 | editorfilepicker |
| Test questions | essayautograde | essayautograde-003 | plain |
And I log in as "teacher1"
And I follow "Course 1"
And I navigate to "Question bank" node in "Course administration"
And I am on "Course 1" course homepage
And I navigate to "Question bank" in current page administration
And I add a "Essay (auto-grade)" question filling the form with:
| Question name | essayautograde-001 |
| Question text | Please write a story about a frog. |
| General feedback | I hope your story had a beginning, a middle and an end. |
| Response format | HTML editor |
And I add a "Essay (auto-grade)" question filling the form with:
| Question name | essayautograde-002 |
| Question text | Please write a story about a frog. |
| General feedback | I hope your story had a beginning, a middle and an end. |
| Response format | HTML editor with file picker |
And I add a "Essay (auto-grade)" question filling the form with:
| Question name | essayautograde-003 |
| Question text | Please write a story about a frog. |
| General feedback | I hope your story had a beginning, a middle and an end. |
| Response format | Plain text |

Scenario: Edit an Essay question
Scenario: Edit an Essay autograde question
When I click on "Edit" "link" in the "essayautograde-001" "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 essayautograde-001 name |
| Response format | No inline text |
| Response format | No online text |
And I press "id_submitbutton"
Then I should see "When \"no inline text\" is selected, or responses are optional, you must allow at least one attachment."
Then I should see "When \"No online text\" is selected, or responses are optional, you must allow at least one attachment."
When I set the following fields to these values:
| Response format | Plain text |
And I press "id_submitbutton"
Expand Down
25 changes: 13 additions & 12 deletions tests/behat/export.feature
@@ -1,7 +1,7 @@
@qtype @qtype_essayautograde
Feature: Test exporting Essay questions
Feature: Test exporting Essay autograde questions
As a teacher
In order to be able to reuse my Essay questions
In order to be able to reuse my Essay autograde questions
I need to export them

Background:
Expand All @@ -18,18 +18,19 @@ Feature: Test exporting Essay questions
| contextlevel | reference | name |
| Course | C1 | Test questions |
And the following "questions" exist:
| questioncategory | qtype | name | template |
| Test questions | essayautograde | essayautograde-001 | editor |
| Test questions | essayautograde | essayautograde-002 | editorfilepicker |
| Test questions | essayautograde | essayautograde-003 | plain |
And I log in as "teacher1"
And I follow "Course 1"

Scenario: Export 3 Essay questions
When I navigate to "Export" node in "Course administration > Question bank"
| questioncategory | qtype | name | template |
| Test questions | essayautograde | essayautograde-001 | editor |
| Test questions | essayautograde | essayautograde-002 | editorfilepicker |
| Test questions | essayautograde | essayautograde-003 | plain |
And I log in as "admin"
Scenario: Export 3 Essay autograde questions
When I am on "Course 1" course homepage
And I navigate to "Question bank > Export" in current page administration
And I set the field "id_format_xml" to "1"
And I press "Export questions to file"
Then following "click here" should download between "2600" and "2700" bytes
Then I should see "Your export file should start to download shortly"
#TODO: And following "click here" should download between "2600" and "12700" 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
Expand Down
4 changes: 2 additions & 2 deletions tests/behat/import.feature
Expand Up @@ -15,11 +15,11 @@ Feature: Test importing Essay questions
| user | course | role |
| teacher1 | C1 | editingteacher |
And I log in as "teacher1"
And I follow "Course 1"
And I am on "Course 1" course homepage

@javascript @_file_upload
Scenario: import Essay question.
When I navigate to "Import" node in "Course administration > Question bank"
When I navigate to "Question bank > Import" in current page administration
And I set the field "id_format_xml" to "1"
And I upload "question/type/essayautograde/tests/fixtures/testquestion.moodle.xml" file to "Import" filemanager
And I press "id_submitbutton"
Expand Down
24 changes: 12 additions & 12 deletions tests/behat/preview.feature
@@ -1,7 +1,7 @@
@qtype @qtype_essayautograde
Feature: Preview Essay questions
Feature: Preview Essay autograde questions
As a teacher
In order to check my Essay questions will work for students
In order to check my Essay autograde questions will work for students
I need to preview them

Background:
Expand All @@ -18,16 +18,16 @@ Feature: Preview Essay questions
| contextlevel | reference | name |
| Course | C1 | Test questions |
And the following "questions" exist:
| questioncategory | qtype | name | template |
| Test questions | essayautograde | essayautograde-001 | editor |
| Test questions | essayautograde | essayautograde-002 | editorfilepicker |
| Test questions | essayautograde | essayautograde-003 | plain |
| questioncategory | qtype | name | template |
| Test questions | essayautograde | essayautograde-001 | editor |
| Test questions | essayautograde | essayautograde-002 | editorfilepicker |
| Test questions | essayautograde | essayautograde-003 | plain |
Given I log in as "teacher1"
And I follow "Course 1"
And I navigate to "Question bank" node in "Course administration"

And I am on "Course 1" course homepage
And I navigate to "Question bank" in current page administration
@javascript @_switch_window
Scenario: Preview an Essay question and submit a partially correct response.
Scenario: Preview an Essay autograde question and submit a partially correct response.
When I click on "Preview" "link" in the "essayautograde-001" "table_row"
And I switch to "questionpreview" window
And I set the field "How questions behave" to "Immediate feedback"
Expand All @@ -36,7 +36,7 @@ Feature: Preview Essay questions
And I switch to the main window

@javascript @_switch_window
Scenario: Preview an Essay question and submit a partially correct response.
Scenario: Preview an Essay autograde question and submit a partially correct response.
When I click on "Preview" "link" in the "essayautograde-002" "table_row"
And I switch to "questionpreview" window
And I set the field "How questions behave" to "Immediate feedback"
Expand All @@ -46,7 +46,7 @@ Feature: Preview Essay questions
And I switch to the main window

@javascript @_switch_window
Scenario: Preview an Essay question and submit a partially correct response.
Scenario: Preview an Essay autograde question and submit a partially correct response.
When I click on "Preview" "link" in the "essayautograde-003" "table_row"
And I switch to "questionpreview" window
And I set the field "How questions behave" to "Immediate feedback"
Expand Down

0 comments on commit d5b5739

Please sign in to comment.