Skip to content

Instantly share code, notes, and snippets.

@jonpugh
Created July 15, 2015 21:45
Show Gist options
  • Save jonpugh/d697608a5db73af6800a to your computer and use it in GitHub Desktop.
Save jonpugh/d697608a5db73af6800a to your computer and use it in GitHub Desktop.
Custom Behat steps for OG: @given I start a :type community called :title with description :description
<?php
use Drupal\DrupalExtension\Context\RawDrupalContext;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Behat\Tester\Exception\PendingException;
use Behat\Behat\Hook\Scope\AfterStepScope;
use Behat\Behat\Hook\Scope\BeforeStepScope;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
use Behat\Mink\Exception;
use Behat\Mink\Selector;
use Drupal\DrupalExtension\Hook\Scope\AfterUserCreateScope;
/**
* Defines application features from the specific context.
*/
class FeatureContext extends RawDrupalContext implements SnippetAcceptingContext {
private $community_urls;
/**
* @Given I start a :type community called :title
* @Given I start a :type community called :title with description :description
*
* Type can be public, private, or invite.
*
And I am at "user"
And I click "Start a Community"
Then I fill in "Behat Community" for "title"
And I fill in "This is my test community" for "Body"
# Who can find and access this community and its content? Members Only
And I select "1" from "group_access[und]"
# Is moderator approval required to join this community? No, anyone can join.
And I select "1" from "group_subscribe[und]"
And I press "Save Community"
Then I should see "Behat Community"
And I should see "This is my test community"
*/
public function iStartACommunityCalled($type, $title, $body = "") {
// Visit MyEngage, Click Start a community
$this->getSession()->visit('user');
$this->getSession()->getPage()->clickLink('Start a Community');
// Fill out the fields for community.
$this->getSession()->getPage()->fillField("title", $title);
$this->getSession()->getPage()->fillField("Body", $body);
if ($type == 'public') {
$group_access = 0;
$group_subscribe = 1;
}
elseif ($type == 'invite') {
$group_access = 0;
$group_subscribe = 0;
}
elseif ($type == 'private') {
$group_access = 1;
$group_subscribe = 0;
}
else {
throw new \Exception('Group type must be "open membership", "closed membership", or "private"');
}
$this->getSession()->getPage()->selectFieldOption('group_access[und]', $group_access);
if ($group_access != 1) {
$this->getSession()->getPage()->selectFieldOption('group_subscribe[und]', $group_subscribe);
}
// Click the Save button.
$this->getSession()->getPage()->pressButton("Save Community");
// Save the Community URL for later.
$this->community_urls[$title] = $this->getSession()->getCurrentUrl();
// Make sure the page contains the community title and the settings button.
$this->assertSession()->pageTextContains($title);
$this->assertSession()->pageTextContains('Community Settings');
}
/**
* @When I visit the community :title
*/
public function iVisitTheCommunityUrl($title)
{
$this->getSession()->visit($this->community_urls[$title]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment