mirror of
https://github.com/moodle/moodle.git
synced 2025-04-12 20:12:15 +02:00
MDL-45602 behat: add members to cohorts
This commit is contained in:
parent
457f818026
commit
9cc66e866c
@ -253,24 +253,40 @@ Feature: Set up contextual data for tests
|
||||
And I set the field "groups" to "Group 2 (1)"
|
||||
And the "members" select box should contain "Student 2"
|
||||
|
||||
Scenario: Add cohorts with data generator
|
||||
Scenario: Add cohorts and cohort members with data generator
|
||||
Given the following "categories" exist:
|
||||
| name | category | idnumber |
|
||||
| Cat 1 | 0 | CAT1 |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| student1 | Student | 1 | student1@asd.com |
|
||||
| student2 | Student | 2 | student2@asd.com |
|
||||
And the following "cohorts" exist:
|
||||
| name | idnumber |
|
||||
| System cohort 1 | CH01 |
|
||||
| System cohort A | CHSA |
|
||||
And the following "cohorts" exist:
|
||||
| name | idnumber | contextlevel | reference |
|
||||
| System cohort 2 | CH02 | System | |
|
||||
| Cohort in category 1 | CH1 | Category | CAT1 |
|
||||
| System cohort B | CHSB | System | |
|
||||
| Cohort in category | CHC | Category | CAT1 |
|
||||
| Empty cohort | CHE | Category | CAT1 |
|
||||
And the following "cohort members" exist:
|
||||
| user | cohort |
|
||||
| student1 | CHSA |
|
||||
| student2 | CHSB |
|
||||
| student1 | CHSB |
|
||||
| student1 | CHC |
|
||||
When I log in as "admin"
|
||||
And I navigate to "Cohorts" node in "Site administration > Users > Accounts"
|
||||
Then I should see "System cohort 1"
|
||||
And I should see "System cohort 2"
|
||||
Then the following should exist in the "cohorts" table:
|
||||
| Name | Cohort size |
|
||||
| System cohort A | 1 |
|
||||
| System cohort B | 2 |
|
||||
And I should not see "Cohort in category"
|
||||
And I follow "Courses"
|
||||
And I follow "Cat 1"
|
||||
And I follow "Cohorts"
|
||||
And I should see "Cohort in category 1"
|
||||
And I should not see "System cohort"
|
||||
And the following should exist in the "cohorts" table:
|
||||
| Name | Cohort size |
|
||||
| Cohort in category | 1 |
|
||||
| Empty cohort | 0 |
|
||||
|
@ -127,6 +127,11 @@ class behat_data_generators extends behat_base {
|
||||
'datagenerator' => 'cohort',
|
||||
'required' => array('idnumber')
|
||||
),
|
||||
'cohort members' => array(
|
||||
'datagenerator' => 'cohort_member',
|
||||
'required' => array('user', 'cohort'),
|
||||
'switchids' => array('user' => 'userid', 'cohort' => 'cohortid')
|
||||
),
|
||||
'roles' => array(
|
||||
'datagenerator' => 'role',
|
||||
'required' => array('shortname')
|
||||
@ -412,6 +417,16 @@ class behat_data_generators extends behat_base {
|
||||
$this->datagenerator->create_role($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds members to cohorts
|
||||
*
|
||||
* @param array $data
|
||||
* @return void
|
||||
*/
|
||||
protected function process_cohort_member($data) {
|
||||
cohort_add_member($data['cohortid'], $data['userid']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the user id from it's username.
|
||||
* @throws Exception
|
||||
@ -509,6 +524,21 @@ class behat_data_generators extends behat_base {
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cohort id from it's idnumber.
|
||||
* @throws Exception
|
||||
* @param string $idnumber
|
||||
* @return int
|
||||
*/
|
||||
protected function get_cohort_id($idnumber) {
|
||||
global $DB;
|
||||
|
||||
if (!$id = $DB->get_field('cohort', 'id', array('idnumber' => $idnumber))) {
|
||||
throw new Exception('The specified cohort with idnumber "' . $idnumber . '" does not exist');
|
||||
}
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the internal context id from the context reference.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user