protected function FieldTargetEntityTest::mockContentEntity in Twig Field Value 8
Same name and namespace in other branches
- 2.0.x tests/src/Unit/FieldValue/FieldTargetEntityTest.php \Drupal\Tests\twig_field_value\Unit\FieldValue\FieldTargetEntityTest::mockContentEntity()
Returns a mock Content Entity object.
Parameters
array $referenced_entities:
Return value
\Drupal\Core\Field\FieldItemBase The entity object.
1 call to FieldTargetEntityTest::mockContentEntity()
- FieldTargetEntityTest::providerTestTargetEntity in tests/
src/ Unit/ FieldValue/ FieldTargetEntityTest.php - Provides data and expected results for the test method.
File
- tests/
src/ Unit/ FieldValue/ FieldTargetEntityTest.php, line 33
Class
- FieldTargetEntityTest
- @coversDefaultClass \Drupal\twig_field_value\Twig\Extension\FieldValueExtension @group twig_field_value
Namespace
Drupal\Tests\twig_field_value\Unit\FieldValueCode
protected function mockContentEntity(array $referenced_entities) {
$entities = [];
// Build the 'entity' objects with a property 'entity' that contains the
// referenced entity.
foreach ($referenced_entities as $referenced_entity) {
$entity = new \stdClass();
$entity->entity = $referenced_entity;
$entities[] = $entity;
}
$field_item = $this
->getMockBuilder('Drupal\\Core\\Entity\\ContentEntityBase')
->disableOriginalConstructor()
->getMock();
$field_item
->expects($this
->any())
->method('get')
->will($this
->returnValue($entities));
return $field_item;
}