Tests iterating over properties.
public function testIterator() {
  $entity = $this
    ->createTestEntity();
  foreach ($entity as $name => $field) {
    $this
      ->assertTrue($field instanceof FieldInterface, "Field {$name} implements interface.");
    foreach ($field as $delta => $item) {
      $this
        ->assertTrue($field[0] instanceof FieldItemInterface, "Item {$delta} of field {$name} implements interface.");
      foreach ($item as $value_name => $value_property) {
        $this
          ->assertTrue($value_property instanceof TypedDataInterface, "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, "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()), 'All properties returned.');
  $this
    ->assertEqual($properties, iterator_to_array($entity
    ->getIterator()), 'Entity iterator iterates over all properties.');
}