Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
34 changes: 21 additions & 13 deletions tests/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
31 changes: 31 additions & 0 deletions tests/features/lib/AdminPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
}
}
}