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.
   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  // NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
  18  // For that reason, we can't even rely on $CFG->admin being available here.
  19  
  20  require_once (__DIR__ . '/../../../../lib/behat/behat_base.php');
  21  
  22  use Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException;
  23  use Behat\Mink\Exception\ExpectationException as ExpectationException;
  24  
  25  /**
  26   * Step definitions related mod_lesson.
  27   *
  28   * @package    mod_lesson
  29   * @category   test
  30   * @copyright  2021 Adrian Greeve <adrian@moodle.com>
  31   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  32   */
  33  class behat_mod_lesson_behat extends behat_base {
  34  
  35      /**
  36       * Select the lesson edit type [Collapsed|Expanded]
  37       *
  38       * @Given i select edit type :edittype
  39       *
  40       * @param  string $edittype The edit type of either Collapsed or Expanded
  41       */
  42      public function i_select_edit_type(string $edittype): void {
  43  
  44          $typestring = ($edittype == 'Collapsed') ? get_string('collapsed', 'mod_lesson') : get_string('full', 'mod_lesson');
  45          try {
  46              $this->execute("behat_forms::i_select_from_the_singleselect", [$typestring, 'jump']);
  47          } catch (ElementNotFoundException $e) {
  48              $this->execute("behat_general::click_link", [$typestring]);
  49          }
  50      }
  51  
  52      /**
  53       * Go to the lesson essay grading page.
  54       *
  55       * @Given i grade lesson essays
  56       */
  57      public function i_grade_lesson_essays(): void {
  58          try {
  59              $this->execute("behat_general::i_click_on", [get_string('manualgrading', 'mod_lesson'), 'button']);
  60          } catch (ElementNotFoundException $e) {
  61              $this->execute("behat_general::click_link", [get_string('manualgrading', 'mod_lesson')]);
  62          }
  63      }
  64  
  65      /**
  66       * Go to the lesson edit page.
  67       *
  68       * @Given i edit the lesson
  69       */
  70      public function i_edit_the_lesson(): void {
  71          try {
  72              $this->execute("behat_general::click_link", [get_string('editlesson', 'mod_lesson')]);
  73          } catch (ElementNotFoundException $e) {
  74              $this->execute("behat_general::i_click_on_in_the",
  75                  [get_string('editlesson', 'mod_lesson'), 'button', 'region-main', 'region']
  76              );
  77          }
  78      }
  79  }