. /** * Helper to get behat contexts from other contexts. * * @package core * @category test * @copyright 2014 David Monllaó * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ // NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php. use Behat\Testwork\Environment\Environment; /** * Helper to get behat contexts. * * @package core * @category test * @copyright 2014 David Monllaó * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class behat_context_helper { /** * Behat environment. * * @var Environment */ protected static $environment = null; /** * @var Escaper::escapeLiteral */ protected static $escaper; /** * Sets the browser session. * * @param Environment $environment * @return void */ public static function set_session(Environment $environment) { self::$environment = $environment; } /** * Gets the required context. * * Getting a context you get access to all the steps * that uses direct API calls; steps returning step chains * can not be executed like this. * * @throws coding_exception * @param string $classname Context identifier (the class name). * @return behat_base */ public static function get($classname) { if (!$subcontext = self::$environment->getContext($classname)) { throw coding_exception('The required "' . $classname . '" class does not exist'); } return $subcontext; } /** * Translates string to XPath literal. * * @param string $label label to escape * @return string escaped string. */ public static function escape($label) { if (empty(self::$escaper)) { self::$escaper = new \Behat\Mink\Selector\Xpath\Escaper(); } return self::$escaper->escapeLiteral($label); } }