本文整理汇总了PHP中behat_context_helper类的典型用法代码示例。如果您正苦于以下问题:PHP behat_context_helper类的具体用法?PHP behat_context_helper怎么用?PHP behat_context_helper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了behat_context_helper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: i_add_a_reviewer_for_workshop_participant
/**
* Manually adds a reviewer for workshop participant.
*
* This step should start on manual allocation page.
*
* @When /^I add a reviewer "(?P<reviewer_name_string>(?:[^"]|\\")*)" for workshop participant "(?P<participant_name_string>(?:[^"]|\\")*)"$/
* @param string $reviewername
* @param string $participantname
*/
public function i_add_a_reviewer_for_workshop_participant($reviewername, $participantname)
{
$participantnameliteral = behat_context_helper::escape($participantname);
$xpathtd = "//table[contains(concat(' ', normalize-space(@class), ' '), ' allocations ')]/" . "tbody/tr[./td[contains(concat(' ', normalize-space(@class), ' '), ' peer ')]" . "[contains(.,{$participantnameliteral})]]/" . "td[contains(concat(' ', normalize-space(@class), ' '), ' reviewedby ')]";
$xpathselect = $xpathtd . "/descendant::select";
try {
$selectnode = $this->find('xpath', $xpathselect);
} catch (Exception $ex) {
$this->find_button(get_string('showallparticipants', 'workshopallocation_manual'))->press();
$selectnode = $this->find('xpath', $xpathselect);
}
$selectformfield = behat_field_manager::get_form_field($selectnode, $this->getSession());
$selectformfield->set_value($reviewername);
if (!$this->running_javascript()) {
// Without Javascript we need to press the "Go" button.
$go = behat_context_helper::escape(get_string('go'));
$this->find('xpath', $xpathtd . "/descendant::input[@value={$go}]")->click();
} else {
// With Javascript we just wait for the page to reload.
$this->getSession()->wait(self::EXTENDED_TIMEOUT, self::PAGE_READY_JS);
}
// Check the success string to appear.
$allocatedtext = behat_context_helper::escape(get_string('allocationadded', 'workshopallocation_manual'));
$this->find('xpath', "//*[contains(.,{$allocatedtext})]");
}
示例2: i_add_user_to_group_members
/**
* Add the specified user to the group. You should be in the groups page when running this step. The user should be specified like "Firstname Lastname (user@example.com)".
*
* @Given /^I add "(?P<user_fullname_string>(?:[^"]|\\")*)" user to "(?P<group_name_string>(?:[^"]|\\")*)" group members$/
* @throws ElementNotFoundException Thrown by behat_base::find
* @param string $username
* @param string $groupname
*/
public function i_add_user_to_group_members($userfullname, $groupname)
{
$userfullname = behat_context_helper::escape($userfullname);
// Using a xpath liternal to avoid problems with quotes and double quotes.
$groupname = behat_context_helper::escape($groupname);
// We don't know the option text as it contains the number of users in the group.
$select = $this->find_field('groups');
$xpath = "//select[@id='groups']/descendant::option[contains(., {$groupname})]";
$groupoption = $this->find('xpath', $xpath);
$fulloption = $groupoption->getText();
$select->selectOption($fulloption);
// This is needed by some drivers to ensure relevant event is triggred and button is enabled.
$script = "Syn.trigger('change', {}, {{ELEMENT}})";
$this->getSession()->getDriver()->triggerSynScript($select->getXpath(), $script);
$this->getSession()->wait(self::TIMEOUT * 1000, self::PAGE_READY_JS);
// Here we don't need to wait for the AJAX response.
$this->find_button(get_string('adduserstogroup', 'group'))->click();
// Wait for add/remove members page to be loaded.
$this->getSession()->wait(self::TIMEOUT * 1000, self::PAGE_READY_JS);
// Getting the option and selecting it.
$select = $this->find_field('addselect');
$xpath = "//select[@id='addselect']/descendant::option[contains(., {$userfullname})]";
$memberoption = $this->find('xpath', $xpath);
$fulloption = $memberoption->getText();
$select->selectOption($fulloption);
// Click add button.
$this->find_button(get_string('add'))->click();
// Wait for the page to load.
$this->getSession()->wait(self::TIMEOUT * 1000, self::PAGE_READY_JS);
// Returning to the main groups page.
$this->find_button(get_string('backtogroups', 'group'))->click();
}
示例3: user_has_not_completed_activity
/**
* Checks that the specified user has not completed the specified activity of the current course.
*
* @Then /^"(?P<user_fullname_string>(?:[^"]|\\")*)" user has not completed "(?P<activity_name_string>(?:[^"]|\\")*)" activity$/
* @param string $userfullname
* @param string $activityname
*/
public function user_has_not_completed_activity($userfullname, $activityname)
{
// Will throw an exception if the element can not be hovered.
$titleliteral = behat_context_helper::escape($userfullname . ", " . $activityname . ": Not completed");
$xpath = "//table[@id='completion-progress']" . "/descendant::img[contains(@title, {$titleliteral})]";
$this->execute("behat_completion::go_to_the_current_course_activity_completion_report");
$this->execute("behat_general::should_exist", array($this->escape($xpath), "xpath_element"));
}
示例4: the_following_instances_exist
/**
* Creates the specified element. More info about available elements in http://docs.moodle.org/dev/Acceptance_testing#Fixtures.
*
* @Given /^the following "(?P<element_string>(?:[^"]|\\")*)" instances exist:$/
*
* This step overrides behat generator step and accepts following parameters to call generator steps for multiple instances.
* - instances : Number of instances to create
* * It replaces #!count!# with the incremental value.
* - refencecont: This is used in case you want a counter to be modulo of some value.
* * It replaces #!count#! with incremental value.
* * #!refcount!# will
* - repeat: This will repeat the table row x times.
* * Replaces #!repeatcount!3 with the repeating value.
*
* @throws Exception
* @throws PendingException
* @param string $elementname The name of the entity to add
* @param TableNode $data
*/
public function the_following_instances_exist($elementname, TableNode $data)
{
$datageneratorcontext = behat_context_helper::get('behat_data_generators');
$datanodes = $this->fix_data_counter($data);
foreach ($datanodes as $datanode) {
generator::dot();
$datageneratorcontext->the_following_exist($elementname, $datanode);
}
}
示例5: i_upload_the_saved_responses_file_to_filemanager
/**
* Upload the responses previously saved above, to a given filepicker.
*
* @param string $fieldlabel the lable of the file manager to upload to.
*
* @Given /^I upload the saved responses file to "([^"]*)" filemanager$/
*/
public function i_upload_the_saved_responses_file_to_filemanager($fieldlabel)
{
$session = $this->getSession();
if ($this->downloadedfile === null) {
throw new ExpectationException('No responses downloaded yet, so we can\'t upload them.', $session);
}
$uploadcontext = behat_context_helper::get('behat_repository_upload');
$uploadcontext->i_upload_file_to_filemanager($this->downloadedfile, $fieldlabel);
}
示例6: i_should_see_question_in_section_in_the_quiz_navigation
public function i_should_see_question_in_section_in_the_quiz_navigation($questionnumber, $sectionheading)
{
// Using xpath literal to avoid quotes problems.
$questionnumberliteral = behat_context_helper::escape('Question ' . $questionnumber);
$headingliteral = behat_context_helper::escape($sectionheading);
// Split in two checkings to give more feedback in case of exception.
$exception = new ExpectationException('Question "' . $questionnumber . '" is not in section "' . $sectionheading . '" in the quiz navigation.', $this->getSession());
$xpath = "//*[@id = 'mod_quiz_navblock']//*[contains(concat(' ', normalize-space(@class), ' '), ' qnbutton ') and " . "contains(., {$questionnumberliteral}) and contains(preceding-sibling::h3[1], {$headingliteral})]";
$this->find('xpath', $xpath);
}
示例7: get_top_navigation_node
protected function get_top_navigation_node($nodetext)
{
// Avoid problems with quotes.
$nodetextliteral = behat_context_helper::escape($nodetext);
$exception = new ExpectationException('Top navigation node "' . $nodetext . ' not found in "', $this->getSession());
// First find in navigation block.
$xpath = "//div[contains(concat(' ', normalize-space(@class), ' '), ' card-text ')]" . "/ul[contains(concat(' ', normalize-space(@class), ' '), ' block_tree ')]" . "/li[contains(concat(' ', normalize-space(@class), ' '), ' contains_branch ')]" . "/ul/li[contains(concat(' ', normalize-space(@class), ' '), ' contains_branch ')]" . "[p[contains(concat(' ', normalize-space(@class), ' '), ' branch ')]" . "/span[normalize-space(.)=" . $nodetextliteral . "]]" . "|" . "//div[contains(concat(' ', normalize-space(@class), ' '), ' card-text ')]/div" . "/ul[contains(concat(' ', normalize-space(@class), ' '), ' block_tree ')]" . "/li[contains(concat(' ', normalize-space(@class), ' '), ' contains_branch ')]" . "/ul/li[contains(concat(' ', normalize-space(@class), ' '), ' contains_branch ')]" . "[p[contains(concat(' ', normalize-space(@class), ' '), ' branch ')]" . "/span[normalize-space(.)=" . $nodetextliteral . "]]" . "|" . "//div[contains(concat(' ', normalize-space(@class), ' '), ' card-text ')]/div" . "/ul[contains(concat(' ', normalize-space(@class), ' '), ' block_tree ')]" . "/li[p[contains(concat(' ', normalize-space(@class), ' '), ' branch ')]" . "/span[normalize-space(.)=" . $nodetextliteral . "]]" . "|" . "//div[contains(concat(' ', normalize-space(@class), ' '), ' card-text ')]/div" . "/ul[contains(concat(' ', normalize-space(@class), ' '), ' block_tree ')]" . "/li[p[contains(concat(' ', normalize-space(@class), ' '), ' branch ')]" . "/a[normalize-space(.)=" . $nodetextliteral . "]]";
$node = $this->find('xpath', $xpath, $exception);
return $node;
}
示例8: i_log_in_as
/**
* Logs in the user. There should exist a user with the same value as username and password.
*
* @Given /^I log in as "(?P<username_string>(?:[^"]|\\")*)"$/
*/
public function i_log_in_as($username)
{
// Visit login page.
$this->getSession()->visit($this->locate_path('login/index.php'));
// Enter username and password.
$behatforms = behat_context_helper::get('behat_forms');
$behatforms->i_set_the_field_to('Username', $this->escape($username));
$behatforms->i_set_the_field_to('Password', $this->escape($username));
// Press log in button.
$behatforms->press_button(get_string('login'));
}
示例9: set_value
/**
* Sets the value(s) of an availability element.
*
* At present this only supports the following value 'Grouping: xxx' where
* xxx is the name of a grouping. Additional value types can be added as
* necessary.
*
* @param string $value Value code
* @return void
*/
public function set_value($value)
{
global $DB;
$driver = $this->session->getDriver();
// Check the availability condition is currently unset - we don't yet
// support changing an existing one.
$existing = $this->get_value();
if ($existing && $existing !== '{"op":"&","c":[],"showc":[]}') {
throw new Exception('Cannot automatically set availability when ' . 'there is existing setting - must clear manually');
}
// Check the value matches a supported format.
$matches = array();
if (!preg_match('~^\\s*([^:]*):\\s*(.*?)\\s*$~', $value, $matches)) {
throw new Exception('Value for availability field does not match correct ' . 'format. Example: "Grouping: G1"');
}
$type = $matches[1];
$param = $matches[2];
if ($this->running_javascript()) {
switch (strtolower($type)) {
case 'grouping':
// Set a grouping condition.
$driver->click('//div[@class="availability-button"]/button');
$driver->click('//button[@id="availability_addrestriction_grouping"]');
$escparam = behat_context_helper::escape($param);
$nodes = $driver->find('//span[contains(concat(" " , @class, " "), " availability_grouping ")]//' . 'option[normalize-space(.) = ' . $escparam . ']');
if (count($nodes) != 1) {
throw new Exception('Cannot find grouping in dropdown' . count($nodes));
}
$node = reset($nodes);
$value = $node->getValue();
$driver->selectOption('//span[contains(concat(" " , @class, " "), " availability_grouping ")]//' . 'select', $value);
break;
default:
// We don't support other types yet. The test author must write
// manual 'click on that button, etc' commands.
throw new Exception('The availability type "' . $type . '" is currently not supported - must set manually');
}
} else {
$courseid = $driver->getValue('//input[@name="course"]');
switch (strtolower($type)) {
case 'grouping':
// Define result with one grouping condition.
$groupingid = $DB->get_field('groupings', 'id', array('courseid' => $courseid, 'name' => $param));
$json = \core_availability\tree::get_root_json(array(\availability_grouping\condition::get_json($groupingid)));
break;
default:
// We don't support other types yet.
throw new Exception('The availability type "' . $type . '" is currently not supported - must set with JavaScript');
}
$driver->setValue('//textarea[@name="availabilityconditionsjson"]', json_encode($json));
}
}
示例10: the_state_of_question_is_shown_as
/**
* Checks the state of the specified question.
*
* @Then /^the state of "(?P<question_description_string>(?:[^"]|\\")*)" question is shown as "(?P<state_string>(?:[^"]|\\")*)"$/
* @throws ExpectationException
* @throws ElementNotFoundException
* @param string $questiondescription
* @param string $state
*/
public function the_state_of_question_is_shown_as($questiondescription, $state)
{
// Using xpath literal to avoid quotes problems.
$questiondescriptionliteral = behat_context_helper::escape($questiondescription);
$stateliteral = behat_context_helper::escape($state);
// Split in two checkings to give more feedback in case of exception.
$exception = new ElementNotFoundException($this->getSession(), 'Question "' . $questiondescription . '" ');
$questionxpath = "//div[contains(concat(' ', normalize-space(@class), ' '), ' que ')]" . "[contains(div[@class='content']/div[contains(concat(' ', normalize-space(@class), ' '), ' formulation ')]," . "{$questiondescriptionliteral})]";
$this->find('xpath', $questionxpath, $exception);
$exception = new ExpectationException('Question "' . $questiondescription . '" state is not "' . $state . '"', $this->getSession());
$xpath = $questionxpath . "/div[@class='info']/div[@class='state' and contains(., {$stateliteral})]";
$this->find('xpath', $xpath, $exception);
}
示例11: i_drag_to_in_the_drag_and_drop_markers_question
/**
* Drag the drag item with the given text to the given space.
*
* @param string $marker the marker to drag. The label, optionally followed by ,<instance number> (int) if relevant.
* @param string $coordinates the position to drag the marker to, 'x,y'.
*
* @Given /^I drag "(?P<marker>[^"]*)" to "(?P<coordinates>\d+,\d+)" in the drag and drop markers question$/
*/
public function i_drag_to_in_the_drag_and_drop_markers_question($marker, $coordinates)
{
list($marker, $item) = $this->parse_marker_name($marker);
list($x, $y) = explode(',', $coordinates);
// This is a bit nasty, but Behat (indeed Selenium) will only drag on
// DOM node so that its centre is over the centre of anothe DOM node.
// Therefore to make it drag to the specified place, we have to add
// a target div.
$session = $this->getSession();
$session->evaluateScript("\n (function() {\n if (document.getElementById('target-{$x}-{$y}')) {\n return;\n }\n var image = document.querySelector('.dropbackground');\n var target = document.createElement('div');\n target.setAttribute('id', 'target-{$x}-{$y}');\n var container = document.querySelector('.droparea');\n container.style.setProperty('position', 'relative');\n container.insertBefore(target, image);\n var xadjusted = {$x} + (container.offsetWidth - image.offsetWidth) / 2;\n var yadjusted = {$y} + (container.offsetHeight - image.offsetHeight) / 2;\n target.style.setProperty('position', 'absolute');\n target.style.setProperty('left', xadjusted + 'px');\n target.style.setProperty('top', yadjusted + 'px');\n target.style.setProperty('width', '1px');\n target.style.setProperty('height', '1px');\n }())");
$generalcontext = behat_context_helper::get('behat_general');
$generalcontext->i_drag_and_i_drop_it_in($this->marker_xpath($marker, $item), 'xpath_element', "#target-{$x}-{$y}", 'css_element');
}
示例12: get_behat_selector
/**
* Returns the behat selector and locator for a given moodle selector and locator
*
* @param string $selectortype The moodle selector type, which includes moodle selectors
* @param string $element The locator we look for in that kind of selector
* @param Session $session The Mink opened session
* @return array Contains the selector and the locator expected by Mink.
*/
public static function get_behat_selector($selectortype, $element, Behat\Mink\Session $session)
{
// CSS and XPath selectors locator is one single argument.
if ($selectortype == 'css_element' || $selectortype == 'xpath_element') {
$selector = str_replace('_element', '', $selectortype);
$locator = $element;
} else {
// Named selectors uses arrays as locators including the type of named selector.
$locator = array($selectortype, behat_context_helper::escape($element));
$selector = 'named_partial';
}
return array($selector, $locator);
}
示例13: i_delete_comment_from_comments_block
/**
* Deletes the specified comment from the current page's comments block.
*
* @Given /^I delete "(?P<comment_text_string>(?:[^"]|\\")*)" comment from comments block$/
* @throws ElementNotFoundException
* @throws ExpectationException
* @param string $comment
*/
public function i_delete_comment_from_comments_block($comment)
{
$exception = new ElementNotFoundException($this->getSession(), '"' . $comment . '" comment ');
// Using xpath liternal to avoid possible problems with comments containing quotes.
$commentliteral = behat_context_helper::escape($comment);
$commentxpath = "//*[contains(concat(' ', normalize-space(@class), ' '), ' block_comments ')]" . "/descendant::div[@class='comment-message'][contains(., {$commentliteral})]";
$commentnode = $this->find('xpath', $commentxpath, $exception);
// Click on delete icon.
$deleteexception = new ExpectationException('"' . $comment . '" comment can not be deleted', $this->getSession());
$deleteicon = $this->find('css', '.comment-delete a img', $deleteexception, $commentnode);
$deleteicon->click();
// Wait for the animation to finish, in theory is just 1 sec, adding 4 just in case.
$this->getSession()->wait(4 * 1000, false);
}
示例14: get_filepicker_node
protected function get_filepicker_node($filepickerelement)
{
// More info about the problem (in case there is a problem).
$exception = new ExpectationException('"' . $filepickerelement . '" filepicker can not be found', $this->getSession());
// If no file picker label is mentioned take the first file picker from the page.
if (empty($filepickerelement)) {
$filepickercontainer = $this->find('xpath', "//*[@data-fieldtype=\"filemanager\"]", $exception);
} else {
// Gets the ffilemanager node specified by the locator which contains the filepicker container.
$filepickerelement = behat_context_helper::escape($filepickerelement);
$filepickercontainer = $this->find('xpath', "//input[./@id = //label[normalize-space(.)={$filepickerelement}]/@for]" . "//ancestor::*[@data-fieldtype = 'filemanager' or @data-fieldtype = 'filepicker']", $exception);
}
return $filepickercontainer;
}
示例15: i_set_the_following_administration_settings_values
public function i_set_the_following_administration_settings_values(TableNode $table)
{
if (!($data = $table->getRowsHash())) {
return;
}
foreach ($data as $label => $value) {
// We expect admin block to be visible, otherwise go to homepage.
if (!$this->getSession()->getPage()->find('css', '.block_settings')) {
$this->getSession()->visit($this->locate_path('/'));
$this->wait(self::TIMEOUT * 1000, self::PAGE_READY_JS);
}
// Search by label.
$searchbox = $this->find_field(get_string('searchinsettings', 'admin'));
$searchbox->setValue($label);
$submitsearch = $this->find('css', 'form.adminsearchform input[type=submit]');
$submitsearch->press();
$this->wait(self::TIMEOUT * 1000, self::PAGE_READY_JS);
// Admin settings does not use the same DOM structure than other moodle forms
// but we also need to use lib/behat/form_field/* to deal with the different moodle form elements.
$exception = new ElementNotFoundException($this->getSession(), '"' . $label . '" administration setting ');
// The argument should be converted to an xpath literal.
$label = behat_context_helper::escape($label);
// Single element settings.
try {
$fieldxpath = "//*[self::input | self::textarea | self::select]" . "[not(./@type = 'submit' or ./@type = 'image' or ./@type = 'hidden')]" . "[@id=//label[contains(normalize-space(.), {$label})]/@for or " . "@id=//span[contains(normalize-space(.), {$label})]/preceding-sibling::label[1]/@for]";
$fieldnode = $this->find('xpath', $fieldxpath, $exception);
$formfieldtypenode = $this->find('xpath', $fieldxpath . "/ancestor::div[contains(concat(' ', @class, ' '), ' form-setting ')]" . "/child::div[contains(concat(' ', @class, ' '), ' form-')]/child::*/parent::div");
} catch (ElementNotFoundException $e) {
// Multi element settings, interacting only the first one.
$fieldxpath = "//*[label[contains(., {$label})]|span[contains(., {$label})]]" . "/ancestor::div[contains(concat(' ', normalize-space(@class), ' '), ' form-item ')]" . "/descendant::div[contains(concat(' ', @class, ' '), ' form-group ')]" . "/descendant::*[self::input | self::textarea | self::select]" . "[not(./@type = 'submit' or ./@type = 'image' or ./@type = 'hidden')]";
$fieldnode = $this->find('xpath', $fieldxpath);
// It is the same one that contains the type.
$formfieldtypenode = $fieldnode;
}
// Getting the class which contains the field type.
$classes = explode(' ', $formfieldtypenode->getAttribute('class'));
$type = false;
foreach ($classes as $class) {
if (substr($class, 0, 5) == 'form-') {
$type = substr($class, 5);
}
}
// Instantiating the appropiate field type.
$field = behat_field_manager::get_field_instance($type, $fieldnode, $this->getSession());
$field->set_value($value);
$this->find_button(get_string('savechanges'))->press();
}
}