Skip to content

Commit

Permalink
MDL-40619 behat: test for creating a one-question quiz
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaglancy committed Feb 17, 2014
1 parent 692d247 commit 7f051de
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 0 deletions.
54 changes: 54 additions & 0 deletions mod/quiz/tests/behat/add_quiz.feature
@@ -0,0 +1,54 @@
@mod @mod_quiz
Feature: Add a quiz
In order to evaluate students
As a teacher
I need to create a quiz

Background:
Given the following "users" exists:
| username | firstname | lastname | email |
| teacher1 | Terry1 | Teacher1 | teacher1@moodle.com |
| student1 | Sam1 | Student1 | student1@moodle.com |
And the following "courses" exists:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "course enrolments" exists:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
When I log in as "teacher1"
And I follow "Course 1"
And I turn editing mode on
And I add a "Quiz" to section "1" and I fill the form with:
| Name | Test quiz name |
| Description | Test quiz description |
And I add a "True/False" question to the "Test quiz name" quiz with:
| Question name | First question |
| Question text | Answer the first question |
| General feedback | Thank you, this is the general feedback |
| Correct answer | False |
| Feedback for the response 'True'. | So you think it is true |
| Feedback for the response 'False'. | So you think it is false |
And I log out
And I log in as "student1"
And I follow "Course 1"
And I follow "Test quiz name"
And I press "Attempt quiz now"
Then I should see "Question 1"
And I should see "Answer the first question"
And I select "True" radio button
And I press "Next"
And I should see "Answer saved"
And I press "Submit all and finish"
And I press "Yes"
And I should see "So you think it is true"
And I should see "Thank you, this is the general feedback"
And I should see "The correct answer is 'False'."
And I follow "Finish review"
And I should see "Highest grade: 0.00 / 10.00."
And I log out

@javascript
Scenario: Add and configure small quiz and perform an attempt as a student with Javascript enabled

#Scenario: Add and configure small quiz and perform an attempt as a student with Javascript disabled
69 changes: 69 additions & 0 deletions mod/quiz/tests/behat/behat_mod_quiz.php
@@ -0,0 +1,69 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Steps definitions related to mod_quiz.
*
* @package mod_quiz
* @category test
* @copyright 2014 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.

require_once(__DIR__ . '/../../../../lib/behat/behat_base.php');

use Behat\Behat\Context\Step\Given as Given,
Behat\Gherkin\Node\TableNode as TableNode;

/**
* Steps definitions related to mod_quiz.
*
* @package mod_quiz
* @category test
* @copyright 2014 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_mod_quiz extends behat_base {
/**
* Adds a question to the existing quiz with filling the form.
*
* The form for creating a question should be on one page.
*
* @When /^I add a "(?P<question_type_string>(?:[^"]|\\")*)" question to the "(?P<quiz_name_string>(?:[^"]|\\")*)" quiz with:$/
* @param string $questiontype
* @param string $quizname
* @param TableNode $table with data for filling the add question form
*/
public function i_add_question_to_the_quiz_with($questiontype, $quizname, TableNode $table) {
$questiontype = $this->escape($questiontype);
$quizname = $this->escape($quizname);
$editquiz = $this->escape(get_string('editquiz', 'quiz'));
$addaquestion = $this->escape(get_string('addaquestion', 'quiz'));
$next = $this->escape(get_string('next'));
$savechanges = $this->escape(get_string('savechanges'));
return array(
new Given("I follow \"$quizname\""),
new Given("I follow \"$editquiz\""),
new Given("I press \"$addaquestion\""),
new Given("I select \"$questiontype\" radio button"),
new Given("I press \"$next\""),
new Given("I fill the moodle form with:", $table),
new Given("I press \"$savechanges\"")
);
}
}

0 comments on commit 7f051de

Please sign in to comment.