本文整理汇总了PHP中Behat\Mink\Element\NodeElement::getText方法的典型用法代码示例。如果您正苦于以下问题:PHP NodeElement::getText方法的具体用法?PHP NodeElement::getText怎么用?PHP NodeElement::getText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Behat\Mink\Element\NodeElement
的用法示例。
在下文中一共展示了NodeElement::getText方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetText
public function testGetText()
{
$expected = 'val1';
$node = new NodeElement('text_tag', $this->session);
$this->driver->expects($this->once())->method('getText')->with('text_tag')->will($this->returnValue($expected));
$this->assertEquals($expected, $node->getText());
}
示例2: assertNodeElementContainsText
/**
* Check if the given node has the given text.
*
* @param NodeElement $element
* @param string $text
*
* @throws \PHPUnit_Framework_AssertionFailedError
*/
private function assertNodeElementContainsText(NodeElement $element, $text)
{
$actual = $element->getText();
$regex = '/' . preg_quote($text, '/') . '/ui';
$message = sprintf('The text "%s" was not found in the text of the %s.', $text, $actual);
PHPUnit::assertTrue((bool) preg_match($regex, $actual), $message);
}
示例3: deleteComment
/**
* @param NodeElement $comment
*
* @throws \LogicException
*/
public function deleteComment(NodeElement $comment)
{
$link = $comment->find('css', 'span.remove-comment');
if (null === $link) {
throw new \LogicException(sprintf('Delete link of comment "%s" not found.', $comment->getText()));
}
$link->click();
}
示例4: getComment
/**
* @param NodeElement $element
* @return string
*/
protected function getComment(NodeElement $element)
{
return $element->getText();
}
示例5: fillMultiSelect2Field
/**
* Fills a multivalues Select2 field with $value, identified by its $label.
* It deletes existing selected values from field if not present in $value.
*
* $value can be a string of multiple values. Each value must be separated with comma, eg :
* 'Hot, Dry, Fresh'
*
* @param NodeElement $label
* @param string $value
*
* @throws \InvalidArgumentException
*/
protected function fillMultiSelect2Field(NodeElement $label, $value)
{
$allValues = explode(',', $value);
$selectedValues = $label->getParent()->findAll('css', '.select2-search-choice');
$selectedTextValues = array_map(function ($selectedValue) {
return $selectedValue->getText();
}, $selectedValues);
// Delete tag from right to left to prevent select2 DOM change
$selectedValues = array_reverse($selectedValues);
foreach ($selectedValues as $selectedValue) {
if (false === in_array($selectedValue->getText(), $allValues)) {
$closeButton = $selectedValue->find('css', 'a');
if (!$closeButton) {
throw new \InvalidArgumentException(sprintf('Could not find "%s" close button for "%s"', trim($selectedValue->getText()), $label->getText()));
}
$closeButton->click();
}
}
$allValues = array_filter($allValues);
if (1 === count($allValues) && null !== $label->getParent()->find('css', 'select')) {
$value = array_shift($allValues);
$this->fillSelectField($label, $value);
}
// Fill in remaining values
$remainingValues = array_diff($allValues, $selectedTextValues);
foreach ($remainingValues as $value) {
if (trim($value)) {
$label->click();
$label->click();
$option = $this->spin(function () use($value) {
return $this->find('css', sprintf('.select2-result:not(.select2-selected) .select2-result-label:contains("%s")', trim($value)));
}, sprintf('Could not find option "%s" for "%s"', trim($value), $label->getText()));
$option->click();
}
}
}
示例6: fillMultiSelect2Field
/**
* Fills a multivalues Select2 field with $value, identified by its $label.
* It deletes existing selected values from field if not present in $value.
*
* $value can be a string of multiple values. Each value must be separated with comma, eg :
* 'Hot, Dry, Fresh'
*
* @param NodeElement $label
* @param string $value
*
* @throws \InvalidArgumentException
*/
protected function fillMultiSelect2Field(NodeElement $label, $value)
{
$allValues = explode(',', $value);
$selectedValues = $label->getParent()->findAll('css', '.select2-search-choice');
$selectedTextValues = array_map(function ($selectedValue) {
return $selectedValue->getText();
}, $selectedValues);
// Delete tag from right to left to prevent select2 DOM change
$selectedValues = array_reverse($selectedValues);
foreach ($selectedValues as $selectedValue) {
if (false === in_array($selectedValue->getText(), $allValues)) {
$closeButton = $selectedValue->find('css', 'a');
if (!$closeButton) {
throw new \InvalidArgumentException(sprintf('Could not find "%s" close button for "%s"', trim($selectedValue->getText()), $label->getText()));
}
$closeButton->click();
}
}
// Removing tags in MultiSelect2 drops an "animation" with opacity, we must
// wait for it to completly vanish in order to reopen select list
$this->getSession()->wait(2000);
$allValues = array_filter($allValues);
if (1 === count($allValues) && null !== $label->getParent()->find('css', 'select')) {
$value = array_shift($allValues);
$this->fillSelectField($label, $value);
}
// Fill in remaining values
$remainingValues = array_diff($allValues, $selectedTextValues);
foreach ($remainingValues as $value) {
if (trim($value)) {
$label->getParent()->find('css', 'input[type="text"]')->click();
$this->getSession()->wait(100000, "\$('div:contains(\"Searching\")').length == 0");
$option = $this->find('css', sprintf('.select2-result:not(.select2-selected) .select2-result-label:contains("%s")', trim($value)));
if (!$option) {
throw new \InvalidArgumentException(sprintf('Could not find option "%s" for "%s"', trim($value), $label->getText()));
}
$option->click();
}
}
}
示例7: fillTextField
/**
* Fills a text field element with $value, identified by its container or label.
*
* @param NodeElement $fieldContainerOrLabel
* @param string $value
*
* @throws ElementNotFoundException
*/
protected function fillTextField(NodeElement $fieldContainerOrLabel, $value)
{
$field = $fieldContainerOrLabel->find('css', 'div.field-input input');
// no field found, we're using a label
if (!$field) {
$field = $fieldContainerOrLabel->getParent()->getParent()->find('css', 'div.field-input input');
}
if (!$field) {
$field = $fieldContainerOrLabel->getParent()->find('css', 'div.controls input');
}
if (null === $field) {
throw new ElementNotFoundException(sprintf('No text field can be found from "%s".', $fieldContainerOrLabel->getText()));
}
$field->setValue($value);
$this->getSession()->executeScript('$(\'.field-input input[type="text"]\').trigger(\'change\');');
}
示例8: getAttributesFromElement
private function getAttributesFromElement(NodeElement $element)
{
$attr = array();
$attr['id'] = strtolower($element->getAttribute('id'));
$attr['name'] = strtolower($element->getAttribute('name'));
$attr['label'] = strtolower($element->getAttribute('label'));
$attr['value'] = strtolower($element->getAttribute('value'));
$attr['text'] = strtolower($element->getText());
$attr['title'] = strtolower($element->getAttribute('title'));
return $attr;
}