Skip to content
Snippets Groups Projects
Commit 32157c7c authored by Alex Pott's avatar Alex Pott
Browse files

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

Issue #2941457 by agentrickard, tim.plunkett, hbensalem: EntityAdapter::getIterator requires undocumented methods
parent 6341df36
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -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());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment