mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
MDL-46503 behat: cohort generator allows to create cohort in category
This commit is contained in:
parent
40f0ad21a3
commit
5f079af450
2 changed files with 41 additions and 0 deletions
|
@ -252,3 +252,25 @@ Feature: Set up contextual data for tests
|
||||||
And the "members" select box should contain "Student 1"
|
And the "members" select box should contain "Student 1"
|
||||||
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
|
||||||
|
Given the following "categories" exist:
|
||||||
|
| name | category | idnumber |
|
||||||
|
| Cat 1 | 0 | CAT1 |
|
||||||
|
And the following "cohorts" exist:
|
||||||
|
| name | idnumber |
|
||||||
|
| System cohort 1 | CH01 |
|
||||||
|
And the following "cohorts" exist:
|
||||||
|
| name | idnumber | contextlevel | reference |
|
||||||
|
| System cohort 2 | CH02 | System | |
|
||||||
|
| Cohort in category 1 | CH1 | Category | CAT1 |
|
||||||
|
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"
|
||||||
|
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"
|
||||||
|
|
|
@ -217,6 +217,25 @@ class behat_data_generators extends behat_base {
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If contextlevel and reference are specified for cohort, transform them to the contextid.
|
||||||
|
*
|
||||||
|
* @param array $data
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function preprocess_cohort($data) {
|
||||||
|
if (isset($data['contextlevel'])) {
|
||||||
|
if (!isset($data['reference'])) {
|
||||||
|
throw new Exception('If field contextlevel is specified, field reference must also be present');
|
||||||
|
}
|
||||||
|
$context = $this->get_context($data['contextlevel'], $data['reference']);
|
||||||
|
unset($data['contextlevel']);
|
||||||
|
unset($data['reference']);
|
||||||
|
$data['contextid'] = $context->id;
|
||||||
|
}
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adapter to modules generator
|
* Adapter to modules generator
|
||||||
* @throws Exception Custom exception for test writers
|
* @throws Exception Custom exception for test writers
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue