You are here

class FeatureContext in Bear 8.2

Same name and namespace in other branches
  1. 8 tests/features/bootstrap/FeatureContext.php \FeatureContext
  2. 7.2 tests/features/bootstrap/FeatureContext.php \FeatureContext
  3. 7 tests/features/bootstrap/FeatureContext.php \FeatureContext

Defines application features from the specific context.

Hierarchy

  • class \FeatureContext extends \Drupal\DrupalExtension\Context\RawDrupalContext implements \Behat\Behat\Context\SnippetAcceptingContext

Expanded class hierarchy of FeatureContext

1 string reference to 'FeatureContext'
behat.yml in tests/behat.yml
tests/behat.yml

File

tests/features/bootstrap/FeatureContext.php, line 19

View source
class FeatureContext extends RawDrupalContext implements SnippetAcceptingContext {

  /**
   * An array of Behat Context objects.
   *
   * An array of other contexts that this class delegates to in the event
   * a non-existent method is called on this class.  It's the poor man's traits.
   */
  public $subcontexts = array();

  /**
   * Initializes context.
   *
   * Every scenario gets its own context instance.
   * You can also pass arbitrary arguments to the
   * context constructor through behat.yml.
   */
  public function __construct() {

    #$this->localConf = $this->getConfig();
  }

  #public function getConfig() {

  #  if (!file_exists('local-config.yaml')) {

  #    throw new Exception('Please create a local-config.yaml.  See example.local-config.yaml for structure.');

  #  }

  #  return Yaml::parse('local-config.yaml');

  #}

  /**
   * @Transform /\[.*\](?:.*)/
   */
  public function transformLocalConf($argument) {

    // Token replace the argument.
    preg_match('/\\[(.*)\\]/', $argument, $matches);
    $token = $matches[1];
    if (isset($this->localConf[$token])) {

      // throw new \Exception(sprintf('Argument %s and token %s and result %s', $argument, $token, str_replace('[' . $token . ']', $this->localConf[$token], $argument)));
      return str_replace('[' . $token . ']', $this->localConf[$token], $argument);
    }
  }

  /**
   * @AfterScenario @deleteTestField
   */
  public function deleteTestField() {
    $driver = $this
      ->getSession()
      ->getDriver();
    $driver
      ->visit("/admin/structure/types/manage/page/fields/node.page.field_test/delete");
    $this
      ->getSession()
      ->getPage()
      ->pressButton("Delete");
  }

  /**
   * Checks that a specific radio button is checked, must use radio button's id.
   *
   * @Then /^the "([^"]*)" radio should be checked$/
   */
  public function theRadioShouldBeChecked($arg1) {
    $elementByCss = $this
      ->getSession()
      ->getPage()
      ->find('css', 'input[type="radio"]:checked#' . $arg1);
    if (!$elementByCss) {
      throw new Exception('Radio button with id ' . $arg1 . ' is not checked');
    }
  }

  /**
   * Waits for 1 second.
   *
   * @Given /^I wait (\d+) seconds$/
   */
  public function iWait($time) {
    sleep($time);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FeatureContext::$subcontexts public property An array of Behat Context objects.
FeatureContext::deleteTestField public function @AfterScenario @deleteTestField
FeatureContext::iWait public function Waits for 1 second.
FeatureContext::theRadioShouldBeChecked public function Checks that a specific radio button is checked, must use radio button's id.
FeatureContext::transformLocalConf public function @Transform /\[.*\](?:.*)/
FeatureContext::__construct public function Initializes context.