From 4beb120f0fa0b5583f2b798210a3d82ded8ab742 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ny=C3=A1rai=20Gerg=C5=91?= Date: Thu, 18 Oct 2018 11:45:08 +0200 Subject: [PATCH 1/7] Add hasOption method to NodeElement class. --- src/Element/NodeElement.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Element/NodeElement.php b/src/Element/NodeElement.php index bbb857332..b7a5c3d85 100644 --- a/src/Element/NodeElement.php +++ b/src/Element/NodeElement.php @@ -237,6 +237,24 @@ public function selectOption($option, $multiple = false) $this->getDriver()->selectOption($this->getXpath(), $opt->getValue(), $multiple); } + /** + * Returns that the element has the find option or not. + * + * @param string $option + * @return Boolean + */ + public function hasOption($option){ + $previousValue=$this->getValue(); + try{ + $this->selectOption($value); + $this->setValue($previousValue); + return true; + } + catch (ElementNotFoundException $e){ + return false; + } + } + /** * Checks whether current node is selected if it's a option field. * From 677797e5b63713023db3d44b5b370f00a41ef2b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ny=C3=A1rai=20Gerg=C5=91?= Date: Thu, 18 Oct 2018 11:53:39 +0200 Subject: [PATCH 2/7] Changed the method description. --- src/Element/NodeElement.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Element/NodeElement.php b/src/Element/NodeElement.php index b7a5c3d85..a1ae1dc37 100644 --- a/src/Element/NodeElement.php +++ b/src/Element/NodeElement.php @@ -238,7 +238,7 @@ public function selectOption($option, $multiple = false) } /** - * Returns that the element has the find option or not. + * Returns that the option is in the element or not. * * @param string $option * @return Boolean From dc687c47a06216ce892c42745290e7f128b832b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ny=C3=A1rai=20Gerg=C5=91?= Date: Thu, 18 Oct 2018 12:15:05 +0200 Subject: [PATCH 3/7] Rewrite hasOption method to don't change value of the select. --- src/Element/NodeElement.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/Element/NodeElement.php b/src/Element/NodeElement.php index a1ae1dc37..6c9883745 100644 --- a/src/Element/NodeElement.php +++ b/src/Element/NodeElement.php @@ -244,15 +244,11 @@ public function selectOption($option, $multiple = false) * @return Boolean */ public function hasOption($option){ - $previousValue=$this->getValue(); - try{ - $this->selectOption($value); - $this->setValue($previousValue); - return true; - } - catch (ElementNotFoundException $e){ - return false; + if ('select' !== $this->getTagName()) { + return; } + $optionElement=$this->find('named', array('option', $option)); + return $optionElement!==null; } /** From 3a74211fb80ff7f32dc24a4cbcaccf1c63309739 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ny=C3=A1rai=20Gerg=C5=91?= Date: Thu, 18 Oct 2018 12:19:27 +0200 Subject: [PATCH 4/7] Fix missing spaces. --- src/Element/NodeElement.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Element/NodeElement.php b/src/Element/NodeElement.php index 6c9883745..c2be2e9d5 100644 --- a/src/Element/NodeElement.php +++ b/src/Element/NodeElement.php @@ -247,8 +247,8 @@ public function hasOption($option){ if ('select' !== $this->getTagName()) { return; } - $optionElement=$this->find('named', array('option', $option)); - return $optionElement!==null; + $optionElement = $this->find('named', array('option', $option)); + return $optionElement !== null; } /** From bf68bef744b6ef0556baa99626fe30226710ca3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ny=C3=A1rai=20Gerg=C5=91?= Date: Thu, 18 Oct 2018 12:24:52 +0200 Subject: [PATCH 5/7] Fixing code style issues. --- src/Element/NodeElement.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Element/NodeElement.php b/src/Element/NodeElement.php index c2be2e9d5..0357d6ef3 100644 --- a/src/Element/NodeElement.php +++ b/src/Element/NodeElement.php @@ -243,11 +243,14 @@ public function selectOption($option, $multiple = false) * @param string $option * @return Boolean */ - public function hasOption($option){ + public function hasOption($option) + { if ('select' !== $this->getTagName()) { return; } + $optionElement = $this->find('named', array('option', $option)); + return $optionElement !== null; } From 7f134a18f23f97ac40329851d1b900d60d1f2490 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ny=C3=A1rai=20Gerg=C5=91?= Date: Thu, 18 Oct 2018 12:44:15 +0200 Subject: [PATCH 6/7] Fix return type in documentation. --- src/Element/NodeElement.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Element/NodeElement.php b/src/Element/NodeElement.php index 0357d6ef3..f88d8c11c 100644 --- a/src/Element/NodeElement.php +++ b/src/Element/NodeElement.php @@ -239,9 +239,9 @@ public function selectOption($option, $multiple = false) /** * Returns that the option is in the element or not. - * + * * @param string $option - * @return Boolean + * @return Boolean|null */ public function hasOption($option) { From 6b3d7fe976e3e6989f45fe6a7c6ebcc233d4e200 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ny=C3=A1rai=20Gerg=C5=91?= Date: Thu, 25 Oct 2018 13:08:49 +0200 Subject: [PATCH 7/7] Throw exception instead of return null. --- src/Element/NodeElement.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Element/NodeElement.php b/src/Element/NodeElement.php index f88d8c11c..e7dffeda3 100644 --- a/src/Element/NodeElement.php +++ b/src/Element/NodeElement.php @@ -241,17 +241,15 @@ public function selectOption($option, $multiple = false) * Returns that the option is in the element or not. * * @param string $option - * @return Boolean|null + * @return Boolean */ public function hasOption($option) { if ('select' !== $this->getTagName()) { - return; + throw new ExpectationException("Element should be a select element.", $this->getDriver()); } - $optionElement = $this->find('named', array('option', $option)); - - return $optionElement !== null; + return $this->find('named', array('option', $option)) !== null; } /**