Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ from the community.

| Class | Description |
| --- | --- |
| [Drupal\BigPipeTrait](STEPS.md#drupalbigpipetrait) | Bypass Drupal BigPipe when rendering pages. |
| [Drupal\BlockTrait](STEPS.md#drupalblocktrait) | Manage Drupal blocks. |
| [Drupal\CacheTrait](STEPS.md#drupalcachetrait) | Invalidate specific Drupal caches from within a scenario. |
| [Drupal\ConfigOverrideTrait](STEPS.md#drupalconfigoverridetrait) | Disable Drupal config overrides from settings.php during a scenario. |
Expand Down
13 changes: 0 additions & 13 deletions STEPS.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

| Class | Description |
| --- | --- |
| [Drupal\BigPipeTrait](#drupalbigpipetrait) | Bypass Drupal BigPipe when rendering pages. |
| [Drupal\BlockTrait](#drupalblocktrait) | Manage Drupal blocks. |
| [Drupal\CacheTrait](#drupalcachetrait) | Invalidate specific Drupal caches from within a scenario. |
| [Drupal\ConfigOverrideTrait](#drupalconfigoverridetrait) | Disable Drupal config overrides from settings.php during a scenario. |
Expand Down Expand Up @@ -2473,18 +2472,6 @@ Then the XML should not use the namespace "http://example.com/nonexistent"



## Drupal\BigPipeTrait

[Source](src/Drupal/BigPipeTrait.php), [Example](tests/behat/features/drupal_big_pipe.feature)

> Bypass Drupal BigPipe when rendering pages.
> <br/><br/>
> Activated by adding `@big_pipe` tag to the scenario.
> <br/><br/>
> Skip processing with tags: `@behat-steps-skip:bigPipeBeforeScenario` or
> `@behat-steps-skip:bigPipeBeforeStep`.


## Drupal\BlockTrait

[Source](src/Drupal/BlockTrait.php), [Example](tests/behat/features/drupal_block.feature)
Expand Down
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
"php": ">=8.2",
"behat/behat": "^3.14",
"behat/mink": ">=1.11",
"behat/mink-selenium2-driver": ">=1.7",
"drupal/drupal-extension": "^5.3.1"
"drupal/drupal-driver": "^3.0@alpha",
"drupal/drupal-extension": "^6.0@alpha",
"lullabot/mink-selenium2-driver": "^1.7.4"
},
"require-dev": {
"alexskrypnyk/phpunit-helpers": "^0.15.0",
Expand All @@ -43,6 +44,8 @@
"phpunit/phpunit": "^11",
"rector/rector": "^2.0"
},
"minimum-stability": "alpha",
"prefer-stable": true,
"autoload": {
"psr-4": {
"DrevOps\\BehatSteps\\": "src/"
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ services:
chrome:
image: selenium/standalone-chromium:145.0
ports:
- "7900:7900" # Access Chrome using noVNC at http://behat-steps.docker.amazee.io:7900/?autoconnect=1&password=secret
- "7900" # Access Chrome using noVNC at http://behat-steps.docker.amazee.io:7900/?autoconnect=1&password=secret
expose:
- "8888"
shm_size: '1gb'
Expand Down
87 changes: 0 additions & 87 deletions src/Drupal/BigPipeTrait.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/Drupal/BlockTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ trait BlockTrait {
* Add the tag @behat-steps-skip:blockAfterScenario to your scenario to
* prevent automatic cleanup of blocks.
*/
#[AfterScenario]
#[AfterScenario('@api')]
public function blockAfterScenario(AfterScenarioScope $scope): void {
if ($scope->getScenario()->hasTag('behat-steps-skip:' . __FUNCTION__)) {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/Drupal/ConfigOverrideTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ trait ConfigOverrideTrait {
* state never bleeds between scenarios - even when this hook is bypassed
* via `@behat-steps-skip:configOverrideBeforeScenario`.
*/
#[BeforeScenario]
#[BeforeScenario('@api')]
public function configOverrideBeforeScenario(BeforeScenarioScope $scope): void {
$this->configOverrideDisabledNames = [];
$this->configOverrideSkipBeforeStep = FALSE;
Expand Down
12 changes: 6 additions & 6 deletions src/Drupal/ContentBlockTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Drupal\block_content\BlockContentTypeInterface;
use Drupal\block_content\Entity\BlockContent;
use Drupal\Core\Entity\EntityStorageException;
use Drupal\Driver\Entity\EntityStub;

/**
* Manage Drupal content blocks.
Expand All @@ -39,7 +40,7 @@ trait ContentBlockTrait {
/**
* Clean up all content block entities created during the scenario.
*/
#[AfterScenario]
#[AfterScenario('@api')]
public function contentBlockAfterScenario(AfterScenarioScope $scope): void {
if ($scope->getScenario()->hasTag('behat-steps-skip:' . __FUNCTION__)) {
return;
Expand Down Expand Up @@ -218,13 +219,12 @@ public function contentBlockCreateWithFields(string $type, TableNode $table): vo
* When the entity cannot be saved.
*/
protected function contentBlockCreateSingle(string $type, array $values): BlockContent {
$values = (object) $values;
$values->type = $type;
$this->parseEntityFields('block_content', $values);
$values = (array) $values;
$values['type'] = $type;
$stub = new EntityStub('block_content', $type, $values);
$this->parseEntityFields($stub);

/** @var \Drupal\block_content\Entity\BlockContent $entity */
$entity = BlockContent::create($values);
$entity = BlockContent::create($stub->getValues());
$entity->save();

static::$contentBlockEntities[] = $entity;
Expand Down
30 changes: 17 additions & 13 deletions src/Drupal/EckTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

namespace DrevOps\BehatSteps\Drupal;

use Behat\Step\Given;
use Behat\Step\When;
use Behat\Behat\Hook\Scope\AfterScenarioScope;
use Behat\Gherkin\Node\TableNode;
use Behat\Hook\AfterScenario;
use Behat\Step\Given;
use Behat\Step\When;
use Drupal\Driver\Capability\ContentCapabilityInterface;
use Drupal\Driver\Entity\EntityStub;

/**
* Manage Drupal ECK entities with custom type and bundle creation.
Expand All @@ -31,7 +33,7 @@ trait EckTrait {
/**
* Remove ECK types and entities.
*/
#[AfterScenario]
#[AfterScenario('@api')]
public function eckAfterScenario(AfterScenarioScope $scope): void {
if ($scope->getScenario()->hasTag('behat-steps-skip:' . __FUNCTION__)) {
return;
Expand Down Expand Up @@ -190,26 +192,28 @@ protected function eckLoadMultiple(string $entity_type, string $bundle, array $c
*/
protected function eckCreateEntities(string $entity_type, string $bundle, TableNode $table): void {
foreach ($table->getHash() as $entity_hash) {
$entity = (object) $entity_hash;
$entity->type = $bundle;
$this->eckCreateEntity($entity_type, $entity);
$stub = new EntityStub($entity_type, $bundle, $entity_hash);
$this->eckCreateEntity($stub);
}
}

/**
* Create a single content entity.
*/
protected function eckCreateEntity(string $entity_type, \StdClass $entity): void {
$this->parseEntityFields($entity_type, $entity);
$saved = $this->getDriver()->createEntity($entity_type, $entity);
if (!$saved) {
protected function eckCreateEntity(EntityStub $stub): void {
$this->parseEntityFields($stub);

$driver = $this->getDriver();
if (!$driver instanceof ContentCapabilityInterface) {
// @codeCoverageIgnoreStart
throw new \RuntimeException(sprintf('Failed to create ECK entity of type "%s".', $entity_type));
throw new \RuntimeException(sprintf('The active Drupal driver "%s" does not support ECK entity creation.', $driver::class));
// @codeCoverageIgnoreEnd
}

// Store the entity - driver may return stdClass or entity object.
$this->eckEntities[$entity_type][] = $saved;
$driver->entityCreate($stub);

// Store the saved Drupal entity for AfterScenario cleanup.
$this->eckEntities[$stub->getEntityType()][] = $stub->getSavedEntity();
}

}
4 changes: 2 additions & 2 deletions src/Drupal/EmailTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ trait EmailTrait {
/**
* Enable email tracking.
*/
#[BeforeScenario]
#[BeforeScenario('@api')]
public function emailBeforeScenario(BeforeScenarioScope $scope): void {
// @codeCoverageIgnoreStart
if ($scope->getScenario()->hasTag('behat-steps-skip:' . __FUNCTION__)) {
Expand Down Expand Up @@ -84,7 +84,7 @@ public function emailBeforeScenario(BeforeScenarioScope $scope): void {
/**
* Disable email tracking.
*/
#[AfterScenario]
#[AfterScenario('@api')]
public function emailAfterScenario(AfterScenarioScope $scope): void {
if ($scope->getScenario()->hasTag('behat-steps-skip:' . __FUNCTION__)) {
return;
Expand Down
28 changes: 19 additions & 9 deletions src/Drupal/FileTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Behat\Mink\Exception\ExpectationException;
use Drupal\Core\File\FileExists;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Driver\Entity\EntityStub;
use Drupal\file\FileInterface;
use Symfony\Component\Filesystem\Filesystem;

Expand Down Expand Up @@ -46,13 +47,22 @@ trait FileTrait {
/**
* Ensure private and temp directories exist.
*/
#[BeforeScenario]
#[BeforeScenario('@api')]
public function fileBeforeScenario(BeforeScenarioScope $scope): void {
// @codeCoverageIgnoreStart
if ($scope->getScenario()->hasTag('behat-steps-skip:' . __FUNCTION__)) {
return;
}
// @codeCoverageIgnoreEnd
// 6.x Drupal driver bootstraps lazily on first step that needs Drupal,
// so the container may not exist yet when this hook fires. Skip the
// best-effort directory check until Drupal is up - the dirs will be
// created on demand by the file operations that actually need them.
// @codeCoverageIgnoreStart
if (!\Drupal::hasContainer()) {
return;
}
// @codeCoverageIgnoreEnd
$fs = new Filesystem();

// @codeCoverageIgnoreStart
Expand Down Expand Up @@ -89,7 +99,7 @@ public function fileCreateManaged(TableNode $table): void {
$uri = $hash['uri'] ?? NULL;
unset($hash['path'], $hash['uri']);

$stub = (object) $hash;
$stub = new EntityStub('file', NULL, $hash);
$this->fileCreateManagedSingle($path, $stub, $uri);
}
}
Expand All @@ -99,16 +109,16 @@ public function fileCreateManaged(TableNode $table): void {
*
* @param string $path
* The source file path relative to 'files_path'.
* @param \StdClass $stub
* @param \Drupal\Driver\Entity\EntityStub $stub
* Entity fields stub (must not contain 'path' or 'uri').
* @param string|null $uri
* Optional destination URI. Defaults to 'public://filename'.
*
* @return \Drupal\file\FileInterface
* Created file entity.
*/
protected function fileCreateManagedSingle(string $path, \StdClass $stub, ?string $uri = NULL): FileInterface {
$this->parseEntityFields('file', $stub);
protected function fileCreateManagedSingle(string $path, EntityStub $stub, ?string $uri = NULL): FileInterface {
$this->parseEntityFields($stub);

$saved = $this->fileCreateEntity($path, $stub, $uri);

Expand All @@ -122,15 +132,15 @@ protected function fileCreateManagedSingle(string $path, \StdClass $stub, ?strin
*
* @param string $path
* The source file path relative to 'files_path'.
* @param \StdClass $stub
* @param \Drupal\Driver\Entity\EntityStub $stub
* Entity fields stub.
* @param string|null $uri
* Optional destination URI. Defaults to 'public://filename'.
*
* @return \Drupal\file\FileInterface
* Created file entity.
*/
protected function fileCreateEntity(string $path, \StdClass $stub, ?string $uri = NULL): FileInterface {
protected function fileCreateEntity(string $path, EntityStub $stub, ?string $uri = NULL): FileInterface {
$path = ltrim($path, '/');

// Get fixture file path.
Expand Down Expand Up @@ -166,7 +176,7 @@ protected function fileCreateEntity(string $path, \StdClass $stub, ?string $uri
// @codeCoverageIgnoreEnd
$entity = \Drupal::service('file.repository')->writeData($content, $destination, FileExists::Replace);

foreach (get_object_vars($stub) as $property => $value) {
foreach ($stub->getValues() as $property => $value) {
$entity->set($property, $value);
}

Expand All @@ -178,7 +188,7 @@ protected function fileCreateEntity(string $path, \StdClass $stub, ?string $uri
/**
* Clean all created managed files after scenario run.
*/
#[AfterScenario]
#[AfterScenario('@api')]
public function fileAfterScenario(AfterScenarioScope $scope): void {
// @codeCoverageIgnoreStart
if ($scope->getScenario()->hasTag('behat-steps-skip:' . __FUNCTION__)) {
Expand Down
Loading