Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401]

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Behat course-related step definition overrides for the Classic theme.
  19   *
  20   * @package    theme_classic
  21   * @category   test
  22   * @copyright  2019 Michael Hawkins
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  // NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
  27  
  28  require_once (__DIR__ . '/../../../../course/tests/behat/behat_course.php');
  29  
  30  /**
  31   * Course-related step definition overrides for the Classic theme.
  32   *
  33   * @package    theme_classic
  34   * @category   test
  35   * @copyright  2019 Michael Hawkins
  36   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  37   */
  38  class behat_theme_classic_behat_course extends behat_course {
  39  
  40      /**
  41       * Go to the course participants.
  42       */
  43      public function i_navigate_to_course_participants() {
  44          $coursestr = behat_context_helper::escape(get_string('courses'));
  45          $mycoursestr = behat_context_helper::escape(get_string('mycourses'));
  46          $xpath = "//div[contains(@class,'block')]//li[contains(@class,'contains_branch')]" .
  47              "[p/*[string(.)=$coursestr or string(.)=$mycoursestr]]";
  48          $this->execute('behat_general::i_click_on_in_the', [get_string('participants'), 'link', $xpath, 'xpath_element']);
  49      }
  50  
  51      /**
  52       * Returns whether the user has permission to modify this course.
  53       *
  54       * @return bool
  55       */
  56      protected function is_course_editor(): bool {
  57          // If the course is already in editing mode then it will have the class 'editing' on the body.
  58          // This is a 'cheap' way of telling if the course is in editing mode.
  59          $body = $this->find('css', 'body');
  60          if ($body->hasClass('editing')) {
  61              return true;
  62          }
  63  
  64          // If the course is not already in editing mode, then the only real way to find out if the current user may edit
  65          // the page is to look for the "Turn editing on" button.
  66          // If the button is found then the user is a course editor.
  67          try {
  68              $this->find('button', get_string('turneditingon'), false, false, 0);
  69              return true;
  70          } catch (Exception $e) {
  71              return false;
  72          }
  73      }
  74  }