2012-11-09 19:16:16 +01:00
|
|
|
<?php
|
|
|
|
|
2017-01-20 03:57:50 +01:00
|
|
|
namespace SilverStripe\Framework\Tests\Behaviour;
|
2012-11-09 19:16:16 +01:00
|
|
|
|
2017-05-11 11:07:27 +02:00
|
|
|
use BadMethodCallException;
|
2017-01-20 03:57:50 +01:00
|
|
|
use Behat\Behat\Context\Context;
|
2016-01-25 16:17:57 +01:00
|
|
|
use Behat\Mink\Exception\ElementHtmlException;
|
|
|
|
use Behat\Gherkin\Node\TableNode;
|
2017-09-12 06:24:34 +02:00
|
|
|
use Behat\Mink\Session;
|
2021-10-27 04:39:47 +02:00
|
|
|
use PHPUnit\Framework\Assert;
|
2017-01-20 03:57:50 +01:00
|
|
|
use SilverStripe\BehatExtension\Context\MainContextAwareTrait;
|
2017-07-28 01:59:24 +02:00
|
|
|
use SilverStripe\BehatExtension\Utility\StepHelper;
|
2013-09-15 01:50:10 +02:00
|
|
|
use Symfony\Component\DomCrawler\Crawler;
|
2016-11-29 13:45:41 +01:00
|
|
|
use Behat\Mink\Element\NodeElement;
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\SiteConfig\SiteConfig;
|
|
|
|
|
2012-11-09 19:16:16 +01:00
|
|
|
/**
|
|
|
|
* CmsFormsContext
|
|
|
|
*
|
|
|
|
* Context used to define steps related to forms inside CMS.
|
|
|
|
*/
|
2017-01-20 03:57:50 +01:00
|
|
|
class CmsFormsContext implements Context
|
2016-12-16 05:34:21 +01:00
|
|
|
{
|
2017-01-20 03:57:50 +01:00
|
|
|
use MainContextAwareTrait;
|
2017-07-28 01:59:24 +02:00
|
|
|
use StepHelper;
|
2012-11-09 19:16:16 +01:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
/**
|
|
|
|
* Get Mink session from MinkContext
|
2017-09-12 06:24:34 +02:00
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @return Session
|
2016-12-16 05:34:21 +01:00
|
|
|
*/
|
|
|
|
public function getSession($name = null)
|
|
|
|
{
|
|
|
|
return $this->getMainContext()->getSession($name);
|
|
|
|
}
|
2012-11-09 19:16:16 +01:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
/**
|
|
|
|
* Returns fixed step argument (with \\" replaced back to ").
|
|
|
|
* Copied from {@see MinkContext}
|
|
|
|
*
|
|
|
|
* @param string $argument
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected function fixStepArgument($argument)
|
|
|
|
{
|
2022-04-14 03:12:59 +02:00
|
|
|
return str_replace('\\"', '"', $argument ?? '');
|
2016-12-16 05:34:21 +01:00
|
|
|
}
|
2014-09-12 05:09:12 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
/**
|
|
|
|
* @Then /^I should( not? |\s*)see an edit page form$/
|
|
|
|
*/
|
|
|
|
public function stepIShouldSeeAnEditPageForm($negative)
|
|
|
|
{
|
|
|
|
$page = $this->getSession()->getPage();
|
2012-11-09 19:16:16 +01:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
$form = $page->find('css', '#Form_EditForm');
|
2022-04-14 03:12:59 +02:00
|
|
|
if (trim($negative ?? '')) {
|
2021-10-27 04:39:47 +02:00
|
|
|
Assert::assertNull($form, 'I should not see an edit page form');
|
2016-12-16 05:34:21 +01:00
|
|
|
} else {
|
2021-10-27 04:39:47 +02:00
|
|
|
Assert::assertNotNull($form, 'I should see an edit page form');
|
2016-12-16 05:34:21 +01:00
|
|
|
}
|
|
|
|
}
|
2014-09-12 05:09:12 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
/**
|
|
|
|
* @When /^I fill in the "(?P<field>(?:[^"]|\\")*)" HTML field with "(?P<value>(?:[^"]|\\")*)"$/
|
|
|
|
* @When /^I fill in "(?P<value>(?:[^"]|\\")*)" for the "(?P<field>(?:[^"]|\\")*)" HTML field$/
|
|
|
|
*/
|
|
|
|
public function stepIFillInTheHtmlFieldWith($field, $value)
|
|
|
|
{
|
|
|
|
$inputField = $this->getHtmlField($field);
|
|
|
|
$value = $this->fixStepArgument($value);
|
|
|
|
|
|
|
|
$this->getSession()->evaluateScript(sprintf(
|
|
|
|
"jQuery('#%s').entwine('ss').getEditor().setContent('%s')",
|
|
|
|
$inputField->getAttribute('id'),
|
2022-04-14 03:12:59 +02:00
|
|
|
addcslashes($value ?? '', "'")
|
2016-12-16 05:34:21 +01:00
|
|
|
));
|
2018-10-11 03:34:18 +02:00
|
|
|
$this->getSession()->evaluateScript(sprintf(
|
|
|
|
"jQuery('#%s').entwine('ss').getEditor().save()",
|
|
|
|
$inputField->getAttribute('id')
|
|
|
|
));
|
2016-12-16 05:34:21 +01:00
|
|
|
}
|
2012-12-10 15:37:00 +01:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
/**
|
|
|
|
* @When /^I append "(?P<value>(?:[^"]|\\")*)" to the "(?P<field>(?:[^"]|\\")*)" HTML field$/
|
|
|
|
*/
|
|
|
|
public function stepIAppendTotheHtmlField($field, $value)
|
|
|
|
{
|
|
|
|
$inputField = $this->getHtmlField($field);
|
|
|
|
$value = $this->fixStepArgument($value);
|
|
|
|
|
|
|
|
$this->getSession()->evaluateScript(sprintf(
|
|
|
|
"jQuery('#%s').entwine('ss').getEditor().insertContent('%s')",
|
|
|
|
$inputField->getAttribute('id'),
|
2022-04-14 03:12:59 +02:00
|
|
|
addcslashes($value ?? '', "'")
|
2016-12-16 05:34:21 +01:00
|
|
|
));
|
|
|
|
}
|
2014-01-06 05:22:40 +01:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
/**
|
|
|
|
* @Then /^the "(?P<locator>(?:[^"]|\\")*)" HTML field should(?P<negative> not? |\s*)contain "(?P<html>.*)"$/
|
|
|
|
*/
|
|
|
|
public function theHtmlFieldShouldContain($locator, $negative, $html)
|
|
|
|
{
|
|
|
|
$element = $this->getHtmlField($locator);
|
|
|
|
$actual = $element->getValue();
|
2022-04-14 03:12:59 +02:00
|
|
|
$regex = '/' . preg_quote($html ?? '', '/') . '/ui';
|
2016-12-16 05:34:21 +01:00
|
|
|
$failed = false;
|
|
|
|
|
2022-04-14 03:12:59 +02:00
|
|
|
if (trim($negative ?? '')) {
|
|
|
|
if (preg_match($regex ?? '', $actual ?? '')) {
|
2016-12-16 05:34:21 +01:00
|
|
|
$failed = true;
|
|
|
|
}
|
|
|
|
} else {
|
2022-04-14 03:12:59 +02:00
|
|
|
if (!preg_match($regex ?? '', $actual ?? '')) {
|
2016-12-16 05:34:21 +01:00
|
|
|
$failed = true;
|
|
|
|
}
|
|
|
|
}
|
2014-01-06 05:22:40 +01:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
if ($failed) {
|
|
|
|
$message = sprintf(
|
|
|
|
'The string "%s" should%sbe found in the HTML of the element matching name "%s". Actual content: "%s"',
|
|
|
|
$html,
|
|
|
|
$negative,
|
|
|
|
$locator,
|
|
|
|
$actual
|
|
|
|
);
|
|
|
|
throw new ElementHtmlException($message, $this->getSession(), $element);
|
|
|
|
}
|
|
|
|
}
|
2013-04-09 09:39:06 +02:00
|
|
|
|
2014-03-30 08:51:38 +02:00
|
|
|
// @codingStandardsIgnoreStart
|
2013-09-15 01:50:10 +02:00
|
|
|
/**
|
|
|
|
* Checks formatting in the HTML field, by analyzing the HTML node surrounding
|
|
|
|
* the text for certain properties.
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2013-09-15 01:50:10 +02:00
|
|
|
* Example: Given "my text" in the "Content" HTML field should be right aligned
|
|
|
|
* Example: Given "my text" in the "Content" HTML field should not be bold
|
|
|
|
*
|
|
|
|
* @todo Use an actual DOM parser for more accurate assertions
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2014-09-12 05:09:12 +02:00
|
|
|
* @Given /^"(?P<text>([^"]*))" in the "(?P<field>(?:[^"]|\\")*)" HTML field should(?P<negate>(?: not)?) be (?P<formatting>(.*))$/
|
2013-09-15 01:50:10 +02:00
|
|
|
*/
|
|
|
|
public function stepContentInHtmlFieldShouldHaveFormatting($text, $field, $negate, $formatting) {
|
2016-11-29 02:49:39 +01:00
|
|
|
$inputField = $this->getHtmlField($field);
|
2013-09-15 01:50:10 +02:00
|
|
|
|
|
|
|
$crawler = new Crawler($inputField->getValue());
|
|
|
|
$matchedNode = null;
|
|
|
|
foreach($crawler->filterXPath('//*') as $node) {
|
|
|
|
if(
|
|
|
|
$node->firstChild
|
|
|
|
&& $node->firstChild->nodeType == XML_TEXT_NODE
|
2022-04-14 03:12:59 +02:00
|
|
|
&& stripos($node->firstChild->nodeValue ?? '', $text ?? '') !== FALSE
|
2013-09-15 01:50:10 +02:00
|
|
|
) {
|
|
|
|
$matchedNode = $node;
|
|
|
|
}
|
|
|
|
}
|
2021-10-27 04:39:47 +02:00
|
|
|
Assert::assertNotNull($matchedNode);
|
|
|
|
|
|
|
|
if ($formatting == 'bold') {
|
|
|
|
if ($negate) {
|
|
|
|
Assert::assertNotEquals('strong', $matchedNode->nodeName);
|
|
|
|
} else {
|
|
|
|
Assert::assertEquals('strong', $matchedNode->nodeName);
|
|
|
|
}
|
|
|
|
} else if ($formatting == 'left aligned') {
|
|
|
|
if ($matchedNode->getAttribute('class')) {
|
|
|
|
if ($negate) {
|
|
|
|
Assert::assertNotEquals('text-left', $matchedNode->getAttribute('class'));
|
|
|
|
} else {
|
|
|
|
Assert::assertEquals('text-left', $matchedNode->getAttribute('class'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if ($formatting == 'right aligned') {
|
|
|
|
if ($negate) {
|
|
|
|
Assert::assertNotEquals('text-right', $matchedNode->getAttribute('class'));
|
|
|
|
} else {
|
|
|
|
Assert::assertEquals('text-right', $matchedNode->getAttribute('class'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// @codingStandardsIgnoreEnd
|
2013-09-15 01:50:10 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
/**
|
|
|
|
* Selects the first textual match in the HTML editor. Does not support
|
|
|
|
* selection across DOM node boundaries.
|
|
|
|
*
|
|
|
|
* @When /^I select "(?P<text>([^"]*))" in the "(?P<field>(?:[^"]|\\")*)" HTML field$/
|
|
|
|
*/
|
|
|
|
public function stepIHighlightTextInHtmlField($text, $field)
|
|
|
|
{
|
|
|
|
$inputField = $this->getHtmlField($field);
|
|
|
|
$inputFieldId = $inputField->getAttribute('id');
|
2022-04-14 03:12:59 +02:00
|
|
|
$text = addcslashes($text ?? '', "'");
|
2013-09-14 18:32:29 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
$js = <<<JS
|
2013-09-14 18:32:29 +02:00
|
|
|
// TODO <IE9 support
|
|
|
|
// TODO Allow text matches across nodes
|
2014-08-15 08:53:05 +02:00
|
|
|
var editor = jQuery('#$inputFieldId').entwine('ss').getEditor(),
|
2016-02-12 04:00:15 +01:00
|
|
|
doc = editor.getInstance().getDoc(),
|
2013-09-14 18:32:29 +02:00
|
|
|
sel = editor.getInstance().selection,
|
|
|
|
rng = document.createRange(),
|
|
|
|
matched = false;
|
2014-02-13 05:36:46 +01:00
|
|
|
|
2017-05-19 00:34:45 +02:00
|
|
|
editor.getInstance().focus();
|
2013-09-14 18:32:29 +02:00
|
|
|
jQuery(doc).find('body *').each(function() {
|
2014-02-13 05:36:46 +01:00
|
|
|
if(!matched) {
|
|
|
|
for(var i=0;i<this.childNodes.length;i++) {
|
|
|
|
if(!matched && this.childNodes[i].nodeValue && this.childNodes[i].nodeValue.match('$text')) {
|
|
|
|
rng.setStart(this.childNodes[i], this.childNodes[i].nodeValue.indexOf('$text'));
|
|
|
|
rng.setEnd(this.childNodes[i], this.childNodes[i].nodeValue.indexOf('$text') + '$text'.length);
|
|
|
|
sel.setRng(rng);
|
|
|
|
editor.getInstance().nodeChanged();
|
|
|
|
matched = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-09-14 18:32:29 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
JS;
|
2014-02-13 05:36:46 +01:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
$this->getSession()->executeScript($js);
|
|
|
|
}
|
2013-09-14 18:32:29 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
/**
|
|
|
|
* @Given /^I should( not? |\s*)see a "([^"]*)" field$/
|
|
|
|
*/
|
|
|
|
public function iShouldSeeAField($negative, $text)
|
|
|
|
{
|
|
|
|
$page = $this->getSession()->getPage();
|
2020-04-20 19:58:09 +02:00
|
|
|
$els = $page->findAll('named', ['field', "'$text'"]);
|
2016-12-16 05:34:21 +01:00
|
|
|
$matchedEl = null;
|
2017-09-12 06:24:34 +02:00
|
|
|
/** @var NodeElement $el */
|
2016-12-16 05:34:21 +01:00
|
|
|
foreach ($els as $el) {
|
|
|
|
if ($el->isVisible()) {
|
|
|
|
$matchedEl = $el;
|
|
|
|
}
|
|
|
|
}
|
2013-12-02 18:35:21 +01:00
|
|
|
|
2022-04-14 03:12:59 +02:00
|
|
|
if (trim($negative ?? '')) {
|
2021-10-27 04:39:47 +02:00
|
|
|
Assert::assertNull($matchedEl);
|
2016-12-16 05:34:21 +01:00
|
|
|
} else {
|
2021-10-27 04:39:47 +02:00
|
|
|
Assert::assertNotNull($matchedEl);
|
2016-12-16 05:34:21 +01:00
|
|
|
}
|
|
|
|
}
|
2013-06-07 05:01:57 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
/**
|
2016-02-12 04:00:15 +01:00
|
|
|
* Click on the element with the provided CSS Selector
|
|
|
|
*
|
|
|
|
* @When /^I press the "([^"]*)" HTML field button$/
|
|
|
|
*/
|
|
|
|
public function iClickOnTheHtmlFieldButton($button)
|
|
|
|
{
|
2017-10-26 23:49:38 +02:00
|
|
|
$xpath = "//*[@aria-label='" . $button . "']";
|
2016-02-12 04:00:15 +01:00
|
|
|
$session = $this->getSession();
|
|
|
|
$element = $session->getPage()->find('xpath', $xpath);
|
|
|
|
if (null === $element) {
|
2018-08-20 21:44:52 +02:00
|
|
|
// If it can't find the exact name, find one that starts with the phrase
|
|
|
|
// Helpful for "Insert link" which has a conditional label for keyboard shortcut
|
2018-08-23 01:07:40 +02:00
|
|
|
$xpath = "//*[starts-with(@aria-label, '" . $button . "')]";
|
2018-08-20 21:44:52 +02:00
|
|
|
$element = $session->getPage()->find('xpath', $xpath);
|
|
|
|
|
|
|
|
if (null === $element) {
|
|
|
|
throw new \InvalidArgumentException(sprintf('Could not find element with xpath %s', $xpath));
|
|
|
|
};
|
2016-02-12 04:00:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$element->click();
|
|
|
|
}
|
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
/*
|
2017-12-14 02:18:41 +01:00
|
|
|
* @example Given the CMS settings has the following data
|
|
|
|
* | Title | My site title |
|
|
|
|
* | Theme | My site theme |
|
|
|
|
* @Given /^the CMS settings have the following data$/
|
|
|
|
*/
|
2016-12-16 05:34:21 +01:00
|
|
|
public function theCmsSettingsHasData(TableNode $fieldsTable)
|
|
|
|
{
|
|
|
|
$fields = $fieldsTable->getRowsHash();
|
|
|
|
$siteConfig = SiteConfig::get()->first();
|
|
|
|
foreach ($fields as $field => $value) {
|
|
|
|
$siteConfig->$field = $value;
|
|
|
|
}
|
|
|
|
$siteConfig->write();
|
|
|
|
$siteConfig->flushCache();
|
|
|
|
}
|
2017-07-28 03:34:49 +02:00
|
|
|
|
2017-07-28 01:59:24 +02:00
|
|
|
/**
|
|
|
|
* Select a value in the tree dropdown field
|
|
|
|
*
|
|
|
|
* NOTE: This is react specific, may need to move to its own react section later
|
|
|
|
*
|
|
|
|
* @When /^I select "([^"]*)" in the "([^"]*)" tree dropdown$/
|
|
|
|
*/
|
|
|
|
public function iSelectValueInTreeDropdown($text, $selector)
|
|
|
|
{
|
|
|
|
$page = $this->getSession()->getPage();
|
2017-09-12 06:24:34 +02:00
|
|
|
/** @var NodeElement $parentElement */
|
2017-07-28 03:34:49 +02:00
|
|
|
$parentElement = null;
|
|
|
|
$this->retryThrowable(function () use (&$parentElement, &$page, $selector) {
|
|
|
|
$parentElement = $page->find('css', $selector);
|
2021-10-27 04:39:47 +02:00
|
|
|
Assert::assertNotNull($parentElement, sprintf('"%s" element not found', $selector));
|
2017-07-28 03:34:49 +02:00
|
|
|
$page = $this->getSession()->getPage();
|
|
|
|
});
|
|
|
|
|
|
|
|
$this->retryThrowable(function () use ($parentElement, $selector) {
|
|
|
|
$dropdown = $parentElement->find('css', '.Select-arrow');
|
2021-10-27 04:39:47 +02:00
|
|
|
Assert::assertNotNull($dropdown, sprintf('Unable to find the dropdown in "%s"', $selector));
|
2017-07-28 03:34:49 +02:00
|
|
|
$dropdown->click();
|
|
|
|
});
|
|
|
|
|
2017-07-28 01:59:24 +02:00
|
|
|
$this->retryThrowable(function () use ($text, $parentElement, $selector) {
|
|
|
|
$element = $parentElement->find('xpath', sprintf('//*[count(*)=0 and contains(.,"%s")]', $text));
|
2021-10-27 04:39:47 +02:00
|
|
|
Assert::assertNotNull($element, sprintf('"%s" not found in "%s"', $text, $selector));
|
2017-07-28 01:59:24 +02:00
|
|
|
$element->click();
|
|
|
|
});
|
|
|
|
}
|
2017-07-28 03:34:49 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
/**
|
|
|
|
* Locate an HTML editor field
|
|
|
|
*
|
|
|
|
* @param string $locator Raw html field identifier as passed from
|
|
|
|
* @return NodeElement
|
|
|
|
*/
|
|
|
|
protected function getHtmlField($locator)
|
|
|
|
{
|
|
|
|
$locator = $this->fixStepArgument($locator);
|
|
|
|
$page = $this->getSession()->getPage();
|
2018-10-08 03:28:10 +02:00
|
|
|
|
|
|
|
// Searching by name is usually good...
|
2016-12-16 05:34:21 +01:00
|
|
|
$element = $page->find('css', 'textarea.htmleditor[name=\'' . $locator . '\']');
|
2018-10-08 03:28:10 +02:00
|
|
|
|
|
|
|
if ($element === null) {
|
|
|
|
$element = $this->findInputByLabelContent($locator);
|
|
|
|
}
|
|
|
|
|
2021-10-27 04:39:47 +02:00
|
|
|
Assert::assertNotNull($element, sprintf('HTML field "%s" not found', $locator));
|
2016-12-16 05:34:21 +01:00
|
|
|
return $element;
|
|
|
|
}
|
2017-05-11 11:07:27 +02:00
|
|
|
|
2018-10-08 03:28:10 +02:00
|
|
|
protected function findInputByLabelContent($locator)
|
|
|
|
{
|
|
|
|
$page = $this->getSession()->getPage();
|
|
|
|
$label = $page->findAll('xpath', sprintf('//label[contains(text(), \'%s\')]', $locator));
|
|
|
|
|
|
|
|
if (empty($label)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-10-27 04:39:47 +02:00
|
|
|
Assert::assertCount(1, $label, sprintf(
|
2018-10-08 03:28:10 +02:00
|
|
|
'Found more than one element containing the phrase "%s".',
|
|
|
|
$locator
|
|
|
|
));
|
|
|
|
|
|
|
|
$label = array_shift($label);
|
|
|
|
|
|
|
|
$fieldId = $label->getAttribute('for');
|
|
|
|
return $page->find('css', '#' . $fieldId);
|
|
|
|
}
|
|
|
|
|
2017-05-11 11:07:27 +02:00
|
|
|
/**
|
|
|
|
* @Given /^the "([^"]*)" field ((?:does not have)|(?:has)) property "([^"]*)"$/
|
|
|
|
*/
|
|
|
|
public function assertTheFieldHasProperty($name, $cond, $property)
|
|
|
|
{
|
|
|
|
$name = $this->fixStepArgument($name);
|
|
|
|
$property = $this->fixStepArgument($property);
|
|
|
|
|
|
|
|
$context = $this->getMainContext();
|
|
|
|
$fieldObj = $context->assertSession()->fieldExists($name);
|
|
|
|
|
|
|
|
// Check property
|
|
|
|
$hasProperty = $fieldObj->hasAttribute($property);
|
|
|
|
switch ($cond) {
|
|
|
|
case 'has':
|
|
|
|
assert($hasProperty, "Field $name does not have property $property");
|
|
|
|
break;
|
|
|
|
case 'does not have':
|
|
|
|
assert(!$hasProperty, "Field $name should not have property $property");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new BadMethodCallException("Invalid condition");
|
|
|
|
}
|
|
|
|
}
|
2017-05-31 07:48:16 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @When /^I switch to the "([^"]*)" iframe$/
|
|
|
|
* @param string $id iframe id property
|
|
|
|
*/
|
|
|
|
public function stepSwitchToTheFrame($id)
|
|
|
|
{
|
|
|
|
$this->getMainContext()->getSession()->getDriver()->switchToIFrame($id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @When /^I am not in an iframe$/
|
|
|
|
*/
|
|
|
|
public function stepSwitchToParentFrame()
|
|
|
|
{
|
|
|
|
$this->getMainContext()->getSession()->getDriver()->switchToIFrame(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @When /^my session expires$/
|
|
|
|
*/
|
|
|
|
public function stepMySessionExpires()
|
|
|
|
{
|
|
|
|
// Destroy cookie to detach session
|
|
|
|
$this->getMainContext()->getSession()->setCookie('PHPSESSID', null);
|
|
|
|
}
|
2017-10-26 23:49:38 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @When /^I should see the "([^"]*)" button in the "([^"]*)" gridfield for the "([^"]*)" row$/
|
|
|
|
* @param string $buttonLabel
|
|
|
|
* @param string $gridFieldName
|
|
|
|
* @param string $rowName
|
|
|
|
*/
|
|
|
|
public function assertIShouldSeeTheGridFieldButtonForRow($buttonLabel, $gridFieldName, $rowName)
|
|
|
|
{
|
|
|
|
$button = $this->getGridFieldButton($gridFieldName, $rowName, $buttonLabel);
|
2021-10-27 04:39:47 +02:00
|
|
|
Assert::assertNotNull($button, sprintf('Button "%s" not found', $buttonLabel));
|
2017-10-26 23:49:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @When /^I should not see the "([^"]*)" button in the "([^"]*)" gridfield for the "([^"]*)" row$/
|
|
|
|
* @param string $buttonLabel
|
|
|
|
* @param string $gridFieldName
|
|
|
|
* @param string $rowName
|
|
|
|
*/
|
|
|
|
public function assertIShouldNotSeeTheGridFieldButtonForRow($buttonLabel, $gridFieldName, $rowName)
|
|
|
|
{
|
|
|
|
$button = $this->getGridFieldButton($gridFieldName, $rowName, $buttonLabel);
|
2021-10-27 04:39:47 +02:00
|
|
|
Assert::assertNull($button, sprintf('Button "%s" found', $buttonLabel));
|
2017-10-26 23:49:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @When /^I click the "([^"]*)" button in the "([^"]*)" gridfield for the "([^"]*)" row$/
|
|
|
|
* @param string $buttonLabel
|
|
|
|
* @param string $gridFieldName
|
|
|
|
* @param string $rowName
|
|
|
|
*/
|
|
|
|
public function stepIClickTheGridFieldButtonForRow($buttonLabel, $gridFieldName, $rowName)
|
|
|
|
{
|
|
|
|
$button = $this->getGridFieldButton($gridFieldName, $rowName, $buttonLabel);
|
2021-10-27 04:39:47 +02:00
|
|
|
Assert::assertNotNull($button, sprintf('Button "%s" not found', $buttonLabel));
|
2017-10-26 23:49:38 +02:00
|
|
|
|
|
|
|
$button->click();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Finds a button in the gridfield row
|
|
|
|
*
|
|
|
|
* @param $gridFieldName
|
|
|
|
* @param $rowName
|
|
|
|
* @param $buttonLabel
|
|
|
|
* @return $button
|
|
|
|
*/
|
|
|
|
protected function getGridFieldButton($gridFieldName, $rowName, $buttonLabel)
|
|
|
|
{
|
|
|
|
$page = $this->getSession()->getPage();
|
|
|
|
$gridField = $page->find('xpath', sprintf('//*[@data-name="%s"]', $gridFieldName));
|
2021-10-27 04:39:47 +02:00
|
|
|
Assert::assertNotNull($gridField, sprintf('Gridfield "%s" not found', $gridFieldName));
|
2017-10-26 23:49:38 +02:00
|
|
|
|
|
|
|
$name = $gridField->find('xpath', sprintf('//*[count(*)=0 and contains(.,"%s")]', $rowName));
|
|
|
|
if (!$name) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-05-29 06:10:52 +02:00
|
|
|
if ($dropdownButton = $name->getParent()->find('css', '.action-menu__toggle')) {
|
|
|
|
$dropdownButton->click();
|
|
|
|
}
|
|
|
|
|
2020-04-20 19:58:09 +02:00
|
|
|
$button = $name->getParent()->find('named', ['link_or_button', $buttonLabel]);
|
2017-10-26 23:49:38 +02:00
|
|
|
|
|
|
|
return $button;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @When /^I click the "([^"]*)" option in the "([^"]*)" listbox$/
|
|
|
|
* @param $optionLabel
|
|
|
|
* @param $fieldName
|
|
|
|
*/
|
|
|
|
public function stepIClickTheListBoxOption($optionLabel, $fieldName)
|
|
|
|
{
|
|
|
|
$page = $this->getSession()->getPage();
|
|
|
|
$listBox = $page->find('xpath', sprintf('//*[@name="%s[]"]', $fieldName));
|
2021-10-27 04:39:47 +02:00
|
|
|
Assert::assertNotNull($listBox, sprintf('The listbox %s is not found', $fieldName));
|
2017-10-26 23:49:38 +02:00
|
|
|
|
|
|
|
$option = $listBox->getParent()
|
|
|
|
->find('css', '.chosen-choices')
|
|
|
|
->find('xpath', sprintf('//*[count(*)=0 and contains(.,"%s")]', $optionLabel));
|
2021-10-27 04:39:47 +02:00
|
|
|
Assert::assertNotNull($option, sprintf('Option %s is not found', $optionLabel));
|
2017-10-26 23:49:38 +02:00
|
|
|
|
|
|
|
$button = $option->getParent()->find('css', 'a');
|
|
|
|
|
|
|
|
$button->click();
|
|
|
|
}
|
2012-11-09 19:16:16 +01:00
|
|
|
}
|