Skip to content

Instantly share code, notes, and snippets.

@fago
Created February 10, 2013 22:55
Show Gist options
  • Save fago/4751413 to your computer and use it in GitHub Desktop.
Save fago/4751413 to your computer and use it in GitHub Desktop.
protected function assertIterator($entity_type) {
$entity = $this->createTestEntity($entity_type);
foreach ($entity as $name => $field) {
$this->assertTrue($field instanceof FieldInterface, $entity_type . ": Field $name implements interface.");
foreach ($field as $delta => $item) {
$this->assertTrue($field[0] instanceof FieldItemInterface, $entity_type . ": Item $delta of field $name implements interface.");
foreach ($item as $value_name => $value_property) {
$this->assertTrue($value_property instanceof TypedDataInterface, $entity_type . ": Value $value_name of item $delta of field $name implements interface.");
$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.");
}
}
}
$properties = $entity->getProperties();
$this->assertEqual(array_keys($properties), array_keys($entity->getPropertyDefinitions()), format_string('%entity_type: All properties returned.', array('%entity_type' => $entity_type)));
$this->assertEqual($properties, iterator_to_array($entity->getIterator()), format_string('%entity_type: Entity iterator iterates over all properties.', array('%entity_type' => $entity_type)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment