public function testValueChangedEvents() { $listener = Mockery::mock(ValueChangedListenerInterface::CLASS); $listener->shouldReceive('onValueChanged')->with(ValueChangedEvent::CLASS)->twice(); $article_type = $this->getTypeMock(); $embed_type = new ParagraphType($article_type, $article_type->getAttribute('content_objects')); $embedd_entity = $embed_type->createEntity(['title' => 'Hello world', 'content' => 'Foobar lorem ipsum...']); $embed_attribute = new EmbeddedEntityListAttribute(self::ATTR_NAME, $this->getTypeMock(), [EmbeddedEntityListAttribute::OPTION_ENTITY_TYPES => [ParagraphType::CLASS]]); $value = $embed_attribute->createValueHolder(); $value->addValueChangedListener($listener); $entity_list = $value->getValue(); $entity_list->push($embedd_entity); $embedd_entity->setValue('title', 'Kthxbye'); $this->assertInstanceOf(EntityList::CLASS, $entity_list); $this->assertEquals(1, $entity_list->getSize()); }
/** * @dataProvider getEmbedFixture */ public function testCreateValue(array $embed_data) { $embed_attribute = new EmbeddedEntityListAttribute(self::ATTR_NAME, $this->getTypeMock(), [EmbeddedEntityListAttribute::OPTION_ENTITY_TYPES => [ParagraphType::CLASS]]); $value = $embed_attribute->createValueHolder(); $this->assertInstanceOf(EmbeddedEntityListValueHolder::CLASS, $value); $value->setValue($embed_data); $entity = $value->getValue()->getFirst(); $this->assertInstanceOf(Paragraph::CLASS, $entity); foreach ($embed_data[0] as $attribute_name => $value) { if ($attribute_name === '@type') { $this->assertEquals($value, $entity->getType()->getPrefix()); } else { $this->assertEquals($value, $entity->getValue($attribute_name)); } } }