Merge branch 'MDL-44618_master' of git://github.com/dmonllao/moodle

This commit is contained in:
Marina Glancy 2014-04-17 11:03:52 +08:00
commit 8416d55261
2 changed files with 147 additions and 0 deletions

View file

@ -0,0 +1,56 @@
@mod @mod_data
Feature: Users can add entries to database activities
In order to populate databases
As a user
I need to add entries to databases
Scenario: Students can add entries to a database
Given the following "users" exist:
| username | firstname | lastname | email |
| student1 | Student | 1 | student1@asd.com |
| teacher1 | Teacher | 1 | teacher1@asd.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 |
| student1 | C1 | student |
And the following "activities" exist:
| activity | name | intro | course | idnumber |
| data | Test database name | n | C1 | data1 |
And I log in as "teacher1"
And I follow "Course 1"
And I add a "Text input" field to "Test database name" database and I fill the form with:
| Field name | Test field name |
| Field description | Test field description |
# To generate the default templates.
And I follow "Templates"
And I log out
When I log in as "student1"
And I follow "Course 1"
And I add an entry to "Test database name" database with:
| Test field description | Student original entry |
And I press "Save and view"
Then I should see "Student original entry"
And I follow "Edit"
And I set the following fields to these values:
| Test field description | Student edited entry |
And I press "Save and view"
And I should see "Student edited entry"
And I add an entry to "Test database name" database with:
| Test field description | Student second entry |
And I press "Save and add another"
And I add an entry to "Test database name" database with:
| Test field description | Student third entry |
And I press "Save and view"
And I follow "View list"
And I should see "Student edited entry"
And I should see "Student second entry"
And I should see "Student third entry"
# Will delete the first one.
And I follow "Delete"
And I press "Delete"
And I should not see "Student edited entry"
And I should see "Student second entry"
And I should see "Student third entry"

View file

@ -0,0 +1,91 @@
<?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 with the database activity.
*
* @package mod_data
* @category test
* @copyright 2014 David Monllaó
* @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\Behat\Context\Step\When as When,
Behat\Gherkin\Node\TableNode as TableNode;
/**
* Database-related steps definitions.
*
* @package mod_data
* @category test
* @copyright 2014 David Monllaó
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_mod_data extends behat_base {
/**
* Adds a new field to a database
*
* @Given /^I add a "(?P<fieldtype_string>(?:[^"]|\\")*)" field to "(?P<activityname_string>(?:[^"]|\\")*)" database and I fill the form with:$/
*
* @param string $fieldtype
* @param string $activityname
* @param TableNode $fielddata
* @return Given[]
*/
public function i_add_a_field_to_database_and_i_fill_the_form_with($fieldtype, $activityname, TableNode $fielddata) {
$steps = array(
new Given('I follow "' . $this->escape($activityname) . '"'),
new Given('I follow "' . get_string('fields', 'mod_data') . '"'),
new Given('I set the field "newtype" to "' . $this->escape($fieldtype) . '"')
);
if (!$this->running_javascript()) {
$steps[] = new Given('I click on "' . get_string('go') . '" "button" in the ".fieldadd" "css_element"');
}
array_push(
$steps,
new Given('I set the following fields to these values:', $fielddata),
new Given('I press "' . get_string('add') . '"')
);
return $steps;
}
/**
* Adds an entry to a database.
*
* @Given /^I add an entry to "(?P<activityname_string>(?:[^"]|\\")*)" database with:$/
*
* @param string $activityname
* @param TableNode $entrydata
* @return When[]
*/
public function i_add_an_entry_to_database_with($activityname, TableNode $entrydata) {
return array(
new When('I follow "' . $this->escape($activityname) . '"'),
new When('I follow "' . get_string('add', 'mod_data') . '"'),
new When('I set the following fields to these values:', $entrydata),
);
}
}