Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 401 and 402] [Versions 401 and 403]

Steps definitions related to mod_quiz.

Copyright: 2014 Marina Glancy
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 986 lines (48 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 2 files
 question/tests/behat/behat_question_base.php
 lib/behat/behat_base.php

Defines 1 class

behat_mod_quiz:: (35 methods):
  resolve_page_url()
  resolve_page_instance_url()
  get_quiz_by_name()
  get_cm_by_quiz_name()
  quiz_contains_the_following_questions()
  quiz_contains_the_following_sections()
  i_add_question_to_the_quiz_with()
  i_set_the_max_mark_for_quiz_question()
  i_open_the_add_to_quiz_menu_for()
  i_should_see_on_quiz_page()
  i_should_not_see_on_quiz_page()
  i_should_see_before_on_the_edit_quiz_page()
  should_have_number_on_the_edit_quiz_page()
  get_xpath_page_break_icon_after_question()
  i_click_on_the_page_break_icon_after_question()
  the_page_break_icon_after_question_should_exist()
  the_page_break_icon_after_question_should_not_exist()
  the_page_break_link_after_question_should_contain()
  i_click_on_shuffle_for_section()
  shuffle_for_section_should_be()
  get_xpath_for_shuffle_checkbox()
  i_move_question_after_item_by_clicking_the_move_icon()
  i_move_question_after_item_by_dragging()
  i_delete_question_by_clicking_the_delete_icon()
  i_set_the_section_heading_for()
  i_should_see_question_in_section_in_the_quiz_navigation()
  extract_forced_randomisation_from_attempt_info()
  extract_responses_from_attempt_info()
  user_has_attempted_with_responses()
  user_has_started_an_attempt_at_quiz()
  user_has_started_an_attempt_at_quiz_with_details()
  user_has_input_answers_in_their_attempt_at_quiz()
  user_has_checked_answers_in_their_attempt_at_quiz()
  user_has_finished_an_attempt_at_quiz()
  get_exact_named_selectors()


Class: behat_mod_quiz  - X-Ref

Steps definitions related to mod_quiz.

resolve_page_url(string $page)   X-Ref
Convert page names to URLs for steps like 'When I am on the "[page name]" page'.

Recognised page names are:
| None so far!      |                                                              |

param: string $page name of the page, with the component name removed e.g. 'Admin notification'.
return: moodle_url the corresponding URL.

resolve_page_instance_url(string $type, string $identifier)   X-Ref
Convert page names to URLs for steps like 'When I am on the "[identifier]" "[page type]" page'.

Recognised page names are:
| pagetype          | name meaning                                | description                                  |
| View              | Quiz name                                   | The quiz info page (view.php)                |
| Edit              | Quiz name                                   | The edit quiz page (edit.php)                |
| Group overrides   | Quiz name                                   | The manage group overrides page              |
| User overrides    | Quiz name                                   | The manage user overrides page               |
| Grades report     | Quiz name                                   | The overview report for a quiz               |
| Responses report  | Quiz name                                   | The responses report for a quiz              |
| Manual grading report | Quiz name                               | The manual grading report for a quiz         |
| Statistics report | Quiz name                                   | The statistics report for a quiz             |
| Attempt review    | Quiz name > username > [Attempt] attempt no | Review page for a given attempt (review.php) |
| Question bank     | Quiz name                                   | The question bank page for a quiz            |

param: string $type identifies which type of page this is, e.g. 'Attempt review'.
param: string $identifier identifies the particular page, e.g. 'Test quiz > student > Attempt 1'.
return: moodle_url the corresponding URL.

get_quiz_by_name(string $name)   X-Ref
Get a quiz by name.

param: string $name quiz name.
return: stdClass the corresponding DB row.

get_cm_by_quiz_name(string $name)   X-Ref
Get a quiz cmid from the quiz name.

param: string $name quiz name.
return: stdClass cm from get_coursemodule_from_instance.

quiz_contains_the_following_questions($quizname, TableNode $data)   X-Ref
Put the specified questions on the specified pages of a given quiz.

The first row should be column names:
| question | page | maxmark | requireprevious |
The first two of those are required. The others are optional.

question        needs to uniquely match a question name.
page            is a page number. Must start at 1, and on each following
row should be the same as the previous, or one more.
maxmark         What the question is marked out of. Defaults to question.defaultmark.
requireprevious The question can only be attempted after the previous one was completed.

Then there should be a number of rows of data, one for each question you want to add.

For backwards-compatibility reasons, specifying the column names is optional
(but strongly encouraged). If not specified, the columns are asseumed to be
| question | page | maxmark |.

param: string $quizname the name of the quiz to add questions to.
param: TableNode $data information about the questions to add.

quiz_contains_the_following_sections($quizname, TableNode $data)   X-Ref
Put the specified section headings to start at specified pages of a given quiz.

The first row should be column names:
| heading | firstslot | shufflequestions |

heading   is the section heading text
firstslot is the slot number where the section starts
shuffle   whether this section is shuffled (0 or 1)

Then there should be a number of rows of data, one for each section you want to add.

param: string $quizname the name of the quiz to add sections to.
param: TableNode $data information about the sections to add.

i_add_question_to_the_quiz_with($questiontype, $quizname, TableNode $questiondata)   X-Ref
Adds a question to the existing quiz with filling the form.

The form for creating a question should be on one page.

param: string $questiontype
param: string $quizname
param: TableNode $questiondata with data for filling the add question form

i_set_the_max_mark_for_quiz_question($questionname, $newmark)   X-Ref
Set the max mark for a question on the Edit quiz page.

param: string $questionname the name of the question to set the max mark for.
param: string $newmark the mark to set

i_open_the_add_to_quiz_menu_for($pageorlast)   X-Ref
Open the add menu on a given page, or at the end of the Edit quiz page.

param: string $pageorlast either "Page n" or "last".

i_should_see_on_quiz_page($questionname, $pagenumber)   X-Ref
Check whether a particular question is on a particular page of the quiz on the Edit quiz page.

param: string $questionname the name of the question we are looking for.
param: number $pagenumber the page it should be found on.

i_should_not_see_on_quiz_page($questionname, $pagenumber)   X-Ref
Check whether a particular question is not on a particular page of the quiz on the Edit quiz page.

param: string $questionname the name of the question we are looking for.
param: number $pagenumber the page it should be found on.

i_should_see_before_on_the_edit_quiz_page($firstquestionname, $secondquestionname)   X-Ref
Check whether one question comes before another on the Edit quiz page.
The two questions must be on the same page.

param: string $firstquestionname the name of the question that should come first in order.
param: string $secondquestionname the name of the question that should come immediately after it in order.

should_have_number_on_the_edit_quiz_page($questionname, $number)   X-Ref
Check the number displayed alongside a question on the Edit quiz page.

param: string $questionname the name of the question we are looking for.
param: number $number the number (or 'i') that should be displayed beside that question.

get_xpath_page_break_icon_after_question($addorremoves, $questionname)   X-Ref
Get the xpath for a partcular add/remove page-break icon.

param: string $addorremoves 'Add' or 'Remove'.
param: string $questionname the name of the question before the icon.
return: string the requried xpath.

i_click_on_the_page_break_icon_after_question($addorremoves, $questionname)   X-Ref
Click the add or remove page-break icon after a particular question.

param: string $addorremoves 'Add' or 'Remove'.
param: string $questionname the name of the question before the icon to click.

the_page_break_icon_after_question_should_exist($addorremoves, $questionname)   X-Ref
Assert the add or remove page-break icon after a particular question exists.

param: string $addorremoves 'Add' or 'Remove'.
param: string $questionname the name of the question before the icon to click.
return: array of steps.

the_page_break_icon_after_question_should_not_exist($addorremoves, $questionname)   X-Ref
Assert the add or remove page-break icon after a particular question does not exist.

param: string $addorremoves 'Add' or 'Remove'.
param: string $questionname the name of the question before the icon to click.
return: array of steps.

the_page_break_link_after_question_should_contain($addorremoves, $questionname, $paramdata)   X-Ref
Check the add or remove page-break link after a particular question contains the given parameters in its url.

param: string $addorremoves 'Add' or 'Remove'.
param: string $questionname the name of the question before the icon to click.
param: TableNode $paramdata with data for checking the page break url
return: array of steps.

i_click_on_shuffle_for_section($heading)   X-Ref
Set Shuffle for shuffling questions within sections

param: string $heading the heading of the section to change shuffle for.

shuffle_for_section_should_be($heading, $value)   X-Ref
Check the shuffle checkbox for a particular section.

param: string $heading the heading of the section to check shuffle for
param: int $value whether the shuffle checkbox should be on or off.

get_xpath_for_shuffle_checkbox($heading)   X-Ref
Return the xpath for shuffle checkbox in section heading

param: string $heading
return: string

i_move_question_after_item_by_clicking_the_move_icon($questionname, $target)   X-Ref
Move a question on the Edit quiz page by first clicking on the Move icon,
then clicking one of the "After ..." links.

param: string $questionname the name of the question we are looking for.
param: string $target the target place to move to. One of the links in the pop-up like

i_move_question_after_item_by_dragging($questionname, $target)   X-Ref
Move a question on the Edit quiz page by dragging a given question on top of another item.

param: string $questionname the name of the question we are looking for.
param: string $target the target place to move to. Ether a question name, or "Page N"

i_delete_question_by_clicking_the_delete_icon($questionname)   X-Ref
Delete a question on the Edit quiz page by first clicking on the Delete icon,
then clicking one of the "After ..." links.

param: string $questionname the name of the question we are looking for.
return: array of steps.

i_set_the_section_heading_for($sectionname, $sectionheading)   X-Ref
Set the section heading for a given section on the Edit quiz page

param: string $sectionname the heading to change.
param: string $sectionheading the new heading to set.

i_should_see_question_in_section_in_the_quiz_navigation($questionnumber, $sectionheading)   X-Ref
Check that a given question comes after a given section heading in the
quiz navigation block.

param: int $questionnumber the number of the question to check.
param: string $sectionheading which section heading it should appear after.

extract_forced_randomisation_from_attempt_info(TableNode $attemptinfo)   X-Ref
Helper used by user_has_attempted_with_responses,
user_has_started_an_attempt_at_quiz_with_details, etc.

param: TableNode $attemptinfo data table from the Behat step
return: array with two elements, $forcedrandomquestions, $forcedvariants,

extract_responses_from_attempt_info(TableNode $attemptinfo)   X-Ref
Helper used by user_has_attempted_with_responses, user_has_checked_answers_in_their_attempt_at_quiz,
user_has_input_answers_in_their_attempt_at_quiz, etc.

param: TableNode $attemptinfo data table from the Behat step
return: array of responses that can be passed to $quizgenerator->submit_responses.

user_has_attempted_with_responses($username, $quizname, TableNode $attemptinfo)   X-Ref
Attempt a quiz.

The first row should be column names:
| slot | actualquestion | variant | response |
The first two of those are required. The others are optional.

slot           The slot
actualquestion This column is optional, and is only needed if the quiz contains
random questions. If so, this will let you control which actual
question gets picked when this slot is 'randomised' at the
start of the attempt. If you don't specify, then one will be picked
at random (which might make the response meaningless).
Give the question name.
variant        This column is similar, and also options. It is only needed if
the question that ends up in this slot returns something greater
than 1 for $question->get_num_variants(). Like with actualquestion,
if you specify a value here it is used the fix the 'random' choice
made when the quiz is started.
response       The response that was submitted. How this is interpreted depends on
the question type. It gets passed to
{@link core_question_generator::get_simulated_post_data_for_question_attempt()}
and therefore to the un_summarise_response method of the question to decode.

Then there should be a number of rows of data, one for each question you want to add.
There is no need to supply answers to all questions. If so, other qusetions will be
left unanswered.

param: string $username the username of the user that will attempt.
param: string $quizname the name of the quiz the user will attempt.
param: TableNode $attemptinfo information about the questions to add, as above.

user_has_started_an_attempt_at_quiz($username, $quizname)   X-Ref
Start a quiz attempt without answers.

Then there should be a number of rows of data, one for each question you want to add.
There is no need to supply answers to all questions. If so, other qusetions will be
left unanswered.

param: string $username the username of the user that will attempt.
param: string $quizname the name of the quiz the user will attempt.

user_has_started_an_attempt_at_quiz_with_details($username, $quizname, TableNode $attemptinfo)   X-Ref
Start a quiz attempt without answers.

The supplied data table for have a row for each slot where you want
to force either which random question was chose, or which random variant
was used, as for {@link user_has_attempted_with_responses()} above.

param: string $username the username of the user that will attempt.
param: string $quizname the name of the quiz the user will attempt.
param: TableNode $attemptinfo information about the questions to add, as above.

user_has_input_answers_in_their_attempt_at_quiz($username, $quizname, TableNode $attemptinfo)   X-Ref
Input answers to particular questions an existing quiz attempt, without
simulating a click of the 'Check' button, if any.

Then there should be a number of rows of data, with two columns slot and response,
as for {@link user_has_attempted_with_responses()} above.
There is no need to supply answers to all questions. If so, other questions will be
left unanswered.

param: string $username the username of the user that will attempt.
param: string $quizname the name of the quiz the user will attempt.
param: TableNode $attemptinfo information about the questions to add, as above.

user_has_checked_answers_in_their_attempt_at_quiz($username, $quizname, TableNode $attemptinfo)   X-Ref
Submit answers to questions an existing quiz attempt, with a simulated click on the 'Check' button.

This step should only be used with question behaviours that have have
a 'Check' button. Those include Interactive with multiple tires, Immediate feedback
and Immediate feedback with CBM.

Then there should be a number of rows of data, with two columns slot and response,
as for {@link user_has_attempted_with_responses()} above.
There is no need to supply answers to all questions. If so, other questions will be
left unanswered.

param: string $username the username of the user that will attempt.
param: string $quizname the name of the quiz the user will attempt.
param: TableNode $attemptinfo information about the questions to add, as above.

user_has_finished_an_attempt_at_quiz($username, $quizname)   X-Ref
Finish an existing quiz attempt.

param: string $username the username of the user that will attempt.
param: string $quizname the name of the quiz the user will attempt.

get_exact_named_selectors()   X-Ref
Return a list of the exact named selectors for the component.

return: behat_component_named_selector[]