Skip to content

Commit

Permalink
Initial work to port to Behat 3.
Browse files Browse the repository at this point in the history
  • Loading branch information
jhedstrom committed Jun 9, 2014
1 parent 0d55246 commit 4b9d2e2
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 32 deletions.
11 changes: 7 additions & 4 deletions behat.yml.dist
@@ -1,12 +1,15 @@
default:
filters:
tags: "~@api&&~@drush"
suites:
default:
contexts: [Behat\MinkExtension\Context\MinkContext, Drupal\DrupalExtension\Context\DrupalContext]
filters:
tags: "~@api&&~@drush"
extensions:
Behat\MinkExtension\Extension:
Behat\MinkExtension:
goutte: ~
selenium2: ~
base_url: http://drupal.org
Drupal\DrupalExtension\Extension:
Drupal\DrupalExtension:
blackbox: ~
region_map:
content: "#content"
Expand Down
3 changes: 2 additions & 1 deletion src/Drupal/DrupalExtension/Context/DrupalAwareInterface.php
Expand Up @@ -2,10 +2,11 @@

namespace Drupal\DrupalExtension\Context;

use Behat\Behat\Context\Context;
use Drupal\Drupal;
use Symfony\Component\EventDispatcher\EventDispatcher;

interface DrupalAwareInterface {
interface DrupalAwareInterface extends Context {

/**
* Sets Drupal instance.
Expand Down
16 changes: 6 additions & 10 deletions src/Drupal/DrupalExtension/Context/DrupalContext.php
Expand Up @@ -14,10 +14,9 @@
use Symfony\Component\Process\Process;
use Symfony\Component\EventDispatcher\EventDispatcher;

use Behat\Behat\Context\Step\Given;
use Behat\Behat\Context\Step\When;
use Behat\Behat\Context\Step\Then;
use Behat\Behat\Context\TranslatedContextInterface;
use Behat\Behat\Definition\Call\Given;
use Behat\Behat\Definition\Call\Then;
use Behat\Behat\Context\TranslatableContext;

use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
Expand All @@ -27,7 +26,7 @@
/**
* Features context.
*/
class DrupalContext extends MinkContext implements DrupalAwareInterface, TranslatedContextInterface {
class DrupalContext implements DrupalAwareInterface, TranslatableContext {

private $drupal, $drupalParameters;

Expand Down Expand Up @@ -113,11 +112,8 @@ public function initializeSubContexts() {
*
* @return array
*/
public function getTranslationResources() {
$translationFilesParent = parent::getTranslationResources();
$translationFilesDrupal = glob(__DIR__ . '/../../../../i18n/*.xliff');
$translationFilesCombined = array_merge($translationFilesParent, $translationFilesDrupal);
return $translationFilesCombined;
public static function getTranslationResources() {
return glob(__DIR__ . '/../../../../i18n/*.xliff');
}

/**
Expand Down
@@ -1,25 +1,43 @@
<?php

namespace Drupal\DrupalExtension;
namespace Drupal\DrupalExtension\ServiceContainer;

use Symfony\Component\DependencyInjection\ContainerBuilder,
Symfony\Component\DependencyInjection\Loader\YamlFileLoader,
Symfony\Component\Config\FileLocator,
Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Behat\Testwork\ServiceContainer\Extension as ExtensionInterface;
use Behat\Testwork\ServiceContainer\ExtensionManager;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;

use Behat\Behat\Extension\ExtensionInterface;
class DrupalExtension implements ExtensionInterface {

class Extension implements ExtensionInterface {
/**
* Extension configuration ID.
*/
const DRUPAL_ID = 'drupal';

/**
* Loads a specific configuration.
*
* @param array $config
* Extension configuration (from behat.yml).
* @param ContainerBuilder $container
* ContainerBuilder instance.
* Selectors handler ID.
*/
const SELECTORS_HANDLER_ID = 'drupal.selectors_handler';

/**
* {@inheritDoc}
*/
public function getConfigKey() {
return SELF::DRUPAL_ID;
}

/**
* {@inheritDoc}
*/
public function initialize(ExtensionManager $extensionManager) {
}

/**
* {@inheritDoc}
*/
public function load(array $config, ContainerBuilder $container) {
public function load(ContainerBuilder $container, array $config) {
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/config'));
$loader->load('services.yml');
$container->setParameter('drupal.drupal.default_driver', $config['default_driver']);
Expand Down Expand Up @@ -59,13 +77,19 @@ public function load(array $config, ContainerBuilder $container) {
}
}

/**
* {@inheritDoc}
*/
public function process(ContainerBuilder $container) {
}

/**
* Setup configuration for this extension.
*
* @param ArrayNodeDefinition $builder
* ArrayNodeDefinition instance.
*/
public function getConfig(ArrayNodeDefinition $builder) {
public function configure(ArrayNodeDefinition $builder) {
$builder->
children()->
arrayNode('basic_auth')->
Expand Down Expand Up @@ -144,6 +168,13 @@ public function getConfig(ArrayNodeDefinition $builder) {
end();
}

/**
* Load Drupal Extension selectors handler.
*/
private function loadSelectorsHandler(ContainerBuilder $container) {
$container->setDefinition(self::SELECTORS_HANDLER_ID);
}

/**
* Returns compiler passes used by mink extension.
*
Expand Down
Expand Up @@ -70,7 +70,7 @@ services:
class: %drupal.context.region_selector.class%
arguments:
# inject the CSSSelector
- "@behat.mink.selector.css"
- "@mink.selector.css"
- %drupal.region_map%
tags:
- { name: behat.mink.selector, alias: region }
- { name: mink.selector, alias: region }

0 comments on commit 4b9d2e2

Please sign in to comment.