-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tags for disabling auto_nodetitle and workbench_moderation during…
… particular tests.
- Loading branch information
Showing
2 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
src/Palantirnet/PalantirBehatExtension/Context/DrupalAutoNodetitleContext.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
src/Palantirnet/PalantirBehatExtension/Context/DrupalWorkbenchModerationContext.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
} | ||
} | ||
|
||
} |