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.

Differences Between: [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403]

   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   * Steps definitions for choice activity.
  19   *
  20   * @package   mod_choice
  21   * @category  test
  22   * @copyright 2013 David MonllaĆ³
  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__ . '/../../../../lib/behat/behat_base.php');
  29  
  30  /**
  31   * Choice activity definitions.
  32   *
  33   * @package   mod_choice
  34   * @category  test
  35   * @copyright 2013 David MonllaĆ³
  36   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  37   */
  38  class behat_mod_choice extends behat_base {
  39  
  40      /**
  41       * Chooses the specified option from the choice activity named as specified. You should be located in the activity's course page.
  42       *
  43       * @Given /^I choose "(?P<option_string>(?:[^"]|\\")*)" from "(?P<choice_activity_string>(?:[^"]|\\")*)" choice activity$/
  44       * @param string $option
  45       * @param string $choiceactivity
  46       * @return array
  47       */
  48      public function I_choose_option_from_activity($option, $choiceactivity) {
  49          $this->execute("behat_navigation::i_am_on_page_instance", [$this->escape($choiceactivity), 'choice activity']);
  50  
  51          $this->execute('behat_forms::i_set_the_field_to', array( $this->escape($option), 1));
  52  
  53          $this->execute("behat_forms::press_button", get_string('savemychoice', 'choice'));
  54      }
  55  
  56      /**
  57       * Chooses the specified option from the choice activity named as specified and save the choice.
  58       * You should be located in the activity's course page.
  59       *
  60       * @Given /^I choose options (?P<option_string>"(?:[^"]|\\")*"(?:,"(?:[^"]|\\")*")*) from "(?P<choice_activity_string>(?:[^"]|\\")*)" choice activity$/
  61       * @param string $option
  62       * @param string $choiceactivity
  63       * @return array
  64       */
  65      public function I_choose_options_from_activity($option, $choiceactivity) {
  66          // Get Behat general and forms contexts.
  67          $behatgeneral = behat_context_helper::get('behat_general');
  68          $behatforms = behat_context_helper::get('behat_forms');
  69  
  70          // Go to choice activity.
  71          $this->execute("behat_navigation::i_am_on_page_instance", [$this->escape($choiceactivity), 'choice activity']);
  72  
  73          // Wait for page to be loaded.
  74          $this->wait_for_pending_js();
  75  
  76          // Set all options.
  77          $options = explode('","', trim($option, '"'));
  78          foreach ($options as $option) {
  79              $behatforms->i_set_the_field_to($this->escape($option), '1');
  80          }
  81  
  82          // Save choice.
  83          $behatforms->press_button(get_string('savemychoice', 'choice'));
  84      }
  85  
  86  }