mirror of
https://github.com/moodle/moodle.git
synced 2025-05-09 01:36:40 +02:00
Merge branch 'wip-MDL-45602-master' of git://github.com/marinaglancy/moodle
This commit is contained in:
commit
205cd43352
@ -253,24 +253,40 @@ Feature: Set up contextual data for tests
|
|||||||
And I set the field "groups" to "Group 2 (1)"
|
And I set the field "groups" to "Group 2 (1)"
|
||||||
And the "members" select box should contain "Student 2"
|
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:
|
Given the following "categories" exist:
|
||||||
| name | category | idnumber |
|
| name | category | idnumber |
|
||||||
| Cat 1 | 0 | CAT1 |
|
| 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:
|
And the following "cohorts" exist:
|
||||||
| name | idnumber |
|
| name | idnumber |
|
||||||
| System cohort 1 | CH01 |
|
| System cohort A | CHSA |
|
||||||
And the following "cohorts" exist:
|
And the following "cohorts" exist:
|
||||||
| name | idnumber | contextlevel | reference |
|
| name | idnumber | contextlevel | reference |
|
||||||
| System cohort 2 | CH02 | System | |
|
| System cohort B | CHSB | System | |
|
||||||
| Cohort in category 1 | CH1 | Category | CAT1 |
|
| 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"
|
When I log in as "admin"
|
||||||
And I navigate to "Cohorts" node in "Site administration > Users > Accounts"
|
And I navigate to "Cohorts" node in "Site administration > Users > Accounts"
|
||||||
Then I should see "System cohort 1"
|
Then the following should exist in the "cohorts" table:
|
||||||
And I should see "System cohort 2"
|
| Name | Cohort size |
|
||||||
|
| System cohort A | 1 |
|
||||||
|
| System cohort B | 2 |
|
||||||
And I should not see "Cohort in category"
|
And I should not see "Cohort in category"
|
||||||
And I follow "Courses"
|
And I follow "Courses"
|
||||||
And I follow "Cat 1"
|
And I follow "Cat 1"
|
||||||
And I follow "Cohorts"
|
And I follow "Cohorts"
|
||||||
And I should see "Cohort in category 1"
|
|
||||||
And I should not see "System cohort"
|
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',
|
'datagenerator' => 'cohort',
|
||||||
'required' => array('idnumber')
|
'required' => array('idnumber')
|
||||||
),
|
),
|
||||||
|
'cohort members' => array(
|
||||||
|
'datagenerator' => 'cohort_member',
|
||||||
|
'required' => array('user', 'cohort'),
|
||||||
|
'switchids' => array('user' => 'userid', 'cohort' => 'cohortid')
|
||||||
|
),
|
||||||
'roles' => array(
|
'roles' => array(
|
||||||
'datagenerator' => 'role',
|
'datagenerator' => 'role',
|
||||||
'required' => array('shortname')
|
'required' => array('shortname')
|
||||||
@ -412,6 +417,16 @@ class behat_data_generators extends behat_base {
|
|||||||
$this->datagenerator->create_role($data);
|
$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.
|
* Gets the user id from it's username.
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
@ -509,6 +524,21 @@ class behat_data_generators extends behat_base {
|
|||||||
return $id;
|
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.
|
* Gets the internal context id from the context reference.
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user