mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 08:55:15 +02:00
Merge branch 'MDL-38482_master' of git://github.com/dmonllao/moodle
This commit is contained in:
commit
6b117438b9
@ -58,6 +58,36 @@ class behat_course extends behat_base {
|
||||
return new Given('I press "Turn editing off"');
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new course with the provided table data matching course settings names with the desired values.
|
||||
*
|
||||
* @Given /^I create a course with:$/
|
||||
* @param TableNode $table The course data
|
||||
*/
|
||||
public function i_create_a_course_with(TableNode $table) {
|
||||
return array(
|
||||
new Given('I go to the courses management page'),
|
||||
new Given('I press "Add a new course"'),
|
||||
new Given('I fill the moodle form with:', $table),
|
||||
new Given('I press "Save changes"')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Goes to the system courses/categories management page.
|
||||
*
|
||||
* @Given /^I go to the courses management page$/
|
||||
*/
|
||||
public function i_go_to_the_courses_management_page() {
|
||||
|
||||
return array(
|
||||
new Given('I am on homepage'),
|
||||
new Given('I expand "Site administration" node'),
|
||||
new Given('I expand "Courses" node'),
|
||||
new Given('I follow "Add/edit courses"'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the selected activity/resource filling the form data with the specified field/value pairs.
|
||||
*
|
||||
|
50
course/tests/behat/max_number_sections.feature
Normal file
50
course/tests/behat/max_number_sections.feature
Normal file
@ -0,0 +1,50 @@
|
||||
@core_course @admin
|
||||
Feature: The maximum number of weeks/topics in a course can be configured
|
||||
In order to set boundaries to courses size
|
||||
As a moodle manager
|
||||
I need to limit the number of weeks/topics a course can have
|
||||
|
||||
Background:
|
||||
Given the following "users" exists:
|
||||
| username | firstname | lastname | email |
|
||||
| manager1 | Manager | 1 | manager1@asd.com |
|
||||
And the following "system role assigns" exists:
|
||||
| user | course | role |
|
||||
| manager1 | Acceptance test site | manager |
|
||||
And I log in as "admin"
|
||||
And I expand "Site administration" node
|
||||
And I expand "Courses" node
|
||||
And I follow "Course default settings"
|
||||
|
||||
@javascript
|
||||
Scenario: The number of sections can be increased and the limits are applied to courses
|
||||
Given I fill in "Maximum number of sections" with "100"
|
||||
When I press "Save changes"
|
||||
Then the "Maximum number of sections" field should match "100" value
|
||||
And the "Number of sections" select box should contain "100"
|
||||
And I log out
|
||||
And I log in as "manager1"
|
||||
And I create a course with:
|
||||
| Course full name | New course fullname |
|
||||
| Course short name | New course shortname |
|
||||
| Number of sections | 90 |
|
||||
| Format | Topics format |
|
||||
And I follow "New course fullname"
|
||||
And I should see "Topic 90"
|
||||
|
||||
@javascript
|
||||
Scenario: The number of sections can be reduced to 0 and the limits are applied to courses
|
||||
Given I fill in "Maximum number of sections" with "0"
|
||||
When I press "Save changes"
|
||||
Then the "Maximum number of sections" field should match "0" value
|
||||
And the "Number of sections" select box should contain "0"
|
||||
And the "Number of sections" select box should not contain "52"
|
||||
And I log out
|
||||
And I log in as "manager1"
|
||||
And I create a course with:
|
||||
| Course full name | New course fullname |
|
||||
| Course short name | New course shortname |
|
||||
| Number of sections | 0 |
|
||||
| Format | Topics format |
|
||||
And I follow "New course fullname"
|
||||
And I should not see "Topic 1"
|
@ -37,10 +37,11 @@ use Behat\Behat\Exception\PendingException as PendingException;
|
||||
* Acceptance tests are block-boxed, so this steps definitions should only
|
||||
* be used to set up the test environment as we are not replicating user steps.
|
||||
*
|
||||
* All data generators should be in lib/testing/generator/* and shared between phpunit
|
||||
* All data generators should be in lib/testing/generator/*, shared between phpunit
|
||||
* and behat and they should be called from here, if possible using the standard
|
||||
* 'create_$elementname($options)' and if not possible (data generators arguments will not be
|
||||
* always the same) create an adapter 'adapt_$elementname($options)' that uses the data generator.
|
||||
* 'create_$elementname($options)' and if it's not possible (data generators arguments will not be
|
||||
* always the same) or the element is not suitable to be a data generator, create a
|
||||
* 'process_$elementname($options)' method and use the data generator from there if possible.
|
||||
*
|
||||
* @todo If the available elements list grows too much this class must be split into smaller pieces
|
||||
* @package core
|
||||
@ -93,6 +94,11 @@ class behat_data_generators extends behat_base {
|
||||
'switchids' => array('user' => 'userid', 'course' => 'courseid', 'role' => 'roleid')
|
||||
|
||||
),
|
||||
'system role assigns' => array(
|
||||
'datagenerator' => 'role_assign',
|
||||
'required' => array('user', 'role'),
|
||||
'switchids' => array('user' => 'userid', 'role' => 'roleid')
|
||||
),
|
||||
'group members' => array(
|
||||
'datagenerator' => 'group_member',
|
||||
'required' => array('user', 'group'),
|
||||
@ -168,9 +174,9 @@ class behat_data_generators extends behat_base {
|
||||
// Using data generators directly.
|
||||
$this->datagenerator->{$methodname}($elementdata);
|
||||
|
||||
} else if (method_exists($this, 'adapt_' . $elementdatagenerator)) {
|
||||
// Using an adaptor to use the data generator.
|
||||
$this->{'adapt_' . $elementdatagenerator}($elementdata);
|
||||
} else if (method_exists($this, 'process_' . $elementdatagenerator)) {
|
||||
// Using an alternative to the direct data generator call.
|
||||
$this->{'process_' . $elementdatagenerator}($elementdata);
|
||||
} else {
|
||||
throw new PendingException($elementname . ' data generator is not implemented');
|
||||
}
|
||||
@ -194,10 +200,11 @@ class behat_data_generators extends behat_base {
|
||||
/**
|
||||
* Adapter to enrol_user() data generator.
|
||||
* @throws Exception
|
||||
* @param mixed $data
|
||||
* @param array $data
|
||||
* @return void
|
||||
*/
|
||||
protected function adapt_enrol_user($data) {
|
||||
protected function process_enrol_user($data) {
|
||||
global $SITE;
|
||||
|
||||
if (empty($data['roleid'])) {
|
||||
throw new Exception('\'course enrolments\' requires the field \'role\' to be specified');
|
||||
@ -215,7 +222,37 @@ class behat_data_generators extends behat_base {
|
||||
$data['enrol'] = 'manual';
|
||||
}
|
||||
|
||||
$this->datagenerator->enrol_user($data['userid'], $data['courseid'], $data['roleid'], $data['enrol']);
|
||||
// If the provided course shortname is the site shortname we consider it a system role assign.
|
||||
if ($data['courseid'] == $SITE->id) {
|
||||
// Frontpage course assign.
|
||||
$context = context_course::instance($data['courseid']);
|
||||
role_assign($data['roleid'], $data['userid'], $context->id);
|
||||
|
||||
} else {
|
||||
// Course assign.
|
||||
$this->datagenerator->enrol_user($data['userid'], $data['courseid'], $data['roleid'], $data['enrol']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns a role to a user at system level.
|
||||
* @throws Exception
|
||||
* @param array $data
|
||||
* @return void
|
||||
*/
|
||||
protected function process_role_assign($data) {
|
||||
|
||||
if (empty($data['roleid'])) {
|
||||
throw new Exception('\'system role assigns\' requires the field \'role\' to be specified');
|
||||
}
|
||||
|
||||
if (!isset($data['userid'])) {
|
||||
throw new Exception('\'system role assigns\' requires the field \'user\' to be specified');
|
||||
}
|
||||
|
||||
$context = context_system::instance();
|
||||
role_assign($data['roleid'], $data['userid'], $context->id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user