/**
  * It can deserialize persisted documents with routes.
  */
 public function testDeserializationPersisted()
 {
     $page = $this->createPage(['title' => 'Hello']);
     $this->manager->persist($page, 'de');
     $this->manager->flush();
     $result = $this->serializer->serialize($page, 'json');
     $page = $this->serializer->deserialize($result, PageDocument::class, 'json');
     $this->assertInstanceOf(PageDocument::class, $page);
     $this->assertEquals('Hello', $page->getStructure()->getProperty('title')->getValue());
     $this->assertEquals('de', $this->registry->getOriginalLocaleForDocument($page));
 }
 /**
  * It should update the locale if the requested locale is different from the loaded locale.
  */
 public function testUpdateDocumentLocale()
 {
     $locale = 'de';
     $originalLocale = 'fr';
     $this->hydrateEvent->hasDocument()->willReturn(true);
     $this->hydrateEvent->getLocale()->willReturn($locale);
     $this->hydrateEvent->getDocument()->willReturn($this->document);
     $this->registry->isHydrated($this->document)->willReturn(true);
     $this->registry->getOriginalLocaleForDocument($this->document)->willReturn($originalLocale);
     $this->hydrateEvent->stopPropagation()->shouldNotBeCalled();
     $this->registry->updateLocale($this->document, $locale, $locale)->shouldBeCalled();
     $this->subscriber->handleStopPropagationAndResetLocale($this->hydrateEvent->reveal());
 }
 /**
  * Stop propagation if the document is already loaded in the requested locale,
  * otherwise reset the document locale to the new locale.
  *
  * @param HydrateEvent $event
  */
 public function handleStopPropagationAndResetLocale(HydrateEvent $event)
 {
     if (!$event->hasDocument()) {
         return;
     }
     $locale = $event->getLocale();
     $document = $event->getDocument();
     $originalLocale = $this->documentRegistry->getOriginalLocaleForDocument($document);
     if (true === $this->documentRegistry->isHydrated($document) && $originalLocale === $locale) {
         $event->stopPropagation();
         return;
     }
     $this->documentRegistry->updateLocale($document, $locale, $locale);
 }
 /**
  * Create a new collection of referrers from a list of referencing items.
  *
  * @param $document
  *
  * @return ReferrerCollection
  */
 public function createReferrerCollection($document)
 {
     $node = $this->registry->getNodeForDocument($document);
     $locale = $this->registry->getOriginalLocaleForDocument($document);
     return new ReferrerCollection($node, $this->dispatcher, $locale);
 }
 /**
  * Return the original (requested) locale for the given document.
  *
  * @param object $document
  *
  * @return string
  */
 public function getOriginalLocale($document)
 {
     return $this->documentRegistry->getOriginalLocaleForDocument($document);
 }