Skip to content

Commit

Permalink
Merge branch 'wip-MDL-46503-master' of git://github.com/marinaglancy/…
Browse files Browse the repository at this point in the history
…moodle
  • Loading branch information
danpoltawski committed Jul 28, 2014
2 parents d4a89aa + 5f079af commit 5a8f38d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
22 changes: 22 additions & 0 deletions admin/tool/behat/tests/behat/data_generators.feature
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,25 @@ Feature: Set up contextual data for tests
And the "members" select box should contain "Student 1"
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
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"
19 changes: 19 additions & 0 deletions lib/tests/behat/behat_data_generators.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,25 @@ protected function preprocess_user($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
* @throws Exception Custom exception for test writers
Expand Down

0 comments on commit 5a8f38d

Please sign in to comment.