mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Behat: Support for TreeDropdownField
This commit is contained in:
parent
a39adb46db
commit
a9ed6b34cb
@ -6,8 +6,9 @@ use Behat\Behat\Context\ClosuredContextInterface,
|
|||||||
Behat\Behat\Context\TranslatedContextInterface,
|
Behat\Behat\Context\TranslatedContextInterface,
|
||||||
Behat\Behat\Context\BehatContext,
|
Behat\Behat\Context\BehatContext,
|
||||||
Behat\Behat\Context\Step,
|
Behat\Behat\Context\Step,
|
||||||
Behat\Behat\Exception\PendingException;
|
Behat\Behat\Exception\PendingException,
|
||||||
use Behat\Gherkin\Node\PyStringNode,
|
Behat\Mink\Exception\ElementNotFoundException,
|
||||||
|
Behat\Gherkin\Node\PyStringNode,
|
||||||
Behat\Gherkin\Node\TableNode;
|
Behat\Gherkin\Node\TableNode;
|
||||||
|
|
||||||
|
|
||||||
@ -263,7 +264,7 @@ class CmsUiContext extends BehatContext
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Workaround for chosen.js dropdowns which hide the original dropdown field.
|
* Workaround for chosen.js dropdowns or tree dropdowns which hide the original dropdown field.
|
||||||
*
|
*
|
||||||
* @When /^(?:|I )fill in "(?P<field>(?:[^"]|\\")*)" dropdown with "(?P<value>(?:[^"]|\\")*)"$/
|
* @When /^(?:|I )fill in "(?P<field>(?:[^"]|\\")*)" dropdown with "(?P<value>(?:[^"]|\\")*)"$/
|
||||||
* @When /^(?:|I )fill in "(?P<value>(?:[^"]|\\")*)" for "(?P<field>(?:[^"]|\\")*)" dropdown$/
|
* @When /^(?:|I )fill in "(?P<value>(?:[^"]|\\")*)" for "(?P<field>(?:[^"]|\\")*)" dropdown$/
|
||||||
@ -272,32 +273,55 @@ class CmsUiContext extends BehatContext
|
|||||||
{
|
{
|
||||||
$field = $this->fixStepArgument($field);
|
$field = $this->fixStepArgument($field);
|
||||||
$value = $this->fixStepArgument($value);
|
$value = $this->fixStepArgument($value);
|
||||||
|
$nativeField = $this->getSession()->getPage()->findField($field);
|
||||||
$inputField = $this->getSession()->getPage()->findField($field);
|
if($nativeField) {
|
||||||
|
$nativeField->selectOption($value);
|
||||||
|
} else {
|
||||||
|
// TODO Allow searching by label
|
||||||
|
$inputField = $this->getSession()->getPage()->find('xpath', "//*[@name='$field']");
|
||||||
if(null === $inputField) {
|
if(null === $inputField) {
|
||||||
throw new ElementNotFoundException(sprintf(
|
throw new \InvalidArgumentException(sprintf(
|
||||||
'Chosen.js dropdown named "%s" not found',
|
'Chosen.js dropdown named "%s" not found',
|
||||||
$field
|
$field
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
$container = $inputField->getParent()->getParent();
|
do {
|
||||||
if(null === $container) throw new ElementNotFoundException('Chosen.js field container not found');
|
$container = $inputField->getParent();
|
||||||
|
$containerClasses = explode(' ', $container->getAttribute('class'));
|
||||||
|
} while(
|
||||||
|
$container
|
||||||
|
&& in_array('field', $containerClasses)
|
||||||
|
&& $container->getTagName() != 'form'
|
||||||
|
);
|
||||||
|
if(null === $container) throw new \InvalidArgumentException('Chosen.js field container not found');
|
||||||
|
|
||||||
$linkEl = $container->find('xpath', './/a');
|
$triggerEl = $container->find('xpath', './/a');
|
||||||
if(null === $linkEl) throw new ElementNotFoundException('Chosen.js link element not found');
|
if(null === $triggerEl) throw new \InvalidArgumentException('Chosen.js link element not found');
|
||||||
$linkEl->click();
|
$triggerEl->click();
|
||||||
$this->getSession()->wait(100); // wait for dropdown overlay to appear
|
|
||||||
|
if(in_array('treedropdown', $containerClasses)) {
|
||||||
|
// wait for ajax dropdown to load
|
||||||
|
$this->getSession()->wait(
|
||||||
|
5000,
|
||||||
|
"jQuery('#" . $container->getAttribute('id') . " .treedropdownfield-panel li').length > 0"
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// wait for dropdown overlay to appear
|
||||||
|
$this->getSession()->wait(100);
|
||||||
|
}
|
||||||
|
|
||||||
$listEl = $container->find('xpath', sprintf('.//li[contains(normalize-space(string(.)), \'%s\')]', $value));
|
$listEl = $container->find('xpath', sprintf('.//li[contains(normalize-space(string(.)), \'%s\')]', $value));
|
||||||
if(null === $listEl)
|
if(null === $listEl) {
|
||||||
{
|
throw new \InvalidArgumentException(sprintf(
|
||||||
throw new ElementNotFoundException(sprintf(
|
|
||||||
'Chosen.js list element with title "%s" not found',
|
'Chosen.js list element with title "%s" not found',
|
||||||
$value
|
$value
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
$listEl->click();
|
$listEl->find('xpath', './/a')->click();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -49,7 +49,7 @@ Feature: Manage files
|
|||||||
Scenario: I can change the folder of a file
|
Scenario: I can change the folder of a file
|
||||||
Given I click on "folder1" in the "Files" table
|
Given I click on "folder1" in the "Files" table
|
||||||
And I click on "file1" in the "folder1" table
|
And I click on "file1" in the "folder1" table
|
||||||
And I fill in =>Folder.folder2 for "ParentID"
|
And I fill in "folder2" for "ParentID" dropdown
|
||||||
And I press the "Save" button
|
And I press the "Save" button
|
||||||
# /show/0 is to ensure that we are on top level folder
|
# /show/0 is to ensure that we are on top level folder
|
||||||
And I go to "/admin/assets/show/0"
|
And I go to "/admin/assets/show/0"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user