You are here

public function EntityContext::trashNewest in Lightning Core 8

Same name and namespace in other branches
  1. 8.5 tests/contexts/EntityContext.behat.inc \Acquia\LightningExtension\Context\EntityContext::trashNewest()
  2. 8.2 tests/contexts/EntityContext.behat.inc \Acquia\LightningExtension\Context\EntityContext::trashNewest()
  3. 8.3 tests/contexts/EntityContext.behat.inc \Acquia\LightningExtension\Context\EntityContext::trashNewest()
  4. 8.4 tests/contexts/EntityContext.behat.inc \Acquia\LightningExtension\Context\EntityContext::trashNewest()

Marks recently created entities to be deleted after the test scenario.

@When I delete the latest :entity_type @When I delete the latest :entity_type entity @When I delete the latest :n :entity_type entities

Parameters

string $entity_type: The entity type ID.

int $n: (optional) How many entities to delete.

File

tests/contexts/EntityContext.behat.inc, line 130

Class

EntityContext
Contains miscellaneous step definitions for working with Drupal entities.

Namespace

Acquia\LightningExtension\Context

Code

public function trashNewest($entity_type, $n = 1) {
  $items = \Drupal::entityTypeManager()
    ->getStorage($entity_type)
    ->getQuery()
    ->sort('created', 'DESC')
    ->range(0, $n)
    ->execute();
  foreach ($items as $id) {
    $this->trash[$entity_type][] = $id;
  }
}