Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jhedstrom
Last active August 29, 2015 13:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhedstrom/9633067 to your computer and use it in GitHub Desktop.
Save jhedstrom/9633067 to your computer and use it in GitHub Desktop.
Behat steps for the Achievements module
<?php
// Snippet method in FeatureContext class.
/**
* @Then /^I should see the "(?P<achievement>[^"]*)" achievement "(?P<status>[^"]*)"$/
*/
public function iShouldSeeTheAchievement($achievement, $status) {
if (!in_array($status, array('unlocked', 'locked'))) {
throw new \Exception(sprintf("Achievement status should either be 'locked' or 'unlocked', '%s' given instead.", $status));
}
// Locate all achievements.
$page = $this->getSession()->getPage();
$achievements = $page->findAll('css', '.achievement');
if (!$achievements) {
throw new \Exception(sprintf('No achievements are displayed on this page (%s).', $this->getSession()->getCurrentUrl()));
}
// Verify achievement is present on the page.
$achievement_found = FALSE;
foreach ($achievements as $item) {
if (FALSE !== strpos($item->getText(), $achievement)) {
// This is the achievement we want to check status on.
$achievement_found = $item;
}
}
if (!$achievement_found) {
throw new \Exception(sprintf('The achievement "%s" was not found on this page (%s).', $achievement, $this->getSession()->getCurrentUrl()));
}
if ($status === 'locked') {
// The class 'achievement-locked' should be present.
$class = 'achievement-locked';
}
else {
$class = 'achievement-unlocked';
}
if (!$achievement_found->hasClass($class)) {
throw new \Exception(sprintf('The achievement "%s" was found on the page (%s) but not with the "%s" status.', $achievement, $this->getSession()->getCurrentUrl(), $status));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment