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

Add hasOption method to NodeElement class. #766

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from 4 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
14 changes: 14 additions & 0 deletions src/Element/NodeElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,20 @@ public function selectOption($option, $multiple = false)
$this->getDriver()->selectOption($this->getXpath(), $opt->getValue(), $multiple);
}

/**
aik099 marked this conversation as resolved.
Show resolved Hide resolved
* Returns that the option is in the element or not.
*
* @param string $option
* @return Boolean
*/
public function hasOption($option){
if ('select' !== $this->getTagName()) {
return;
Copy link
Member

Choose a reason for hiding this comment

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

this is wrong. It must return a boolean

Copy link
Author

Choose a reason for hiding this comment

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

I writed this because if the element is not a select tag, It is not logical to return a boolean. That would be nice if I throw an exception instead of return null? Or editing the documentation of method to @return Boolean|null?

Copy link
Member

@aik099 aik099 Oct 22, 2018

Choose a reason for hiding this comment

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

IMO it's better to throw an exception.

}
$optionElement = $this->find('named', array('option', $option));
Copy link
Member

Choose a reason for hiding this comment

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

You can safely inline this variable, because it's used only once.

return $optionElement !== null;
}

/**
* Checks whether current node is selected if it's a option field.
*
Expand Down