You are here

public function ConfigEntityAdapterTest::testGetIterator in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/Core/Entity/ConfigEntityAdapterTest.php \Drupal\KernelTests\Core\Entity\ConfigEntityAdapterTest::testGetIterator()
  2. 9 core/tests/Drupal/KernelTests/Core/Entity/ConfigEntityAdapterTest.php \Drupal\KernelTests\Core\Entity\ConfigEntityAdapterTest::testGetIterator()

@covers ::getIterator

File

core/tests/Drupal/KernelTests/Core/Entity/ConfigEntityAdapterTest.php, line 153

Class

ConfigEntityAdapterTest
Tests entity adapter for configuration entities.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testGetIterator() {
  $adapter = ConfigEntityAdapter::createFromEntity($this->entity);
  $iterator = $adapter
    ->getIterator();
  $fields = iterator_to_array($iterator);
  $expected_fields = [
    'uuid',
    'langcode',
    'status',
    'dependencies',
    'id',
    'label',
    'weight',
    'style',
    'size',
    'size_value',
    'protected_property',
  ];
  $this
    ->assertEquals($expected_fields, array_keys($fields));
  $this
    ->assertEquals($this->entity
    ->id(), $fields['id']
    ->getValue());
  $adapter
    ->setValue(NULL);
  $this
    ->assertEquals(new \ArrayIterator([]), $adapter
    ->getIterator());
}