Skip to content
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

[5.2] Fix seeIsSelected for <option> tags without value attribute #14279

Merged
merged 4 commits into from
Jul 12, 2016
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/Illuminate/Foundation/Testing/Constraints/IsSelected.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,31 @@ protected function getSelectedValueFromSelect(Crawler $select)
if ($option->nodeName === 'optgroup') {
foreach ($option->childNodes as $child) {
if ($child->hasAttribute('selected')) {
$selected[] = $child->getAttribute('value');
$selected[] = $this->getOptionValue($child);
}
}
} elseif ($option->hasAttribute('selected')) {
$selected[] = $option->getAttribute('value');
$selected[] = $this->getOptionValue($option);
}
}

return $selected;
}

/**
* Get the selected value from an option element.
*
* @param \DOMElement $option
* @return string
*/
protected function getOptionValue(\DOMElement $option)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please import this.

{
if($option->hasAttribute('value')){
return $option->getAttribute('value');
}
return $option->textContent;
}

/**
* Get the checked value from a radio group.
*
Expand Down
22 changes: 22 additions & 0 deletions tests/Foundation/FoundationInteractsWithPagesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,28 @@ public function testDontSeeOptionIsSelected()
$this->dontSeeIsSelected('availability', 'partial_time');
}

protected function getSelectHtmlWithoutValueAttribute()
{
return
'<select name="size">
<option>S</option>
<option selected>M</option>
<option>L</option>
</select>';
}

public function testSeeOptionWithoutValueIsSelected()
{
$this->setCrawler($this->getSelectHtmlWithoutValueAttribute());
$this->seeIsSelected('size', 'M');
}

public function testDontSeeOptionWithoutValueIsSelected()
{
$this->setCrawler($this->getSelectHtmlWithoutValueAttribute());
$this->dontSeeIsSelected('size', 'S');
}

protected function getEmptySelectHtml()
{
return
Expand Down