diff --git a/tests/features/bootstrap/FeatureContext.php b/tests/features/bootstrap/FeatureContext.php index 0ae4939..01a6527 100644 --- a/tests/features/bootstrap/FeatureContext.php +++ b/tests/features/bootstrap/FeatureContext.php @@ -140,22 +140,30 @@ public function iAmOnTheNewArticlePage() { } /** - * @Then the article with the title :title and date :date should be listed + * @Then a notification should be displayed with the text :notification */ - public function theArticleShouldBeListed($title,$date) + public function aNotificationShouldBeDisplayedWithTheText($notification) { - $titleElement = $this->getSession()->getPage()->find('xpath', '//tr/td[2][text()[normalize-space()="'.$title.'"]]'); - $dateElement = $this->getSession()->getPage()->find('xpath','//tr/td[1][text()[normalize-space()="'.$date.'"]]'); - if($dateElement === NULL || trim($dateElement->getHtml()) !== $date) - { - throw new \Exception("Expected article with date does not exist"); - } - if ($titleElement === NULL || trim($titleElement->getHtml() ) !== $title) - { - throw new \Exception("Expected article with title does not exist"); - } + $realNotification = $this->getSession()->getPage()->find('xpath', '//div[@class="statusMessage"]'); + if ($realNotification->getHtml()!=$notification) { + throw new \Exception("notification does not match the expected"); + } } - + + /** + * @Then the article with the title :title and date :date should be listed + */ + public function theArticleShouldBeListed($title, $date) { + $titleElement = $this->adminPage->getTitle ($title); + $dateElement = $this->adminPage->getDate ($date); + if ($dateElement === NULL || $dateElement !== $date) { + throw new \Exception ("Expected article with date does not exist"); + } + if ($titleElement === NULL || $titleElement !== $title) { + throw new \Exception ("Expected article with title does not exist"); + } + } + /** * @When I open the article with the title :title * diff --git a/tests/features/lib/AdminPage.php b/tests/features/lib/AdminPage.php index bb4fdb5..f5b8c05 100644 --- a/tests/features/lib/AdminPage.php +++ b/tests/features/lib/AdminPage.php @@ -18,6 +18,8 @@ class AdminPage extends CMSPage{ protected $xpathOfAddNewArticle = '//a[@href="admin.php?action=newArticle"]'; protected $xpathOfOpenArticle = '//td[text()[normalize-space() = "%s"]]'; + protected $xpathOfTitle = '//tr/td[2][text()[normalize-space() = "%s"]]'; + protected $xpathOfDate = '//tr/td[1][text()[normalize-space() = "%s"]]'; /** * @return void @@ -37,4 +39,33 @@ function openArticle($title) { $this->find("xpath", $titleof)->click(); } + /** + * + * @param string $title + * @return NULL|string + */ + function getTitle($title) { + $articleTitle = sprintf($this->xpathOfTitle, $title); + $titleElement = ($this->find('xpath', $articleTitle)); + if ($titleElement === null) { + return null; + } else { + return trim($titleElement->getHtml()); + } + } + + /** + * + * @param string $date + * @return NULL|string + */ + function getDate($date) { + $articleDate = sprintf($this->xpathOfDate, $date); + $dateElement = $this->find('xpath', $articleDate); + if ($dateElement === null) { + return null; + } else { + return trim($dateElement->getHtml()); + } + } } \ No newline at end of file