Skip to content

Commit

Permalink
Merge pull request #2 from palantirnet/features-test
Browse files Browse the repository at this point in the history
Add methods to verify the state of Drupal features.
  • Loading branch information
becw committed Dec 14, 2015
2 parents e1b837c + 4acd7ac commit 8af3b14
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The Palantir Behat Drupal Extension provides additional step definitions for tes
* `NodeContext`: test viewing and editing nodes by title
* `DrupalCommentContext`: test commenting functionality
* `DrupalOrganicGroupsContext`: test access to Organic Groups
* `DrupalSetupContext`: test for enabled modules and overridden features
* `EntityDataContext`: test field data and properties on nodes, terms, and users directly, without relying on output (or write a simpletest...)

### Disable module functionality during tests
Expand Down Expand Up @@ -47,7 +48,15 @@ default:
suites:
default:
contexts:
- Palantirnet\PalantirBehatExtension\Context\NodeContext
- Palantirnet\PalantirBehatExtension\Context\DrupalAutoNodetitleContext.php
- Palantirnet\PalantirBehatExtension\Context\DrupalCommentContext.php
- Palantirnet\PalantirBehatExtension\Context\DrupalOrganicGroupsContext.php
- Palantirnet\PalantirBehatExtension\Context\DrupalSetupContext.php
- Palantirnet\PalantirBehatExtension\Context\DrupalWorkbenchModerationContext.php
- Palantirnet\PalantirBehatExtension\Context\EntityDataContext.php
- Palantirnet\PalantirBehatExtension\Context\MarkupContext.php
- Palantirnet\PalantirBehatExtension\Context\NodeContext.php
- Palantirnet\PalantirBehatExtension\Context\SharedDrupalContext.php
```

----
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/**
* @file
* Behat context for validating Drupal configuration.
*
* @copyright (c) Copyright 2015 Palantir.net, Inc.
*/

namespace Palantirnet\PalantirBehatExtension\Context;

class DrupalSetupContext extends SharedDrupalContext
{

/**
* @Given a Drupal site
*/
public function assertDrupal()
{
if (!$this->getDriver()->isBootstrapped()) {
throw new \Exception('The Drupal site is not bootstrapped.');
}
}

/**
* @Then the :module module is installed
*/
public function assertModuleInstalled($module)
{
if (!module_exists('features')) {
throw new \Exception(sprintf('The "%s" module is not installed.', $module));
}
}

/**
* @Then no Drupal features are overridden
*/
public function assertDefaultDrupalFeatures()
{
$this->assertModuleInstalled('features');

module_load_include('inc', 'features', 'features.export');
$features = features_get_features(NULL, TRUE);

$overridden = array();
foreach ($features as $k => $m) {
if (features_get_storage($m->name) == FEATURES_OVERRIDDEN) {
$overridden[] = $m->name;
}
}

if (!empty($overridden)) {
throw new \Exception(sprintf('%d Drupal features are overridden: %s.', count($overridden), implode(', ', $overridden)));
}
}

}

0 comments on commit 8af3b14

Please sign in to comment.