You are here

protected function ConfigEntityQueryTest::setUp in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/Core/Entity/ConfigEntityQueryTest.php \Drupal\KernelTests\Core\Entity\ConfigEntityQueryTest::setUp()

Overrides KernelTestBase::setUp

File

core/tests/Drupal/KernelTests/Core/Entity/ConfigEntityQueryTest.php, line 52

Class

ConfigEntityQueryTest
Tests Config Entity Query functionality.

Namespace

Drupal\KernelTests\Core\Entity

Code

protected function setUp() : void {
  parent::setUp();
  $this->entities = [];
  $this->entityStorage = $this->container
    ->get('entity_type.manager')
    ->getStorage('config_query_test');

  // These two are here to make sure that matchArray needs to go over several
  // non-matches on every levels.
  $array['level1']['level2a'] = 9;
  $array['level1a']['level2'] = 9;

  // The tests match array.level1.level2.
  $array['level1']['level2'] = 1;
  $entity = ConfigQueryTest::create([
    'label' => 'entity_1',
    'id' => '1',
    'number' => 31,
    'array' => $array,
  ]);
  $this->entities[] = $entity;
  $entity
    ->enforceIsNew();
  $entity
    ->save();
  $array['level1']['level2'] = 2;
  $entity = ConfigQueryTest::create([
    'label' => 'entity_2',
    'id' => '2',
    'number' => 41,
    'array' => $array,
  ]);
  $this->entities[] = $entity;
  $entity
    ->enforceIsNew();
  $entity
    ->save();
  $array['level1']['level2'] = 1;
  $entity = ConfigQueryTest::create([
    'label' => 'test_prefix_entity_3',
    'id' => '3',
    'number' => 59,
    'array' => $array,
  ]);
  $this->entities[] = $entity;
  $entity
    ->enforceIsNew();
  $entity
    ->save();
  $array['level1']['level2'] = 2;
  $entity = ConfigQueryTest::create([
    'label' => 'entity_4_test_suffix',
    'id' => '4',
    'number' => 26,
    'array' => $array,
  ]);
  $this->entities[] = $entity;
  $entity
    ->enforceIsNew();
  $entity
    ->save();
  $array['level1']['level2'] = 3;
  $entity = ConfigQueryTest::create([
    'label' => 'entity_5_TEST_contains_entity_5',
    'id' => '5',
    'number' => 53,
    'array' => $array,
  ]);
  $this->entities[] = $entity;
  $entity
    ->enforceIsNew();
  $entity
    ->save();
  $array['level1'] = [];
  $entity = ConfigQueryTest::create([
    'label' => $this
      ->randomMachineName(),
    'id' => '6',
    'array' => $array,
  ]);
  $this->entities[] = $entity;
  $entity
    ->enforceIsNew();
  $entity
    ->save();
  $array['level1']['level2'] = 4;
  $entity = ConfigQueryTest::create([
    'label' => $this
      ->randomMachineName(),
    'id' => '7',
    'number' => 70,
    'array' => $array,
  ]);
  $this->entities[] = $entity;
  $entity
    ->enforceIsNew();
  $entity
    ->save();
}