8000 Updated language. by AlexSkrypnyk · Pull Request #375 · drevops/behat-steps · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Updated language. #375

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
10 changes: 5 additions & 5 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ A migration map of the step definitions available in v2 to v3.

| V2 | V3 |
|------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| **[`BlockContentTrait`](src/BlockContentTrait< 10000 /span>.php) ([example](tests/behat/features/block_content.feature))** | |
| `Given :type block_content type exists` | `Given the custom block type ":type" exists` |
| `Given no :type block_content:` | `Given the following ":type" custom blocks do not exist:` |
| `When I edit :type block_content_type with description :description` | `When I edit the ":type" custom block with description ":description"` |
| `Given :type block_content:` | `Given the following ":type" custom blocks exist:` |
| **[`ContentBlockTrait`](src/ContentBlockTrait.php) ([example](tests/behat/features/content_block.feature))** | |
| `Given :type block_content type exists` | `Then the content block type :type should exist` |
| `Given no :type block_content:` | `Given the following :type content blocks do not exist:` |
| `When I edit :type block_content_type with description :description` | `When I edit the :type content block with the description :description` |
| `Given :type block_content:` | `Given the following :type content blocks exist:` |
| &nbsp; | |
| **[`ContentTrait`](src/ContentTrait.php) ([example](tests/behat/features/content.feature))** | |
| `Given no :type content type` | `Given the content type :content_type does not exist` |
Expand Down
2 changes: 2 additions & 0 deletions docs.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ function extract_info(string $class_name, array $exclude = []): array {

$traits = $reflection->getTraits();

sort($traits);

$result = [];
foreach ($traits as $trait) {
$trait_name = $trait->getShortName();
Expand Down
153 changes: 77 additions & 76 deletions src/BlockContentTrait.php → src/ContentBlockTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,79 +10,80 @@
use Drupal\block_content\BlockContentTypeInterface;

/**
* Provides Behat step definitions for managing custom block content entities.
* Provides Behat step definitions for managing content block entities.
*
* This trait enables programmatic management of custom block_content
* This trait enables programmatic management of content block
* entities in Drupal, including creation, validation, and editing operations.
* These reusable content blocks can be placed in regions using the BlockTrait.
*/
trait BlockContentTrait {
trait ContentBlockTrait {

/**
* Array of created block_content entities.
*
* @var array<int,\Drupal\block_content\Entity\BlockContent>
*/
protected static $blockContentEntities = [];
protected static $contentBlockEntities = [];

/**
* Cleans up all custom block content entities created during the scenario.
* Cleans up all content block entities created during the scenario.
*
* This method automatically runs after each scenario to ensure clean test
* state.
* Add the tag @behat-steps-skip:blockContentCleanAll to your scenario to
* prevent automatic cleanup of block content entities.
* Add the tag @behat-steps-skip:contentBlockAfterScenario to your scenario to
* prevent automatic cleanup of content block entities.
*
* @AfterScenario
*/
public function blockContentCleanAll(AfterScenarioScope $scope): void {
public function contentBlockAfterScenario(AfterScenarioScope $scope): void {
// Allow to skip this by adding a tag.
if ($scope->getScenario()->hasTag('behat-steps-skip:' . __FUNCTION__)) {
return;
}

foreach (static::$blockContentEntities as $block_content) {
foreach (static::$contentBlockEntities as $block_content) {
$block_content->delete();
}
static::$blockContentEntities = [];

static::$contentBlockEntities = [];
}

/**
* Verifies that a custom block type exists.
* Verifies that a content block type exists.
*
* @code
* Given the custom block type "Search" exists
* Then the content block type "Search" should exist
* @endcode
*
* @Given the custom block type ":type" exists
* @Then the content block type :type should exist
*/
public function blockContentAssertTypeExist(string $type): void {
public function contentBlockAssertTypeExist(string $type): void {
$block_content_type = \Drupal::entityTypeManager()->getStorage('block_content_type')->load($type);

if (!$block_content_type instanceof BlockContentTypeInterface) {
throw new \Exception(sprintf('"%s" block_content_type does not exist', $type));
throw new \Exception(sprintf('"%s" content block type does not exist', $type));

Check warning on line 64 in src/ContentBlockTrait.php

View check run for this annotation

Codecov / codecov/patch

src/ContentBlockTrait.php#L64

Added line #L64 was not covered by tests
}
}

/**
* Removes custom blocks of a specified type with the given descriptions.
* Removes content blocks of a specified type with the given descriptions.
*
* Deletes all custom blocks of the specified type that match any of the
* Deletes all content blocks of the specified type that match any of the
* descriptions (titles) provided in the table.
*
* @code
* Given the following "basic" custom blocks do not exist:
* Given the following "basic" content blocks do not exist:
* | [TEST] Footer Block |
* | [TEST] Contact Form |
* @endcode
*
* @Given the following ":type" custom blocks do not exist:
* @Given the following :type content blocks do not exist:
*
* @throws \Drupal\Core\Entity\EntityStorageException
* When the entity cannot be deleted.
*/
public function blockContentDelete(string $type, TableNode $contentBlockTable): void {
foreach ($contentBlockTable->getColumn(0) as $description) {
public function contentBlockDelete(string $type, TableNode $content_block_table): void {
foreach ($content_block_table->getColumn(0) as $description) {
$content_blocks = \Drupal::entityTypeManager()->getStorage('block_content')->loadByProperties([
'info' => $description,
'type' => $type,
Expand All @@ -96,25 +97,25 @@
}

/**
* Navigates to the edit page for a specified custom block.
* Navigates to the edit page for a specified content block.
*
* Finds a custom block by its type and description (admin title) and
* Finds a content block by its type and description (admin title) and
* navigates to its edit page. Throws an exception if no matching block
* is found.
*
* @code
* When I edit the "basic" custom block with description "[TEST] Footer Block"
* When I edit the "basic" content block with the description "[TEST] Footer Block"
* @endcode
*
* @When I edit the ":type" custom block with description ":description"
* @When I edit the :type content block with the description :description
*/
public function blockContentEditBlockContentWithDescription(string $type, string $description): void {
$block_ids = $this->blockContentLoadMultiple($type, [
public function contentBlockEditBlockContentWithDescription(string $type, string $description): void {
$block_ids = $this->contentBlockLoadMultiple($type, [
'info' => $description,
]);

if (empty($block_ids)) {
throw new \RuntimeException(sprintf('Unable to find %s block content with description "%s"', $type, $description));
throw new \RuntimeException(sprintf('Unable to find "%s" content block with the description "%s"', $type, $description));

Check warning on line 118 in src/ContentBlockTrait.php

View check run for this annotation

Codecov / codecov/patch

src/ContentBlockTrait.php#L118

Added line #L118 was not covered by tests
}

ksort($block_ids);
Expand All @@ -125,34 +126,9 @@
}

/**
* Load multiple content blocks with specified type and conditions.
*
* @param string $type
* The block content type.
* @param array<string,string> $conditions
* Conditions keyed by field names.
*
* @return array<int, string>
* Array of block content ids.
*/
protected function blockContentLoadMultiple(string $type, array $conditions = []): array {
$query = \Drupal::entityQuery('block_content')
->accessCheck(FALSE)
->condition('type', $type);

foreach ($conditions as $k => $v) {
$and = $query->andConditionGroup();
$and->condition($k, $v);
$query->condition($and);
}

return $query->execute();
}

/**
* Creates custom blocks of the specified type with the given field values.
* Creates content blocks of the specified type with the given field values.
*
* This step creates new custom block (block_content) entities with
* This step creates new content block (block_content) entities with
* the specified field values.
* Each row in the table creates a separate block entity of the given type.
*
Expand All @@ -165,37 +141,37 @@
* - body: Block content (for blocks with a body field)
*
* @param string $type
* The custom block type machine name.
* @param \Behat\Gherkin\Node\TableNode $block_content_table
* The content block type machine name.
* @param \Behat\Gherkin\Node\TableNode $content_block_table
* Table containing field values for each block to create.
*
* @Given the following ":type" custom blocks exist:
* @Given the following :type content blocks exist:
*
* @code
* Given the following "basic" custom blocks exist:
* Given the following "basic" content blocks exist:
* | info | status | body | created |
* | [TEST] Footer Contact | 1 | Call us at 555-1234 | 2023-01-17 8:00am |
* | [TEST] Copyright | 1 | © 2023 Example Company | 2023-01-18 9:00am |
* @endcode
*/
public function blockContentCreate(string $type, TableNode $block_content_table): void {
foreach ($block_content_table->getHash() as $hash) {
$this->blockContentCreateSingle($type, $hash);
public function contentBlockCreate(string $type, TableNode $content_block_table): void {
foreach ($content_block_table->getHash() as $hash) {
$this->contentBlockCreateSingle($type, $hash);
}
}

/**
* Creates a block content entity with the specified type and field values.
*
* This internal helper method creates and saves a single block content
* This internal helper method creates and saves a single content block
* entity.
* Created entities are stored in the static $blockContentEntities array for
* automatic cleanup after the scenario.
*
* @param string $type
* The machine name of the block content type.
* @param array<string> $values
* Associative array of field values for the block content entity.
* Associative array of field values for the content block entity.
* Common fields include:
* - info: The admin title/label (required)
* - body: The body field value (optional)
Expand All @@ -206,20 +182,45 @@
*
* @throws \Drupal\Core\Entity\EntityStorageException
* 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;

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

static::$contentBlockEntities[] = $entity;

return $entity;
}

/**
* Load multiple content blocks with specified type and conditions.
*
* @SuppressWarnings(PHPMD.StaticAccess)
* @param string $type
* The block content type.
* @param array<string,string> $conditions
* Conditions keyed by field names.
*
* @return array<int, string>
* Array of block content ids.
*/
protected function blockContentCreateSingle(string $type, array $values): BlockContent {
$block_content = (object) $values;
$block_content->type = $type;
$this->parseEntityFields('block_content', $block_content);
$block_content = (array) $block_content;
/** @var \Drupal\block_content\Entity\BlockContent $block_content */
$block_content = BlockContent::create($block_content);
$block_content->save();
static::$blockContentEntities[] = $block_content;

return $block_content;
protected function contentBlockLoadMultiple(string $type, array $conditions = []): array {
$query = \Drupal::entityQuery('block_content')
->accessCheck(FALSE)
->condition('type', $type);

foreach ($conditions as $k => $v) {
$and = $query->andConditionGroup();
$and->condition($k, $v);
$query->condition($and);
}

return $query->execute();
}

}
Loading
0