-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EWPP-258: Create Behat test for testing "API steps" #315
base: master
Are you sure you want to change the base?
Changes from all commits
016dcb5
315e7f0
0a58740
6b7c230
3bc9040
d3a097c
7f5ccfa
555e019
9f0d228
81ec44a
5489f27
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,13 +119,74 @@ public function fillDateRangeSelectListField(string $field_item, string $field_g | |
} | ||
|
||
/** | ||
* Set the date and time value of a date list widget. | ||
* Check values for list date range fields. | ||
* | ||
* When I set "Field" to the date "22-02-2019" | ||
* When I set "Field" to the date "22-02-2019 14:30" using format "d-m-Y H:i" | ||
* Then datetime "15 1 2020 12 30" is selected for "Start date" of "Datetime" | ||
* | ||
* @param string $value | ||
* The value of the field. | ||
* @param string $field_item | ||
* The date field item inside the field component. | ||
* @param string $field_group | ||
* The field component's label. | ||
* | ||
* @Then datetime :value is selected for :field_item of :field_group | ||
* @Then date :value is selected for :field_item of :field_group | ||
*/ | ||
public function isSelectedForOf($value, $field_item, $field_group): void { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Type hinting are missing. Also in the other methods. |
||
$page = $this->getSession()->getPage(); | ||
$values = explode(' ', $value); | ||
$group = $page->find('named', ['fieldset', $field_group]); | ||
$elements = $group->findAll('css', '.container-inline'); | ||
|
||
if (empty($elements)) { | ||
throw new \Exception('Datetime fields not found.'); | ||
} | ||
|
||
$fields = $elements[0]; | ||
|
||
if ($field_item === 'End date') { | ||
$fields = $elements[1]; | ||
} | ||
|
||
$date_components = [ | ||
'Day', | ||
'Month', | ||
'Year', | ||
]; | ||
|
||
if (count($values) > 3) { | ||
$date_components += [ | ||
'Hour', | ||
'Minute', | ||
]; | ||
} | ||
|
||
foreach ($date_components as $index => $date_component) { | ||
$field = $fields->findField($date_component); | ||
$optionField = $field->find('named', [ | ||
'option', | ||
$values[$index], | ||
]); | ||
|
||
if ($optionField === NULL) { | ||
throw new \Exception(sprintf('%s option not found.', $date_component)); | ||
} | ||
|
||
if (!$optionField->isSelected()) { | ||
throw new \Exception(sprintf('%s not selected for %s option.', $values[$index], $date_component)); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Finds a datetime field. | ||
* | ||
* @param string $field | ||
* The label of the field. | ||
* The field name. | ||
* When I set "Field" to the date "22-02-2019". | ||
* When I set "Field" to the date "22-02-2019 14:30" using | ||
* format "d-m-Y H:i". | ||
* @param string $value | ||
* The value of the field. | ||
* @param string $format | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -187,6 +187,83 @@ protected function getLangcodeByName(string $language_name): string { | |
throw new \Exception("Language name '$language_name' is not valid."); | ||
} | ||
|
||
/** | ||
* Visit a edit page by node title. | ||
* | ||
* @When I visit node :arg1 edit page | ||
*/ | ||
public function iVisitNodeEditPage($arg1) { | ||
$node = $this->getNodeByTitle($arg1); | ||
$this->visitPath("/node/{$node->id()}/edit"); | ||
} | ||
|
||
/** | ||
* Checks, that form field has specified value. | ||
* | ||
* @Then the :field field contains :value | ||
*/ | ||
public function theFieldContains($field, $value) { | ||
$node = $this->getSession()->getPage()->findField($field); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need to first assert that the field exists, before trying to access its value. You can use assert session for this. |
||
$actual = $node->getValue(); | ||
|
||
if (strpos($actual, $value) === FALSE) { | ||
throw new \Exception(sprintf('Field %s does not contain %s.', $field, $value)); | ||
} | ||
} | ||
|
||
/** | ||
* Attempts to find a button in a table row containing giving text. | ||
* | ||
* @When I press :button in the :rowText row | ||
*/ | ||
public function iPressInTheRow($button, $rowText) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing type hints and code sniffing shouldn't have passed here, as camel case is not allowed for method parameters. Check if that actually runs on these classes too. |
||
$page = $this->getSession()->getPage(); | ||
$rows = $page->findAll('css', 'tr'); | ||
|
||
if (empty($rows)) { | ||
throw new \Exception(sprintf('No rows found on the page %s', $this->getSession()->getCurrentUrl())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use assert sessions to check presence of elements. |
||
} | ||
|
||
/** @var \Behat\Mink\Element\NodeElement $row */ | ||
foreach ($rows as $row) { | ||
if (strpos($row->getText(), $rowText) !== FALSE) { | ||
break; | ||
} | ||
} | ||
|
||
if ($row === NULL) { | ||
throw new \Exception(sprintf('Row "%s" not found', $rowText)); | ||
} | ||
|
||
$button_element = $row->findButton($button); | ||
|
||
if ($button_element === NULL) { | ||
throw new \Exception(sprintf('Button "%s" not found in row %s', $button, $rowText)); | ||
} | ||
|
||
$button_element->press(); | ||
} | ||
|
||
/** | ||
* Assert option is selected. | ||
* | ||
* @When :option should be selected for :field select | ||
*/ | ||
public function shouldBeSelectedForSelect($option, $field) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IF we wont use this let's remove it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I use this method in the refactored Behat statements There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't we have this already from the Drupal extension? |
||
if (!$element = $this->getSession()->getPage()->findField($field)) { | ||
throw new \Exception(sprintf('Field %s not found.', $field)); | ||
} | ||
|
||
$selected_option = $element->find('css', "option[selected='selected']"); | ||
|
||
if ($selected_option === NULL) { | ||
print_r($element->getHtml()); | ||
throw new \Exception(sprintf('Option "%s" not selected for %s select', $option, $field)); | ||
} | ||
|
||
Assert::assertTrue($selected_option->getValue() === $option); | ||
} | ||
|
||
/** | ||
* Step to fill in multi value fields with columns. | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep the previous format. Also avoid passive forms as much as possible: