mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
Merge branch 'wip-mdl-50163' of https://github.com/rajeshtaneja/moodle
This commit is contained in:
commit
14248189b7
4 changed files with 25 additions and 50 deletions
|
@ -15,7 +15,7 @@
|
||||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper to initialise behat contexts from moodle code.
|
* Helper to get behat contexts from other contexts.
|
||||||
*
|
*
|
||||||
* @package core
|
* @package core
|
||||||
* @category test
|
* @category test
|
||||||
|
@ -25,8 +25,7 @@
|
||||||
|
|
||||||
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
|
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
|
||||||
|
|
||||||
use Behat\Mink\Session as Session,
|
use \Behat\Behat\Context\BehatContext;
|
||||||
Behat\Mink\Mink as Mink;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper to get behat contexts.
|
* Helper to get behat contexts.
|
||||||
|
@ -39,28 +38,18 @@ use Behat\Mink\Session as Session,
|
||||||
class behat_context_helper {
|
class behat_context_helper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List of already initialized contexts.
|
* @var BehatContext main behat context.
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
*/
|
||||||
protected static $contexts = array();
|
protected static $maincontext = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Mink.
|
* Save main behat context reference to be used for finding sub-contexts.
|
||||||
*/
|
|
||||||
protected static $mink = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the browser session.
|
|
||||||
*
|
*
|
||||||
* @param Session $session
|
* @param BehatContext $maincontext
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function set_session(Session $session) {
|
public static function set_main_context(BehatContext $maincontext) {
|
||||||
|
self::$maincontext = $maincontext;
|
||||||
// Set mink to be able to init a context.
|
|
||||||
self::$mink = new Mink(array('mink' => $session));
|
|
||||||
self::$mink->setDefaultSessionName('mink');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -76,36 +65,10 @@ class behat_context_helper {
|
||||||
*/
|
*/
|
||||||
public static function get($classname) {
|
public static function get($classname) {
|
||||||
|
|
||||||
if (!self::init_context($classname)) {
|
if (!$subcontext = self::$maincontext->getSubcontextByClassName($classname)) {
|
||||||
throw coding_exception('The required "' . $classname . '" class does not exist');
|
throw coding_exception('The required "' . $classname . '" class does not exist');
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::$contexts[$classname];
|
return $subcontext;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes the required context.
|
|
||||||
*
|
|
||||||
* @throws coding_exception
|
|
||||||
* @param string $classname
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
protected static function init_context($classname) {
|
|
||||||
|
|
||||||
if (!empty(self::$contexts[$classname])) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!class_exists($classname)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$instance = new $classname();
|
|
||||||
$instance->setMink(self::$mink);
|
|
||||||
|
|
||||||
self::$contexts[$classname] = $instance;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -256,7 +256,7 @@ class behat_hooks extends behat_base {
|
||||||
// We need the Mink session to do it and we do it only before the first scenario.
|
// We need the Mink session to do it and we do it only before the first scenario.
|
||||||
if (self::is_first_scenario()) {
|
if (self::is_first_scenario()) {
|
||||||
behat_selectors::register_moodle_selectors($session);
|
behat_selectors::register_moodle_selectors($session);
|
||||||
behat_context_helper::set_session($session);
|
behat_context_helper::set_main_context($event->getContext()->getMainContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset mink session between the scenarios.
|
// Reset mink session between the scenarios.
|
||||||
|
@ -384,6 +384,18 @@ class behat_hooks extends behat_base {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executed after scenario having switch window to restart session.
|
||||||
|
* This is needed to close all extra browser windows and starting
|
||||||
|
* one browser window.
|
||||||
|
*
|
||||||
|
* @param ScenarioEvent $event event fired after scenario.
|
||||||
|
* @AfterScenario @_switch_window
|
||||||
|
*/
|
||||||
|
public function after_scenario_switchwindow(ScenarioEvent $event) {
|
||||||
|
$this->getSession()->restart();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Getter for self::$faildumpdirname
|
* Getter for self::$faildumpdirname
|
||||||
*
|
*
|
||||||
|
|
|
@ -4,7 +4,7 @@ Feature: In a book, verify log entries
|
||||||
As an admin
|
As an admin
|
||||||
I need to perform various actions in a book.
|
I need to perform various actions in a book.
|
||||||
|
|
||||||
@javascript
|
@javascript @_switch_window
|
||||||
Scenario: perform various book actions and verify log entries.
|
Scenario: perform various book actions and verify log entries.
|
||||||
Given the following "courses" exist:
|
Given the following "courses" exist:
|
||||||
| fullname | shortname | category | groupmode |
|
| fullname | shortname | category | groupmode |
|
||||||
|
|
|
@ -68,7 +68,7 @@ Feature: Allow students to redo questions in a practice quiz, without starting a
|
||||||
And I click on "Submit all and finish" "button" in the "Confirmation" "dialogue"
|
And I click on "Submit all and finish" "button" in the "Confirmation" "dialogue"
|
||||||
Then "Redo question" "button" should not exist
|
Then "Redo question" "button" should not exist
|
||||||
|
|
||||||
@javascript
|
@javascript @_switch_window
|
||||||
Scenario: Teachers reviewing can see all the qestions attempted in a slot
|
Scenario: Teachers reviewing can see all the qestions attempted in a slot
|
||||||
When I follow "Quiz 1"
|
When I follow "Quiz 1"
|
||||||
And I press "Attempt quiz now"
|
And I press "Attempt quiz now"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue