Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.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  /**
  18   * User tour related steps definitions.
  19   *
  20   * @package    tool_usertours
  21   * @category   test
  22   * @copyright  2016 Andrew Nicols <andrew@nicols.co.uk>
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  require_once (__DIR__ . '/../../../../../lib/behat/behat_base.php');
  27  
  28  use Behat\Gherkin\Node\TableNode as TableNode;
  29  /**
  30   * User tour related steps definitions.
  31   *
  32   * @package    tool_usertours
  33   * @category   test
  34   * @copyright  2016 Andrew Nicols <andrew@nicols.co.uk>
  35   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  36   */
  37  class behat_tool_usertours extends behat_base {
  38  
  39      /**
  40       * Add a new user tour.
  41       *
  42       * @Given /^I add a new user tour with:$/
  43       * @param TableNode $table
  44       */
  45      public function i_add_a_new_user_tour_with(TableNode $table) {
  46          $this->execute('behat_tool_usertours::i_open_the_user_tour_settings_page');
  47          $this->execute('behat_general::click_link', get_string('newtour', 'tool_usertours'));
  48  
  49          // Fill form and post.
  50          $this->execute('behat_forms::i_set_the_following_fields_to_these_values', $table);
  51          $this->execute('behat_forms::press_button', get_string('savechanges', 'moodle'));
  52          $this->execute('behat_general::i_wait_to_be_redirected');
  53      }
  54  
  55      /**
  56       * Add new steps to a user tour.
  57       *
  58       * @Given /^I add steps to the "(?P<tour_name_string>(?:[^"]|\\")*)" tour:$/
  59       * @param   string      $tourname   The name of the tour to add steps to.
  60       * @param   TableNode   $table
  61       */
  62      public function i_add_steps_to_the_named_tour($tourname, TableNode $table) {
  63          $this->execute('behat_tool_usertours::i_open_the_user_tour_settings_page');
  64          $this->execute('behat_general::click_link', $this->escape($tourname));
  65          $this->execute('behat_tool_usertours::i_add_steps_to_the_tour', $table);
  66      }
  67  
  68      /**
  69       * Add new steps to the current user tour.
  70       *
  71       * @Given /^I add steps to the tour:$/
  72       * @param   TableNode   $table
  73       */
  74      public function i_add_steps_to_the_tour(TableNode $table) {
  75          foreach ($table->getHash() as $step) {
  76              $this->execute('behat_general::click_link', get_string('newstep', 'tool_usertours'));
  77  
  78              foreach ($step as $locator => $value) {
  79                  $this->execute('behat_forms::i_set_the_field_to', [$this->escape($locator), $this->escape($value)]);
  80              }
  81  
  82              $this->execute('behat_forms::press_button', get_string('savechanges', 'moodle'));
  83              $this->execute('behat_general::i_wait_to_be_redirected');
  84          }
  85      }
  86  
  87      /**
  88       * Navigate to the user tour settings page.
  89       *
  90       * @Given /^I open the User tour settings page$/
  91       */
  92      public function i_open_the_user_tour_settings_page() {
  93          $this->execute('behat_navigation::i_navigate_to_in_site_administration',
  94                  get_string('appearance', 'admin') . ' > ' .
  95                  get_string('usertours', 'tool_usertours')
  96          );
  97      }
  98  }