[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/behat/classes/ -> behat_context_helper.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   * Helper to get behat contexts from other contexts.
  19   *
  20   * @package    core
  21   * @category   test
  22   * @copyright  2014 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  use Behat\Testwork\Environment\Environment;
  29  
  30  /**
  31   * Helper to get behat contexts.
  32   *
  33   * @package    core
  34   * @category   test
  35   * @copyright  2014 David Monllaó
  36   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  37   */
  38  class behat_context_helper {
  39  
  40      /**
  41       * Behat environment.
  42       *
  43       * @var Environment
  44       */
  45      protected static $environment = null;
  46  
  47  
  48      /**
  49       * @var Escaper::escapeLiteral
  50       */
  51      protected static $escaper;
  52  
  53      /**
  54       * Sets the browser session.
  55       *
  56       * @param Environment $environment
  57       * @return void
  58       */
  59      public static function set_session(Environment $environment) {
  60          self::$environment = $environment;
  61      }
  62  
  63      /**
  64       * Gets the required context.
  65       *
  66       * Getting a context you get access to all the steps
  67       * that uses direct API calls; steps returning step chains
  68       * can not be executed like this.
  69       *
  70       * @throws coding_exception
  71       * @param string $classname Context identifier (the class name).
  72       * @return behat_base
  73       */
  74      public static function get($classname) {
  75  
  76          if (!$subcontext = self::$environment->getContext($classname)) {
  77              throw coding_exception('The required "' . $classname . '" class does not exist');
  78          }
  79  
  80          return $subcontext;
  81      }
  82  
  83      /**
  84       * Translates string to XPath literal.
  85       *
  86       * @param string $label label to escape
  87       * @return string escaped string.
  88       */
  89      public static function escape($label) {
  90          if (empty(self::$escaper)) {
  91              self::$escaper = new \Behat\Mink\Selector\Xpath\Escaper();
  92          }
  93          return self::$escaper->escapeLiteral($label);
  94      }
  95  }


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