You are here

public function ConfigSnapshotConfigEntityUnitTest::testItems in Config Snapshot 8

@covers ::clearItem @covers ::getItem @covers ::getItems @covers ::setItem

File

tests/src/Unit/ConfigSnapshotConfigEntityUnitTest.php, line 112

Class

ConfigSnapshotConfigEntityUnitTest
@coversDefaultClass \Drupal\config_snapshot\Entity\ConfigSnapshot @group config_snapshot

Namespace

Drupal\Tests\config_snapshot\Unit

Code

public function testItems() {
  $expected_item = [
    'collection' => StorageInterface::DEFAULT_COLLECTION,
    'name' => 'example',
    'data' => [
      'something' => 'some_value',
    ],
  ];

  // Set a new item.
  $this->entity
    ->setItem($expected_item['collection'], $expected_item['name'], $expected_item['data']);
  $items = $this->entity
    ->getItems();
  $this
    ->assertEquals(1, count($items));
  $this
    ->assertEquals($expected_item, $items[0]);
  $item = $this->entity
    ->getItem($expected_item['collection'], $expected_item['name']);
  $this
    ->assertEquals($expected_item, $item);

  // Reset an existing item.
  $expected_new_data = [
    'something_else' => 'some_new_value',
  ];
  $this->entity
    ->setItem($expected_item['collection'], $expected_item['name'], $expected_new_data);
  $item = $this->entity
    ->getItem($expected_item['collection'], $expected_item['name']);
  $this
    ->assertEquals($expected_new_data, $item['data']);

  // Clear an item.
  $this->entity
    ->clearItem($expected_item['collection'], $expected_item['name']);
  $item = $this->entity
    ->getItem($expected_item['collection'], $expected_item['name']);
  $this
    ->assertNull($item);
}