[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/mod/choice/tests/behat/ -> behat_mod_choice.php (source)

   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  
  50          $this->execute("behat_general::click_link", $this->escape($choiceactivity));
  51  
  52          $this->execute('behat_forms::i_set_the_field_to', array( $this->escape($option), 1));
  53  
  54          $this->execute("behat_forms::press_button", get_string('savemychoice', 'choice'));
  55      }
  56  
  57      /**
  58       * Chooses the specified option from the choice activity named as specified and save the choice.
  59       * You should be located in the activity's course page.
  60       *
  61       * @Given /^I choose options (?P<option_string>"(?:[^"]|\\")*"(?:,"(?:[^"]|\\")*")*) from "(?P<choice_activity_string>(?:[^"]|\\")*)" choice activity$/
  62       * @param string $option
  63       * @param string $choiceactivity
  64       * @return array
  65       */
  66      public function I_choose_options_from_activity($option, $choiceactivity) {
  67          // Get Behat general and forms contexts.
  68          $behatgeneral = behat_context_helper::get('behat_general');
  69          $behatforms = behat_context_helper::get('behat_forms');
  70  
  71          // Go to choice activity.
  72          $behatgeneral->click_link($this->escape($choiceactivity));
  73  
  74          // Wait for page to be loaded.
  75          $this->wait_for_pending_js();
  76  
  77          // Set all options.
  78          $options = explode('","', trim($option, '"'));
  79          foreach ($options as $option) {
  80              $behatforms->i_set_the_field_to($this->escape($option), '1');
  81          }
  82  
  83          // Save choice.
  84          $behatforms->press_button(get_string('savemychoice', 'choice'));
  85      }
  86  
  87  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1