first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
@@ -0,0 +1,32 @@
@javascript @theme_classic
Feature: Add a block using classic theme
In order to check the blocks to display in the Add a block list for a them
As an administrator
I need to confirm the unaddableblocks setting is empty for classic.
Background:
Given the following "courses" exist:
| fullname | shortname |
| Course 1 | C1 |
And I log in as "admin"
Scenario: All the expected blocks are displayed in the Add a block list for classic
Given I am on "Course 1" course homepage with editing mode on
When I click on "Add a block" "select"
Then I should see "Administration"
And I should see "Navigation"
And I should see "Courses"
And I should see "Section links"
Scenario: Admins can change unaddable blocks using the unaddableblocks setting for classic
Given the following config values are set as admin:
| unaddableblocks | online_users,private_files,settings | theme_classic|
And I am on "Course 1" course homepage with editing mode on
When I click on "Add a block" "select"
Then I should not see "Online users"
And I should not see "Private files"
# The settings block is defined as required block for classic, so it will be displayed always.
And I should see "Administration"
And I should see "Navigation"
And I should see "Courses"
And I should see "Section links"
@@ -0,0 +1,95 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Step definitions related to administration overrides for the Classic theme.
*
* @package theme_classic
* @category test
* @copyright 2019 Michael Hawkins
* @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.
// For that reason, we can't even rely on $CFG->admin being available here.
require_once(__DIR__ . '/../../../../admin/tests/behat/behat_admin.php');
use Behat\Gherkin\Node\TableNode as TableNode,
Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException;
/**
* Site administration level steps definitions overrides for the Classic theme.
*
* @package theme_classic
* @category test
* @copyright 2019 Michael Hawkins
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_theme_classic_behat_admin extends behat_admin {
/**
* Sets the specified site settings. A table with | Setting label | value | is expected.
*
* @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->execute('behat_forms::i_am_on_homepage');
}
// Search by label.
$this->execute('behat_forms::i_set_the_field_to', [get_string('searchinsettings', 'admin'), $label]);
$this->execute("behat_general::i_click_on_in_the", [get_string('search', 'admin'), 'button', '.block_settings', 'css_element']);
// 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 ');
// The argument should be converted to an xpath literal.
$label = behat_context_helper::escape($label);
// Single element settings.
try {
$fieldxpath = "//*[self::input | self::textarea | self::select]" .
"[not(./@type = 'submit' or ./@type = 'image' or ./@type = 'hidden')]" .
"[@id=//label[contains(normalize-space(.), $label)]/@for or " .
"@id=//span[contains(normalize-space(.), $label)]/preceding-sibling::label[1]/@for]";
$fieldnode = $this->find('xpath', $fieldxpath, $exception);
} catch (ElementNotFoundException $e) {
// Multi element settings, interacting only the first one.
$fieldxpath = "//*[label[contains(., $label)]|span[contains(., $label)]]" .
"/ancestor::div[contains(concat(' ', normalize-space(@class), ' '), ' form-item ')]" .
"/descendant::*[self::input | self::textarea | self::select]" .
"[not(./@type = 'submit' or ./@type = 'image' or ./@type = 'hidden')]";
$fieldnode = $this->find('xpath', $fieldxpath);
}
$this->execute('behat_forms::i_set_the_field_with_xpath_to', [$fieldxpath, $value]);
$this->execute("behat_general::i_click_on", [get_string('savechanges'), 'button']);
}
}
}
@@ -0,0 +1,111 @@
<?php
use Behat\Gherkin\Node\TableNode;
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Step definitions related to blocks overrides for the Classic theme.
*
* @package theme_classic
* @category test
* @copyright 2019 Michael Hawkins
* @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__ . '/../../../../blocks/tests/behat/behat_blocks.php');
/**
* Blocks management step definitions for the Classic theme.
*
* @package theme_classic
* @category test
* @copyright 2019 Michael Hawkins
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_theme_classic_behat_blocks extends behat_blocks {
/**
* Adds the selected block. Editing mode must be previously enabled.
*
* @param string $blockname
* @return void
*/
public function i_add_the_block($blockname) {
$this->execute('behat_forms::i_set_the_field_to',
array("bui_addblock", $this->escape($blockname))
);
// If we are running without javascript we need to submit the form.
if (!$this->running_javascript()) {
$this->execute('behat_general::i_click_on_in_the',
array(get_string('go'), "button", "#add_block", "css_element")
);
}
}
/**
* Adds the selected block to the specified region
*
* Editing mode must be previously enabled.
*
* @param string $blockname
* @param string $region
*/
public function i_add_the_block_to_the_region(string $blockname, string $region) {
$this->execute('behat_blocks::i_add_the_block', [$blockname]);
}
/**
* Adds the selected block to the specified region and fills configuration form.
*
* Editing mode must be previously enabled.
*
* @param string $blockname
* @param string $region
* @param TableNode $data
*/
public function i_add_the_block_to_the_region_with(string $blockname, string $region, TableNode $data) {
$this->execute('behat_blocks::i_add_the_block_to_the_region', [$blockname, $region]);
$this->wait_for_pending_js();
$blocktitle = $blockname === 'Text' ? '(new text block)' : $blockname;
$this->execute('behat_blocks::i_configure_the_block', [$blocktitle]);
$dialogname = get_string('configureblock', 'core_block', $blocktitle);
$this->execute('behat_forms::i_set_the_following_fields_in_container_to_these_values',
[$dialogname, "dialogue", $data]);
$this->execute('behat_general::i_click_on_in_the', ["Save changes", 'button', $dialogname, 'dialogue']);
}
/**
* Ensures that block can be added to the page, but does not add it.
*
* @param string $blockname
* @return void
*/
public function the_add_block_selector_should_contain_block($blockname) {
$this->execute('behat_forms::the_select_box_should_contain', [get_string('addblock'), $blockname]);
}
/**
* Ensures that block cannot be added to the page.
*
* @param string $blockname
* @return void
*/
public function the_add_block_selector_should_not_contain_block($blockname) {
$this->execute('behat_forms::the_select_box_should_not_contain', [get_string('addblock'), $blockname]);
}
}
@@ -0,0 +1,40 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
require_once(__DIR__ . '/../../../../completion/tests/behat/behat_completion.php');
/**
* Step definitions related to blocks overrides for the Classic theme.
*
* @package theme_classic
* @category test
* @copyright 2021 Mathew May
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_theme_classic_behat_completion extends behat_completion {
/**
* Goes to the current course activity completion report.
*/
public function go_to_the_current_course_activity_completion_report() {
$completionnode = get_string('pluginname', 'report_progress');
$reportsnode = get_string('reports');
$this->execute("behat_navigation::i_navigate_to_in_current_page_administration",
$reportsnode . ' > ' . $completionnode);
}
}
@@ -0,0 +1,49 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
require_once(__DIR__ . '/../../../../question/tests/behat/behat_core_question.php');
use Behat\Gherkin\Node\TableNode as TableNode;
/**
* Step definitions related to blocks overrides for the Classic theme.
*
* @package theme_classic
* @category test
* @copyright 2021 Mathew May
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_theme_classic_behat_core_question extends behat_core_question {
/**
* Creates a question in the current course questions bank with the provided data.
* This step can only be used when creating question types composed by a single form.
*
* @param string $questiontypename The question type name
* @param TableNode $questiondata The data to fill the question type form.
*/
public function i_add_a_question_filling_the_form_with($questiontypename, TableNode $questiondata) {
// Go to question bank.
$this->execute("behat_general::click_link", get_string('questionbank', 'question'));
// Click on create question.
$this->execute('behat_forms::press_button', get_string('createnewquestion', 'question'));
// Add question.
$this->finish_adding_question($questiontypename, $questiondata);
}
}
@@ -0,0 +1,74 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Behat course-related step definition overrides for the Classic theme.
*
* @package theme_classic
* @category test
* @copyright 2019 Michael Hawkins
* @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__ . '/../../../../course/tests/behat/behat_course.php');
/**
* Course-related step definition overrides for the Classic theme.
*
* @package theme_classic
* @category test
* @copyright 2019 Michael Hawkins
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_theme_classic_behat_course extends behat_course {
/**
* Go to the course participants.
*/
public function i_navigate_to_course_participants() {
$coursestr = behat_context_helper::escape(get_string('courses'));
$mycoursestr = behat_context_helper::escape(get_string('mycourses'));
$xpath = "//div[contains(@class,'block')]//li[contains(@class,'contains_branch')]" .
"[p/*[string(.)=$coursestr or string(.)=$mycoursestr]]";
$this->execute('behat_general::i_click_on_in_the', [get_string('participants'), 'link', $xpath, 'xpath_element']);
}
/**
* Returns whether the user has permission to modify this course.
*
* @return bool
*/
protected function is_course_editor(): bool {
// If the course is already in editing mode then it will have the class 'editing' on the body.
// This is a 'cheap' way of telling if the course is in editing mode.
$body = $this->find('css', 'body');
if ($body->hasClass('editing')) {
return true;
}
// If the course is not already in editing mode, then the only real way to find out if the current user may edit
// the page is to look for the "Turn editing on" button.
// If the button is found then the user is a course editor.
try {
$this->find('button', get_string('turneditingon'), false, false, 0);
return true;
} catch (Exception $e) {
return false;
}
}
}
@@ -0,0 +1,57 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
use Behat\Mink\Exception\ElementNotFoundException;
require_once(__DIR__ . '/../../../../lib/tests/behat/behat_general.php');
/**
* Behat grade related step definition overrides for the Classic theme.
*
* @package theme_classic
* @category test
* @copyright 2021 Andrew Lyons <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_theme_classic_behat_general extends behat_general {
/**
* Check whether edit mode is available on the current page.
*
* @return bool
*/
public function is_edit_mode_available(): bool {
// If the course is already in editing mode then it will have the class 'editing' on the body.
// This is a 'cheap' way of telling if the course is in editing mode and therefore if edit mode is available.
$body = $this->find('css', 'body');
if ($body->hasClass('editing')) {
return true;
}
// If the page is not in editing mode then the only way to put it in editing mode is a "Turn editing on" button
// or link.
try {
$this->find('button', get_string('turneditingon'), false, false, 0);
return true;
} catch (ElementNotFoundException $e) {}
try {
$this->find('link', get_string('turneditingon'), false, false, 0);
return true;
} catch (ElementNotFoundException $e) {}
return false;
}
}
@@ -0,0 +1,57 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Behat grade related step definition overrides for the Classic theme.
*
* @package theme_classic
* @category test
* @copyright 2019 Michael Hawkins
* @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__ . '/../../../../grade/tests/behat/behat_grade.php');
use Behat\Gherkin\Node\TableNode as TableNode;
/**
* Behat grade overrides for the Classic theme.
*
* @package theme_classic
* @category test
* @copyright 2019 Michael Hawkins
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_theme_classic_behat_grade extends behat_grade {
/**
* Navigates to the course gradebook and selects a specified item from the grade navigation tabs.
*
* @param string $gradepath
*/
public function i_navigate_to_in_the_course_gradebook($gradepath) {
// If we are not on one of the gradebook pages already, follow "Grades" link in the navigation block.
$xpath = '//div[contains(@class,\'grade-navigation\')]';
if (!$this->getSession()->getPage()->findAll('xpath', $xpath)) {
$this->execute("behat_general::i_click_on_in_the", array(get_string('grades'), 'link',
get_string('pluginname', 'block_navigation'), 'block'));
}
$this->execute('behat_forms::i_set_the_field_to', [get_string('gradebooknavigationmenu', 'grades'), $gradepath]);
}
}
@@ -0,0 +1,42 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
require_once(__DIR__ . '/../../../../grade/grading/tests/behat/behat_grading.php');
/**
* Step definitions related to blocks overrides for the Classic theme.
*
* @package theme_classic
* @category test
* @copyright 2021 Mathew May
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_theme_classic_behat_grading extends behat_grading {
/**
* Goes to the selected advanced grading page. You should be in the course page when this step begins.
*
* @param string $activityname
*/
public function i_go_to_advanced_grading_page($activityname) {
$this->execute("behat_general::i_click_on_in_the", [$this->escape($activityname), 'link', 'page', 'region']);
$this->execute('behat_navigation::i_navigate_to_in_current_page_administration',
get_string('gradingmanagement', 'grading'));
}
}
@@ -0,0 +1,446 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Navigation step definition overrides for the Classic theme.
*
* @package theme_classic
* @category test
* @copyright 2019 Michael Hawkins
* @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/tests/behat/behat_navigation.php');
use Behat\Mink\Exception\ExpectationException as ExpectationException;
use Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException;
use Behat\Mink\Exception\DriverException as DriverException;
/**
* Step definitions and overrides to navigate through the navigation tree nodes in the Classic theme.
*
* @package theme_classic
* @category test
* @copyright 2019 Michael Hawkins
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_theme_classic_behat_navigation extends behat_navigation {
/**
* Navigate to an item in a current page administration menu.
*
* @throws ExpectationException
* @param string $nodetext The navigation node/path to follow, eg "Course administration > Edit settings"
* @return void
*/
public function i_navigate_to_in_current_page_administration($nodetext) {
$parentnodes = array_map('trim', explode('>', $nodetext));
// Find the name of the first category of the administration block tree.
$xpath = "//section[contains(@class,'block_settings')]//div[@id='settingsnav']/ul[1]/li[1]/p[1]/span";
$node = $this->find('xpath', $xpath);
array_unshift($parentnodes, $node->getText());
$lastnode = array_pop($parentnodes);
try {
$this->select_node_in_navigation($lastnode, $parentnodes);
} catch (Exception $e) {
try {
$this->execute("behat_general::click_link", $lastnode);
} catch (Exception $e) {
// We must be in a weird state i.e. Add competencies to course.
$this->execute("behat_general::click_link", array_pop($parentnodes));
$this->execute('behat_forms::press_button', $lastnode);
}
}
}
/**
* Navigate to an item within the site administration menu.
*
* @throws ExpectationException
* @param string $nodetext The navigation node/path to follow, excluding "Site administration" itself, eg "Grades > Scales"
* @return void
*/
public function i_navigate_to_in_site_administration($nodetext) {
$parentnodes = array_map('trim', explode('>', $nodetext));
array_unshift($parentnodes, get_string('administrationsite'));
$lastnode = array_pop($parentnodes);
$this->select_node_in_navigation($lastnode, $parentnodes);
}
/**
* Helper function to get top navigation node in the tree.
*
* @throws ExpectationException if node not found.
* @param string $nodetext name of top navigation node in tree.
* @return NodeElement
*/
protected function get_top_navigation_node($nodetext) {
// Avoid problems with quotes.
$nodetextliteral = behat_context_helper::escape($nodetext);
$exception = new ExpectationException('Top navigation node "' . $nodetext . '" not found', $this->getSession());
$xpath = // Navigation block.
"//div[contains(concat(' ', normalize-space(@class), ' '), ' content ')]" .
"/ul[contains(concat(' ', normalize-space(@class), ' '), ' block_tree ')]" .
"/li[contains(concat(' ', normalize-space(@class), ' '), ' contains_branch ')]" .
"/ul/li[contains(concat(' ', normalize-space(@class), ' '), ' contains_branch ')]" .
"[p[contains(concat(' ', normalize-space(@class), ' '), ' branch ')]" .
"[span[normalize-space(.)={$nodetextliteral}] or a[normalize-space(.)={$nodetextliteral}]]]" .
"|" .
// Administration block.
"//div[contains(concat(' ', normalize-space(@class), ' '), ' content ')]/div" .
"/ul[contains(concat(' ', normalize-space(@class), ' '), ' block_tree ')]" .
"/li[contains(concat(' ', normalize-space(@class), ' '), ' contains_branch ')]" .
"/ul/li[contains(concat(' ', normalize-space(@class), ' '), ' contains_branch ')]" .
"[p[contains(concat(' ', normalize-space(@class), ' '), ' branch ')]" .
"/span[normalize-space(.)={$nodetextliteral}]]" .
"|" .
"//div[contains(concat(' ', normalize-space(@class), ' '), ' content ')]/div" .
"/ul[contains(concat(' ', normalize-space(@class), ' '), ' block_tree ')]" .
"/li[p[contains(concat(' ', normalize-space(@class), ' '), ' branch ')]" .
"/span[normalize-space(.)={$nodetextliteral}]]" .
"|" .
"//div[contains(concat(' ', normalize-space(@class), ' '), ' content ')]/div" .
"/ul[contains(concat(' ', normalize-space(@class), ' '), ' block_tree ')]" .
"/li[p[contains(concat(' ', normalize-space(@class), ' '), ' branch ')]" .
"/a[normalize-space(.)={$nodetextliteral}]]";
$node = $this->find('xpath', $xpath, $exception);
return $node;
}
/**
* Check that current page administration contains an element.
*
* @throws ElementNotFoundException
* @param string $element The locator of the specified selector.
* This may be a path, for example "Subscription mode > Forced subscription"
* @param string $selectortype The selector type (link or text)
* @return void
*/
public function should_exist_in_current_page_administration($element, $selectortype) {
$nodes = array_map('trim', explode('>', $element));
$nodetext = end($nodes);
// Find administration menu.
$rootxpath = $this->find_header_administration_menu() ?: $this->find_page_administration_menu(true);
$menuxpath = $rootxpath . '/p/../ul[1]';
for ($i = 0; $i < (count($nodes) - 1); $i++) {
$menuxpath .= "/li/p/span[contains(text(), '{$nodes[$i]}')]/../../ul[1]";
}
if ($selectortype == 'link') {
$menuxpath .= "/li/p[a[contains(text(), '{$nodetext}')]";
$menuxpath .= "|a/span[contains(text(), '{$nodetext}')]]";
} else {
$menuxpath .= "/li/p/span[contains(text(), '{$nodes[$i]}')]";
}
$exception = new ElementNotFoundException($this->getSession(), "\"{$element}\" \"{$selectortype}\"");
try {
$this->find('xpath', $menuxpath, $exception);
} catch (Exception $e) {
// For question bank a different approach.
$menuxpath = $rootxpath . "//div[contains(@class, 'dropdown-menu')]";
if ($selectortype === 'link') {
$menuxpath .= "//a[contains(text(), 'Categories')]";
}
$this->find('xpath', $menuxpath, $e);
}
}
/**
* Check that current page administration does not contains an element.
*
* @throws ExpectationException
* @param string $element The locator of the specified selector.
* This may be a path, for example "Subscription mode > Forced subscription"
* @param string $selectortype The selector type (link or text)
* @return void
*/
public function should_not_exist_in_current_page_administration($element, $selectortype) {
try {
$menuxpath = $this->find_header_administration_menu() ?: $this->find_page_administration_menu(true);
} catch (Exception $e) {
// If an exception was thrown, it means the root note does not exist, so we can conclude the test is a success.
return;
}
// Test if the element exists.
try {
$this->should_exist_in_current_page_administration($element, $selectortype);
} catch (ElementNotFoundException $e) {
// If an exception was thrown, it means the element does not exist, so the test is successful.
return;
}
// If the try block passed, the element exists, so throw an exception.
$exception = 'The "' . $element . '" "' . $selectortype . '" was found, but should not exist';
throw new ExpectationException($exception, $this->getSession());
}
/**
* Check that the page administration menu exists on the page.
*
* This confirms the existence of the menu, which authorised users should have access to.
* @Given /^I should see the page administration menu$/
*
* @throws ExpectationException
* @return void
*/
public function page_administration_exists() {
$menuxpath = "//section[contains(@class,'block_settings')]//div[@id='settingsnav']";
$this->ensure_element_exists($menuxpath, 'xpath_element');
}
/**
* Check that the page administration menu does not exist on the page.
*
* This confirms the absence of the menu, which unauthorised users should not have access to.
* @Given /^I should not see the page administration menu$/
*
* @throws ExpectationException
* @return void
*/
public function page_administration_does_not_exist() {
$menuxpath = "//section[contains(@class,'block_settings')]//div[@id='settingsnav']";
$this->ensure_element_does_not_exist($menuxpath, 'xpath_element');
}
/**
* Locate the administration menu on the page (but not in the header) and return its xpath.
*
* @throws ElementNotFoundException
* @param bool $mustexist If true, throws an exception if menu is not found
* @return null|string
*/
protected function find_page_administration_menu($mustexist = false) {
$menuxpath = "//section[contains(@class,'block_settings')]//div[@id='settingsnav']/ul[1]/li[1]";
if ($mustexist) {
$exception = new ElementNotFoundException($this->getSession(), 'Page administration menu');
$this->find('xpath', $menuxpath, $exception);
} else if (!$this->getSession()->getPage()->find('xpath', $menuxpath)) {
return null;
}
return $menuxpath;
}
/**
* Turns editing mode off.
*/
public function i_turn_editing_mode_off(): void {
$buttonnames = [get_string('turneditingoff'), get_string('updatemymoodleoff'), get_string('blockseditoff')];
foreach ($buttonnames as $buttonname) {
if ($editbutton = $this->getSession()->getPage()->findButton($buttonname)) {
$this->execute('behat_general::i_click_on', [$editbutton, 'NodeElement']);
return;
}
}
// Click the turneditingoff link in the Site Administration block.
if ($this->is_editing_on()) {
$this->execute('behat_general::i_click_on', [get_string('turneditingoff'), "link"]);
}
}
/**
* Turns editing mode on.
*/
public function i_turn_editing_mode_on(): void {
$buttonnames = [get_string('turneditingon'), get_string('updatemymoodleon'), get_string('blocksediton')];
foreach ($buttonnames as $buttonname) {
if ($editbutton = $this->getSession()->getPage()->findButton($buttonname)) {
$this->execute('behat_general::i_click_on', [$editbutton, 'NodeElement']);
return;
}
}
if (!$this->is_editing_on()) {
$this->execute('behat_general::i_click_on', [get_string('turneditingon'), "link"]);
}
}
/**
* Finds and clicks a link on the admin page (site administration or course administration)
*
* @param array $nodelist
*/
protected function select_on_administration_page($nodelist) {
$parentnodes = $nodelist;
$lastnode = array_pop($parentnodes);
$xpath = '//section[@id=\'region-main\']';
// Check if there is a separate tab for this submenu of the page. If found go to it.
if ($parentnodes) {
$tabname = behat_context_helper::escape($parentnodes[0]);
$tabxpath = '//ul[@role=\'tablist\']/li/a[contains(normalize-space(.), ' . $tabname . ')]';
$menubarxpath = '//ul[@role=\'menubar\']/li/a[contains(normalize-space(.), ' . $tabname . ')]';
$linkname = behat_context_helper::escape(get_string('moremenu'));
$menubarmorexpath = '//ul[@role=\'menubar\']/li/a[contains(normalize-space(.), ' . $linkname . ')]';
$tabnode = $this->getSession()->getPage()->find('xpath', $tabxpath);
$menunode = $this->getSession()->getPage()->find('xpath', $menubarxpath);
$menubuttons = $this->getSession()->getPage()->findAll('xpath', $menubarmorexpath);
if ($tabnode || $menunode) {
$node = is_object($tabnode) ? $tabnode : $menunode;
if ($this->running_javascript()) {
$this->execute('behat_general::i_click_on', [$node, 'NodeElement']);
// Click on the tab and add 'active' tab to the xpath.
$xpath .= '//div[contains(@class,\'active\')]';
} else {
// Add the tab content selector to the xpath.
$tabid = behat_context_helper::escape(ltrim($node->getAttribute('href'), '#'));
$xpath .= '//div[@id = ' . $tabid . ']';
}
array_shift($parentnodes);
} else if (count($menubuttons) > 0) {
try {
$menubuttons[0]->isVisible();
try {
$this->execute('behat_general::i_click_on', [$menubuttons[1], 'NodeElement']);
} catch (Exception $e) {
$this->execute('behat_general::i_click_on', [$menubuttons[0], 'NodeElement']);
}
$moreitemxpath = '//ul[@data-region=\'moredropdown\']/li/a[contains(normalize-space(.), ' . $tabname . ')]';
if ($morenode = $this->getSession()->getPage()->find('xpath', $moreitemxpath)) {
$this->execute('behat_general::i_click_on', [$morenode, 'NodeElement']);
$xpath .= '//div[contains(@class,\'active\')]';
array_shift($parentnodes);
}
} catch (Exception $e) {
return;
}
}
}
// Find a section with the parent name in it.
if ($parentnodes) {
// Find the section on the page (links may be repeating in different sections).
$section = behat_context_helper::escape($parentnodes[0]);
$xpath .= '//div[@class=\'row\' and contains(.,'.$section.')]';
}
// Find a link and click on it.
$linkname = behat_context_helper::escape($lastnode);
$xpath .= '//a[contains(normalize-space(.), ' . $linkname . ')]';
if (!$node = $this->getSession()->getPage()->find('xpath', $xpath)) {
throw new ElementNotFoundException($this->getSession(), 'Link "' . join(' > ', $nodelist) . '"');
}
$this->execute('behat_general::i_click_on', [$node, 'NodeElement']);
}
/**
* Locates the administration menu in the <header> element and returns its xpath
*
* @param bool $mustexist if specified throws an exception if menu is not found
* @return null|string
*/
protected function find_header_administration_menu($mustexist = false) {
$menuxpath = '//header[@id=\'page-header\']//div[contains(@class,\'moodle-actionmenu\')]';
if ($mustexist) {
$exception = new ElementNotFoundException($this->getSession(), 'Page header administration menu');
$this->find('xpath', $menuxpath, $exception);
} else if (!$this->getSession()->getPage()->find('xpath', $menuxpath)) {
return null;
}
return $menuxpath;
}
/**
* Toggles administration menu
*
* @param string $menuxpath (optional) xpath to the page administration menu if already known
*/
protected function toggle_page_administration_menu($menuxpath = null) {
if (!$menuxpath) {
$menuxpath = $this->find_header_administration_menu() ?: $this->find_page_administration_menu();
}
if ($menuxpath && $this->running_javascript()) {
$node = $this->find('xpath', $menuxpath . '//a[@data-toggle=\'dropdown\']');
$this->execute('behat_general::i_click_on', [$node, 'NodeElement']);
}
}
/**
* Finds a page edit cog and select an item from it
*
* If the page edit cog is in the page header and the item is not found there, click "More..." link
* and find the item on the course/frontpage administration page
*
* @param array $nodelist
* @throws ElementNotFoundException
*/
protected function select_from_administration_menu($nodelist) {
// Find administration menu.
if ($menuxpath = $this->find_header_administration_menu()) {
$isheader = true;
} else {
$menuxpath = $this->find_page_administration_menu(true);
$isheader = false;
}
$this->execute('behat_navigation::toggle_page_administration_menu', [$menuxpath]);
if (!$isheader || count($nodelist) == 1) {
$lastnode = end($nodelist);
$linkname = behat_context_helper::escape($lastnode);
$link = $this->getSession()->getPage()->find('xpath', $menuxpath . '//a[contains(normalize-space(.), ' .
$linkname . ')]'
);
if ($link) {
$this->execute('behat_general::i_click_on', [$link, 'NodeElement']);
return;
}
}
if ($isheader) {
// Course administration and Front page administration will have subnodes under "More...".
$linkname = behat_context_helper::escape(get_string('morenavigationlinks'));
$link = $this->getSession()->getPage()->find('xpath', $menuxpath . '//a[contains(normalize-space(.), ' .
$linkname . ')]'
);
if ($link) {
$this->execute('behat_general::i_click_on', [$link, 'NodeElement']);
$this->select_on_administration_page($nodelist);
return;
}
}
throw new ElementNotFoundException($this->getSession(),
'Link "' . join(' > ', $nodelist) . '" in the current page edit menu"');
}
#[\Override]
public function menu_item_should_be_active(string $navigationmenuitem): void {
throw new DriverException(
'The Classic theme does not implement navigation in a way that allows this step to be used.',
);
}
#[\Override]
public function menu_item_should_not_be_active(string $navigationmenuitem): void {
throw new DriverException(
'The Classic theme does not implement the navigation in a way that allows this step to be used.',
);
}
}
@@ -0,0 +1,74 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Override definitions for the upload repository type for the Classic theme.
*
* @package theme_classic
* @category test
* @copyright 2019 Michael Hawkins
* @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__ . '/../../../../repository/upload/tests/behat/behat_repository_upload.php');
use Behat\Mink\Exception\ExpectationException as ExpectationException;
/**
* Override step definitions to deal with the upload repository in the Classic theme.
*
* @package theme_classic
* @category test
* @copyright 2019 Michael Hawkins
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_theme_classic_behat_repository_upload extends behat_repository_upload {
/**
* Gets the NodeElement for filepicker of filemanager moodleform element.
*
* @throws ExpectationException
* @param string $filepickerelement The filepicker form field label
* @return NodeElement The hidden element node.
*/
protected function get_filepicker_node($filepickerelement) {
// More info about the problem (in case there is a problem).
$exception = new ExpectationException('"' . $filepickerelement . '" filepicker can not be found', $this->getSession());
// If no file picker label is mentioned take the first file picker from the page.
if (empty($filepickerelement)) {
$filepickercontainer = $this->find(
'xpath',
"//*[@class=\"form-filemanager\"]",
$exception
);
} else {
// Gets the filemanager node specified by the locator which contains the filepicker container.
$filepickerelement = behat_context_helper::escape($filepickerelement);
$filepickercontainer = $this->find(
'xpath',
"//input[./@id = substring-before(//p[normalize-space(.)=$filepickerelement]/@id, '_label')]" .
"//ancestor::*[@data-fieldtype = 'filemanager' or @data-fieldtype = 'filepicker']",
$exception
);
}
return $filepickercontainer;
}
}
+21
View File
@@ -0,0 +1,21 @@
{
"contexts": [
"behat_theme_boost_behat_navigation"
],
"features": [
"lib/tests/behat/action_menu.feature",
"admin/tests/behat/site_administration.feature",
"blocks/tests/behat/hide_blocks.feature",
"blocks/tests/behat/move_blocks.feature",
"course/format/tests/behat/course_courseindex.feature",
"course/format/tests/behat/courseindex_keyboardnav.feature",
"course/format/tests/behat/courseindex_completion.feature",
"course/format/tests/behat/courseindex_language.feature",
"badges/tests/behat/badge_navigation.feature",
"lib/tests/behat/menu_navigation_single_activity.feature",
"lib/tests/behat/menu_navigation_topics.feature"
],
"tags": [
"addablocklink"
]
}
@@ -0,0 +1,42 @@
@core @core_course @theme_classic
Feature: Role assignments can be made at the category level in classic
In order to grant a user different capabilities
As a user
I can assign roles in categories
Background:
Given the following "users" exist:
| username | firstname | lastname |
| manager | Manager | Manager |
And the following "categories" exist:
| name | category | idnumber |
| Cat 1 | 0 | CAT1 |
And the following "role assigns" exist:
| user | role | contextlevel | reference |
| manager | manager | Category | CAT1 |
And I log in as "admin"
@javascript
Scenario: A user with a category role can assign roles
Given I define the allowed role assignments for the "Manager" role as:
| Teacher | Assignable |
And I log out
And I log in as "manager"
And I am on course index
When I follow "Cat 1"
Then "Assign roles" "link" should exist in current page administration
@javascript
Scenario: A user with a category role cannot assign roles if there are no roles to assign
Given I define the allowed role assignments for the "Manager" role as:
| Manager | Not assignable |
| Course creator | Not assignable |
| Teacher | Not assignable |
| Non-editing teacher | Not assignable |
| Student | Not assignable |
And I change window size to "large"
And I log out
And I log in as "manager"
And I am on course index
When I follow "Cat 1"
Then "Assign roles" "link" should not exist in current page administration
@@ -0,0 +1,30 @@
@theme_classic
Feature: Select course sections using classic theme
In order to view course sections when using the classic theme
As a teacher
I need to select the section from the section selector
Background:
Given the following "course" exists:
| fullname | Course 1 |
| shortname | C1 |
| numsections | 3 |
| initsections | 1 |
And the following "activities" exist:
| course | activity | name | idnumber | section |
| C1 | assign | Assignment 1 | assign1 | 1 |
| C1 | assign | Assignment 2 | assign2 | 2 |
@javascript
Scenario: Use the course section selector in classic theme
Given I am on the "C1" "Course" page logged in as "admin"
And I turn editing mode on
When I choose the "View" item in the "Edit" action menu of the "Section 1" "section"
Then I should see "Section 1"
And I should see "Assignment 1"
And I should not see "Assignment 2"
And I select "Section 2" from the "jump" singleselect
And I should see "Section 2"
And I should not see "Assignment 1"
And I should see "Assignment 2"
And the "jump" select box should contain "Section 3"
@@ -0,0 +1,27 @@
@javascript @theme_classic
Feature: Course administration menu
To navigate in classic theme teachers need to use the course administration menu
Background:
Given the following "courses" exist:
| fullname | shortname |
| Course 1 | C1 |
And the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
| student1 | Student | 1 | student1@example.com |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
Scenario: Teacher can use the course administration menu
And I log in as "teacher1"
And I am on "Course 1" course homepage
And I should see the page administration menu
Scenario: Student cannot see the course administration menu
And I log in as "student1"
And I am on "Course 1" course homepage
And I should not see the page administration menu
And I log out
@@ -0,0 +1,27 @@
@javascript @theme_classic
Feature: My courses page block layout in Classic theme
In order to have a clear and consistent view on the my courses page
As a student
I need to see the blocks in the expected placement
Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| student1 | Student | 1 | student@example.com |
And I log in as "admin"
And I am on site homepage
And I turn editing mode on
And I add the "Text" block
And I configure the "(new text block)" block
And I set the following fields to these values:
| Page contexts | Display throughout the entire site |
| Text block title | Text on all pages |
| Content | This is visible on all pages |
| Default region | Right |
And I press "Save changes"
Scenario: Student can see relevant blocks with correct placement on my courses page
When I log in as "student1"
And I am on the "My courses" page
Then "Course overview" "text" should exist in the "region-main" "region"
And "This is visible on all pages" "text" should exist in the ".columnright" "css_element"
@@ -0,0 +1,50 @@
@javascript @theme_classic
Feature: Page administration menu
To navigate in classic theme I need to use the page administration menu
Background:
Given the following "courses" exist:
| fullname | shortname | newsitems |
| Course 1 | C1 | 5 |
And the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
| student1 | Student | 1 | student1@example.com |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
And the following "activities" exist:
| activity | name | intro | course | idnumber | option |
| choice | Choice name | Test choice description | C1 | choice1 | Option 1, Option 2, Option 3 |
Scenario: Teacher can access activity administration menus
And I log in as "teacher1"
And I am on "Course 1" course homepage
And I follow "Choice name"
And I should see the page administration menu
And "Settings" "link" should exist in current page administration
And I navigate to "Settings" in current page administration
And I should see "Edit settings"
And I navigate to course participants
And I should see the page administration menu
And I am on the "Course 1" "Enrolment methods" page
And I should see "Enrolment methods"
And I log out
Scenario: Student cannot access course and activity administration menus
And I log in as "student1"
And I am on "Course 1" course homepage
And I should not see the page administration menu
And I follow "Choice name"
And I should not see the page administration menu
And I log out
Scenario: Administrator can access site administration menus and sub-menus
And I log in as "admin"
And I should see the page administration menu
And I navigate to "Advanced features" in site administration
And I should see "Enable comments"
And I navigate to "Users > Accounts > Add a new user" in site administration
And I should see "New password"
And I log out
@@ -0,0 +1,32 @@
@core @core_admin @theme_classic
Feature: Select a theme in Classic theme
In order to choose a theme
As an admin
I need to preview the theme and make a selection
Background:
Given I log in as "admin"
And I navigate to "Appearance > Themes" in site administration
@javascript
Scenario: I am able to preview a theme using a modal window
When I click on "Preview theme 'Classic'" "button"
Then I should see "Classic" in the "Classic" "dialogue"
And I should see "Classic is a highly-customisable theme," in the "Classic" "dialogue"
And I should see "Current theme" in the "Classic" "dialogue"
@javascript
Scenario: I am able to change the theme using the modal window select button
Given I should see "Current theme" in the "#theme-card-classic" "css_element"
When I click on "Preview theme 'Boost'" "button"
And I click on "Select theme" "button" in the "Boost" "dialogue"
Then I should see "Current theme" in the "#theme-card-boost" "css_element"
Scenario: I am able to change the theme using the normal select button
Given I should see "Current theme" in the "#theme-card-classic" "css_element"
When I click on "Select theme 'Boost'" "button"
Then I should see "Current theme" in the "#theme-card-boost" "css_element"
Scenario: I am able to view a theme's settings page
Given I click on "Edit theme settings 'Classic'" "link"
Then I should see "Classic"
@@ -0,0 +1,32 @@
@javascript @theme_classic
Feature: Welcome message on classic
To be welcome in moodle
As a User
I need to see a welcome message on the first page
Scenario: Login and be welcomed on the homepage
Given the following config values are set as admin:
| defaulthomepage | 0 |
When I log in as "admin"
Then I should see "Acceptance test site" in the "page-header" "region"
And I should see "Welcome, Admin!" in the "page-header" "region"
And I reload the page
And I should not see "Welcome, Admin!" in the "page-header" "region"
Scenario: Login and be welcomed on the dashboard
Given the following config values are set as admin:
| defaulthomepage | 1 |
When I log in as "admin"
Then I should see "Dashboard" in the "page-header" "region"
And I should see "Welcome, Admin!" in the "page-header" "region"
And I reload the page
And I should not see "Welcome, Admin!" in the "page-header" "region"
Scenario: Login and be welcomed on the my courses page
Given the following config values are set as admin:
| defaulthomepage | 3 |
When I log in as "admin"
Then I should see "My courses" in the "page-header" "region"
And I should see "Welcome, Admin!" in the "page-header" "region"
And I reload the page
And I should not see "Welcome, Admin!" in the "page-header" "region"
+43
View File
@@ -0,0 +1,43 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace theme_classic;
/**
* Unit tests for scss compilation.
*
* @package theme_classic
* @category test
* @copyright 2019 Michael Hawkins
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class scss_test extends \advanced_testcase {
/**
* Test that classic can be compiled using SassC (the defacto implemention).
*/
public function test_scss_compilation_with_sassc(): void {
if (!defined('PHPUNIT_PATH_TO_SASSC')) {
$this->markTestSkipped('Path to SassC not provided');
}
$this->resetAfterTest();
set_config('pathtosassc', PHPUNIT_PATH_TO_SASSC);
$this->assertNotEmpty(
\theme_config::load('classic')->get_css_content_debug('scss', null, null)
);
}
}