public function testContainsMultipleTypes() { $type = new ArticleType(); $test_entity = $type->createEntity(); $collection = new EntityList([$test_entity]); $this->assertFalse($collection->containsMultipleTypes()); $type2 = new CategoryType(); $test_entity2 = $type2->createEntity(); $collection->addItem($test_entity2); $this->assertTrue($collection->containsMultipleTypes()); }
/** * 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); }