Commit 32157c7c authored by alexpott's avatar alexpott

Issue #2941457 by agentrickard, tim.plunkett, hbensalem:...

Issue #2941457 by agentrickard, tim.plunkett, hbensalem: EntityAdapter::getIterator requires undocumented methods
parent 6341df36
......@@ -167,7 +167,7 @@ public function applyDefaultValue($notify = TRUE) {
* {@inheritdoc}
*/
public function getIterator() {
return isset($this->entity) ? $this->entity->getIterator() : new \ArrayIterator([]);
return $this->entity instanceof \IteratorAggregate ? $this->entity->getIterator() : new \ArrayIterator([]);
}
}
......@@ -29,19 +29,33 @@ class EntityAdapterUnitTest extends UnitTestCase {
protected $bundle;
/**
* The entity used for testing.
* The content entity used for testing.
*
* @var \Drupal\Core\Entity\ContentEntityBase|\PHPUnit_Framework_MockObject_MockObject
*/
protected $entity;
/**
* The entity adapter under test.
* The config entity used for testing.
*
* @var \Drupal\Core\Entity\ConfigtEntityBase|\PHPUnit_Framework_MockObject_MockObject
*/
protected $configEntity;
/**
* The content entity adapter under test.
*
* @var \Drupal\Core\Entity\Plugin\DataType\EntityAdapter
*/
protected $entityAdapter;
/**
* The config entity adapter under test.
*
* @var \Drupal\Core\Entity\Plugin\DataType\EntityAdapter
*/
protected $configEntityAdapter;
/**
* The entity type used for testing.
*
......@@ -228,6 +242,10 @@ protected function setUp() {
$this->entity = $this->getMockForAbstractClass('\Drupal\Core\Entity\ContentEntityBase', [$values, $this->entityTypeId, $this->bundle]);
$this->entityAdapter = EntityAdapter::createFromEntity($this->entity);
$this->configEntity = $this->getMockForAbstractClass('\Drupal\Core\Config\Entity\ConfigEntityBase', [$values, $this->entityTypeId, $this->bundle]);
$this->configEntityAdapter = EntityAdapter::createFromEntity($this->configEntity);
}
/**
......@@ -428,6 +446,7 @@ public function testApplyDefaultValue() {
* @covers ::getIterator
*/
public function testGetIterator() {
// Content entity test.
$iterator = $this->entityAdapter->getIterator();
$fields = iterator_to_array($iterator);
$this->assertArrayHasKey('id', $fields);
......@@ -436,6 +455,11 @@ public function testGetIterator() {
$this->entityAdapter->setValue(NULL);
$this->assertEquals(new \ArrayIterator([]), $this->entityAdapter->getIterator());
// Config entity test.
$iterator = $this->configEntityAdapter->getIterator();
$this->configEntityAdapter->setValue(NULL);
$this->assertEquals(new \ArrayIterator([]), $this->entityAdapter->getIterator());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment