Ignore:
Timestamp:
May 2, 2016, 12:09:23 PM (3 years ago)
Author:
jrpelegrina
Message:

Updated to moodle 3.0.3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • moodle/trunk/fuentes/lib/behat/classes/behat_context_helper.php

    r136 r1331  
    1616
    1717/**
    18  * Helper to initialise behat contexts from moodle code.
     18 * Helper to get behat contexts from other contexts.
    1919 *
    2020 * @package    core
     
    2626// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
    2727
    28 use Behat\Mink\Session as Session,
    29     Behat\Mink\Mink as Mink;
     28use \Behat\Behat\Context\BehatContext;
    3029
    3130/**
     
    4039
    4140    /**
    42      * List of already initialized contexts.
    43      *
    44      * @var array
     41     * @var BehatContext main behat context.
    4542     */
    46     protected static $contexts = array();
     43    protected static $maincontext = false;
    4744
    4845    /**
    49      * @var Mink.
    50      */
    51     protected static $mink = false;
    52 
    53     /**
    54      * Sets the browser session.
     46     * Save main behat context reference to be used for finding sub-contexts.
    5547     *
    56      * @param Session $session
     48     * @param BehatContext $maincontext
    5749     * @return void
    5850     */
    59     public static function set_session(Session $session) {
    60 
    61         // Set mink to be able to init a context.
    62         self::$mink = new Mink(array('mink' => $session));
    63         self::$mink->setDefaultSessionName('mink');
     51    public static function set_main_context(BehatContext $maincontext) {
     52        self::$maincontext = $maincontext;
    6453    }
    6554
     
    7766    public static function get($classname) {
    7867
    79         if (!self::init_context($classname)) {
     68        if (!$subcontext = self::$maincontext->getSubcontextByClassName($classname)) {
    8069            throw coding_exception('The required "' . $classname . '" class does not exist');
    8170        }
    8271
    83         return self::$contexts[$classname];
     72        return $subcontext;
    8473    }
    85 
    86     /**
    87      * Initializes the required context.
    88      *
    89      * @throws coding_exception
    90      * @param string $classname
    91      * @return bool
    92      */
    93     protected static function init_context($classname) {
    94 
    95         if (!empty(self::$contexts[$classname])) {
    96             return true;
    97         }
    98 
    99         if (!class_exists($classname)) {
    100             return false;
    101         }
    102 
    103         $instance = new $classname();
    104         $instance->setMink(self::$mink);
    105 
    106         self::$contexts[$classname] = $instance;
    107 
    108         return true;
    109     }
    110 
    11174}
Note: See TracChangeset for help on using the changeset viewer.