/** * @dataProvider getOptionsFixture */ public function testCreateWithOptions(array $options) { $options = array_merge([EmbeddedEntityListAttribute::OPTION_ENTITY_TYPES => [ParagraphType::CLASS]], $options); $embed_attribute = new EmbeddedEntityListAttribute(self::ATTR_NAME, $this->getTypeMock(), $options); $this->assertEquals($embed_attribute->getName(), self::ATTR_NAME); $this->assertEquals($embed_attribute->getName(), self::ATTR_NAME); $this->assertFalse($embed_attribute->hasOption('snafu_flag')); foreach ($options as $optName => $optValue) { $this->assertTrue($embed_attribute->hasOption($optName)); $this->assertEquals($embed_attribute->getOption($optName), $optValue); } }
/** * Generates and adds fake data for a embed entities. * * @param EntityInterface $entity an instance of the entity to fill with fake data. * @param EmbeddedEntityListAttribute $attribute instance of the EmbeddedEntityListAttribute to fill with fake data. * @param array $options array of options to customize fake data creation. * * @return void */ protected function addEmbeddedEntityList(EntityInterface $entity, EmbeddedEntityListAttribute $attribute, array $options = array()) { $options_clone = $options; $entity_collection = new EntityList(); $embedded_type_map = $attribute->getEmbeddedEntityTypeMap(); $min_count = $attribute->getOption('min_count', 0); $max_count = $attribute->getOption('max_count', 3); $inline_mode = $attribute->getOption('inline_mode', false); if (true === $inline_mode) { $number_of_new_embed_entries = 1; } else { $number_of_new_embed_entries = $this->faker->numberBetween($min_count, $max_count); } // add new entities to collection for embed types for ($i = 0; $i < $number_of_new_embed_entries; $i++) { $embed_type = $this->faker->randomElement($embedded_type_map->getValues()); $new_entity = $this->createFakeEntity($embed_type, $options_clone, $entity); $entity_collection->addItem($new_entity); } $this->setValue($entity, $attribute, $entity_collection, $options); }