diff --git a/admin/tests/behat/behat_admin.php b/admin/tests/behat/behat_admin.php new file mode 100644 index 0000000000000..cdca881ae4a3d --- /dev/null +++ b/admin/tests/behat/behat_admin.php @@ -0,0 +1,97 @@ +. + +/** + * Steps definitions related with administration. + * + * @package core + * @category test + * @copyright 2013 David MonllaĆ³ + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php. + +require_once(__DIR__ . '/../../../lib/behat/behat_base.php'); +require_once(__DIR__ . '/../../../lib/behat/behat_field_manager.php'); + +use Behat\Gherkin\Node\TableNode as TableNode, + Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException; + +/** + * Site administration level steps definitions. + * + * @package core + * @category test + * @copyright 2013 David MonllaĆ³ + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class behat_admin extends behat_base { + + /** + * Sets the specified site settings. A table with | Setting label | value | is expected. + * + * @Given /^I set the following administration settings values:$/ + * @param TableNode $table + */ + public function i_set_the_following_administration_settings_values(TableNode $table) { + + if (!$data = $table->getRowsHash()) { + return; + } + + foreach ($data as $label => $value) { + + // We expect admin block to be visible, otherwise go to homepage. + if (!$this->getSession()->getPage()->find('css', '.block_settings')) { + $this->getSession()->visit($this->locate_path('/')); + $this->getSession()->wait(self::TIMEOUT, '(document.readyState === "complete")'); + } + + // Search by label. + $searchbox = $this->find_field('Search in settings'); + $searchbox->setValue($label); + $submitsearch = $this->find('css', 'form.adminsearchform input[type=submit]'); + $submitsearch->press(); + + $this->getSession()->wait(self::TIMEOUT, '(document.readyState === "complete")'); + + // Admin settings does not use the same DOM structure than other moodle forms + // but we also need to use lib/behat/form_field/* to deal with the different moodle form elements. + $exception = new ElementNotFoundException($this->getSession(), '"' . $label . '" administration setting '); + $fieldxpath = "//*[self::input | self::textarea | self::select][not(./@type = 'submit' or ./@type = 'image' or ./@type = 'hidden')] +[@id=//label[contains(normalize-space(string(.)), '" . $label . "')]/@for]"; + $fieldnode = $this->find('xpath', $fieldxpath, $exception); + $formfieldtypenode = $this->find('xpath', $fieldxpath . "/ancestor::div[@class='form-setting'] +/child::div[contains(concat(' ', @class, ' '), ' form-')]/child::*/parent::div"); + + // Getting the class which contains the field type. + $classes = explode(' ', $formfieldtypenode->getAttribute('class')); + foreach ($classes as $class) { + if (substr($class, 0, 5) == 'form-') { + $type = substr($class, 5); + } + } + + // Instantiating the appropiate field type. + $field = behat_field_manager::get_field_instance($type, $fieldnode, $this->getSession()); + $field->set_value($value); + + $this->find_button('Save changes')->press(); + } + } + +} diff --git a/completion/tests/behat/restrict_section_availability.feature b/completion/tests/behat/restrict_section_availability.feature new file mode 100644 index 0000000000000..88866b1cc512b --- /dev/null +++ b/completion/tests/behat/restrict_section_availability.feature @@ -0,0 +1,53 @@ +@core_completion +Feature: Restrict sections availability through completion conditions + In order to control section's contents access through activities completion + As a moodle teacher + I need to restrict sections availability using different conditions + + @javascript + Scenario: Show section greyed-out to students when completion conditions are not satisfied + Given the following "courses" exists: + | fullname | shortname | category | + | Course 1 | C1 | 0 | + And the following "users" exists: + | username | firstname | lastname | email | + | teacher1 | Teacher | Frist | teacher1@asd.com | + | student1 | Student | First | student1@asd.com | + And the following "course enrolments" exists: + | user | course | role | + | teacher1 | C1 | editingteacher | + | student1 | C1 | student | + And I log in as "admin" + And I set the following administration settings values: + | Enable completion tracking | 1 | + | Enable conditional access | 1 | + And I log out + And I log in as "teacher1" + And I follow "Course 1" + And I turn editing mode on + And I follow "Edit settings" + And I fill the moodle form with: + | Completion tracking | Enabled, control via completion and activity settings | + | Completion tracking begins on enrolment | 1 | + And I press "Save changes" + And I add a "Label" to section "1" and I fill the form with: + | Label text | Test label | + | Completion tracking | Students can manually mark the activity as completed | + And I add a "Page" to section "2" and I fill the form with: + | Name | Test page name | + | Description | Test page description | + | Page content | Test page contents | + When I click on "Edit summary" "link" in the "#section-2" "css_element" + And I fill the moodle form with: + | id_conditioncompletiongroup_0_conditionsourcecmid | Test label | + | id_conditioncompletiongroup_0_conditionrequiredcompletion | must be marked complete | + | Before section can be accessed | Show section greyed-out, with restriction information | + And I press "Save changes" + And I log out + And I log in as "student1" + And I follow "Course 1" + Then I should see "Not available until the activity Test label is marked complete." + And I should not see "Test page name" + And I press "Not completed: Test label. Select to mark as complete." + And I should see "Test page name" + And I should not see "Not available until the activity Test label is marked complete."