Skip to content

Commit

Permalink
Add tags for disabling auto_nodetitle and workbench_moderation during…
Browse files Browse the repository at this point in the history
… particular tests.
  • Loading branch information
becw committed Oct 20, 2015
1 parent 5f155cc commit 1bf85c5
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/**
* @file
* Behat context for use with Auto Nodetitle.
*
* @copyright (c) Copyright 2015 Palantir.net, Inc.
*/

namespace Palantirnet\PalantirBehatExtension\Context;

use Drupal\DrupalExtension\Hook\Scope\BeforeNodeCreateScope;

class DrupalAutoNodetitleContext extends SharedDrupalContext
{

/**
* @var bool
* Whether auto_nodetitle should be disabled for nodes created
* during the current scenario.
*/
var $disableAutoNodetitle = FALSE;

/**
* @BeforeScenario @disableAutoNodetitle
*
* Tag scenarios with "@disableAutoNodetitle" to bypass automatic title
* generation during particular tests; sometimes this is required in order
* to have predictable test content.
*/
public function disableAutoNodetitle()
{
$this->disableAutoNodetitle = TRUE;
}

/**
* @BeforeNodeCreate
*/
public function prepareAutoNodetitleNode(BeforeNodeCreateScope $scope)
{
if ($this->disableAutoNodetitle) {
$node = $scope->getEntity();
$node->auto_nodetitle_applied = TRUE;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
/**
* @file
* Behat context for use with Workbench Moderation.
*
* @copyright (c) Copyright 2015 Palantir.net, Inc.
*/

namespace Palantirnet\PalantirBehatExtension\Context;

use Drupal\DrupalExtension\Hook\Scope\BeforeNodeCreateScope;

class DrupalWorkbenchModerationContext extends SharedDrupalContext
{

/**
* @var bool
* Whether workbench_moderation should be disabled for nodes created
* during the current scenario.
*/
var $disableWorkbenchModeration = FALSE;

/**
* @BeforeScenario @disableWorkbenchModeration
*
* Tag scenarios with "@disableWorkbenchModeration" to bypass moderation
* during particular tests.
*/
public function disableWorkbenchModeration()
{
$this->disableWorkbenchModeration = TRUE;
}

/**
* @BeforeNodeCreate
*/
public function prepareWorkbenchModerationNode(BeforeNodeCreateScope $scope)
{
if ($this->disableWorkbenchModeration) {
$node = $scope->getEntity();
$node->status = 1;

// This is a hack; workbench_moderation_node_update() will return
// without applying moderation if it thinks that it is being called
// recursively.
$node->updating_live_revision = 'behat_skip';
}
}

}

0 comments on commit 1bf85c5

Please sign in to comment.