Last active
August 29, 2015 13:57
-
-
Save jhedstrom/9633067 to your computer and use it in GitHub Desktop.
Behat steps for the Achievements module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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