public function testLoadMetadata() { $this->metadata->getReflectionClass()->willReturn(new \ReflectionClass($this->document->reveal())); $this->metadata->addFieldMapping('redirectType', Argument::any())->shouldBeCalled(); $this->metadata->addFieldMapping('redirectExternal', Argument::any())->shouldBeCalled(); $this->metadata->addFieldMapping('redirectTarget', Argument::any())->shouldBeCalled(); $this->subscriber->handleMetadataLoad($this->event->reveal()); }
public function testPersistWithTypeInternalMissingLink() { $this->setExpectedException(MandatoryPropertyException::class); $locale = 'en'; $encoder = $this->prophesize(PropertyEncoder::class); $factory = $this->prophesize(ProxyFactory::class); $registry = $this->prophesize(DocumentRegistry::class); $subscriber = new RedirectTypeSubscriber($encoder->reveal(), $factory->reveal(), $registry->reveal()); $event = $this->prophesize(PersistEvent::class); $node = $this->prophesize(NodeInterface::class); $document = $this->prophesize(PageDocument::class); $event->getNode()->willReturn($node->reveal()); $event->getDocument()->willReturn($document->reveal()); $event->getLocale()->willReturn($locale); $encoder->localizedSystemName(RedirectTypeSubscriber::REDIRECT_TYPE_FIELD, $locale)->willReturn('i18n:en-nodeType'); $encoder->localizedSystemName(RedirectTypeSubscriber::EXTERNAL_FIELD, $locale)->willReturn('i18n:en-external'); $encoder->localizedSystemName(RedirectTypeSubscriber::INTERNAL_FIELD, $locale)->willReturn('i18n:en-internal_link'); $document->getRedirectType()->willReturn(RedirectType::INTERNAL); $document->getRedirectExternal()->willReturn(null); $document->getRedirectTarget()->willReturn(null); $document->setRedirectType(Argument::any())->shouldNotBeCalled(); $document->setRedirectExternal(Argument::any())->shouldNotBeCalled(); $document->setRedirectTarget(Argument::any())->shouldNotBeCalled(); $node->setProperty('i18n:en-nodeType', RedirectType::INTERNAL, PropertyType::LONG)->shouldBeCalled(); $node->setProperty('i18n:en-external', null)->shouldBeCalled(); $subscriber->doPersist($event->reveal()); }