protected function EntityFieldTest::doTestIterator in Drupal 8
Same name and namespace in other branches
- 9 core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php \Drupal\KernelTests\Core\Entity\EntityFieldTest::doTestIterator()
Executes the iterator tests for the given entity type.
Parameters
string $entity_type: The entity type to run the tests with.
1 call to EntityFieldTest::doTestIterator()
- EntityFieldTest::testIterator in core/
tests/ Drupal/ KernelTests/ Core/ Entity/ EntityFieldTest.php - Tests iterating over properties.
File
- core/
tests/ Drupal/ KernelTests/ Core/ Entity/ EntityFieldTest.php, line 521
Class
- EntityFieldTest
- Tests the Entity Field API.
Namespace
Drupal\KernelTests\Core\EntityCode
protected function doTestIterator($entity_type) {
$entity = $this
->createTestEntity($entity_type);
foreach ($entity as $name => $field) {
$this
->assertInstanceOf(FieldItemListInterface::class, $field);
foreach ($field as $delta => $item) {
$this
->assertInstanceOf(FieldItemInterface::class, $field[0]);
foreach ($item as $value_name => $value_property) {
$this
->assertInstanceOf(TypedDataInterface::class, $value_property);
$value = $value_property
->getValue();
$this
->assertTrue(!isset($value) || is_scalar($value) || $value instanceof EntityInterface, $entity_type . ": Value {$value_name} of item {$delta} of field {$name} is a primitive or an entity.");
}
}
}
$fields = $entity
->getFields();
$this
->assertEqual(array_keys($fields), array_keys($entity
->getTypedData()
->getDataDefinition()
->getPropertyDefinitions()), new FormattableMarkup('%entity_type: All fields returned.', [
'%entity_type' => $entity_type,
]));
$this
->assertEqual($fields, iterator_to_array($entity
->getIterator()), new FormattableMarkup('%entity_type: Entity iterator iterates over all fields.', [
'%entity_type' => $entity_type,
]));
}