/** * Render with the current document * @return string */ public function render() { if ($this->document) { // This gets us the document in the api browser: $url = $this->document->getHref(); /** * This is wrong. The URL is: * https://repo.prismic.io/documents~id=:id */ $url = parse_url($url); $url = sprintf('%s://%s/documents~id=%s', $url['scheme'], $url['host'], $this->document->getId()); return sprintf($this->template, $url, $this->linkText); } return ''; }
public function setUp() { $this->setApplicationConfig(include __DIR__ . '/../../TestConfig.php.dist'); parent::setUp(); $json = json_decode(file_get_contents(__DIR__ . '/../../fixtures/document.json')); $this->document = \Prismic\Document::parse($json); }
public function testSlices() { $response = json_decode(file_get_contents(__DIR__ . '/../fixtures/slices.json')); $document = Document::parse($response->results[0]); $slices = $document->getSliceZone('article.blocks'); $this->assertEquals($slices->asText(), "C'est un bloc content"); $this->assertEquals($slices->asHtml(), '<div data-slicetype="features" class="slice"><div class="group-doc"><section data-field="illustration"><img src="https://wroomdev.s3.amazonaws.com/toto/db3775edb44f9818c54baa72bbfc8d3d6394b6ef_hsf_evilsquall.jpg" alt="" width="4285" height="709"></section><section data-field="title"><span class="text">c\'est un bloc features</span></section></div></div><div data-slicetype="text" class="slice"><p>C\'est un bloc content</p></div>'); }
protected function setUp() { $cache = new ApcCache(); $cache->clear(); $search = json_decode(file_get_contents(__DIR__ . '/../fixtures/search.json')); $this->document = Document::parse($search[0]); $this->micro_api = Api::get(self::$testRepository, null, null, $cache); $this->linkResolver = new FakeLinkResolver(); }
protected function setUp() { $search = json_decode(file_get_contents(__DIR__ . '/../fixtures/search.json')); $document = Document::parse($search[0]); $gallery = $document->get('product.gallery'); $views = array_values($gallery->getViews()); $views[] = $gallery->getMain(); foreach ($document->getStructuredText('product.linked_images')->getImages() as $image) { $views[] = $image->getView(); } $this->input = array(); $this->linkResolver = new FakeLinkResolver(); foreach ($views as $view) { $dom = new DOMDocument(); $this->input[] = array('view' => $view, 'parsed' => $dom->loadHTML($view->asHtml($this->linkResolver)), 'dom' => $dom); } }
public function testNestedSpans() { $json = json_decode(file_get_contents(__DIR__ . '/../fixtures/nested.json')); $document = Document::parse($json[0]); $structuredText = $document->getStructuredText('article.content'); $this->assertEquals('<p><em><strong>SOME Thingyy</strong></em><em>:</em> <em>12345678</em></p>', $structuredText->asHtml()); }
public function testGeoPoint() { $json = "{\"id\":\"abcd\",\"type\":\"article\",\"href\":\"\",\"slugs\":[],\"tags\":[],\"data\":{\"article\":{\"location\":{\"type\":\"GeoPoint\",\"value\":{\"latitude\":48.877108,\"longitude\":2.333879}}}}}"; $doc = Document::parse(json_decode($json)); // startgist:4a4024327fc8454bc809:prismic-geopoint.php // "near" predicate for GeoPoint fragments $near = Predicates::near("my.store.location", 48.8768767, 2.3338802, 10); // Accessing GeoPoint fragments $place = $doc->getGeoPoint("article.location"); $coordinates = ""; if ($place) { $coordinates = $place->getLatitude() . "," . $place->getLongitude(); } // endgist $this->assertEquals("48.877108,2.333879", $coordinates); }
/** * Parses a list of subfragments, and makes it into an associative array of fragments. * Not meant to be used except for testing. * * @param \stdClass $json the json bit retrieved from the API that represents the list of subfragments * @return array the array of subfragments */ public static function parseSubfragmentList($json) { $subfragments = array(); foreach ($json as $subfragment_name => $subfragmentJson) { $subfragment = Document::parseFragment($subfragmentJson); if (isset($subfragment)) { $subfragments[$subfragment_name] = $subfragment; } } return new GroupDoc($subfragments); }
/** * @param Document $doc * @return \stdClass */ private function getNodeData(Document $doc) { $node = new \stdClass(); $node->{'jcr:primaryType'} = 'prismic:' . $doc->getType(); $node->{':jcr:primaryType'} = PropertyType::STRING; $node->{'jcr:mixinTypes'} = array('mix:referenceable'); $node->{':jcr:mixinTypes'} = PropertyType::STRING; $node->{'jcr:uuid'} = $doc->getId(); $node->{':jcr:uuid'} = PropertyType::NAME; $node->slug = $doc->getSlug(); $node->{':slug'} = PropertyType::STRING; $node->slugs = (array) $doc->getSlugs(); $node->{':slugs'} = PropertyType::STRING; $node->tags = (array) $doc->getTags(); $node->{':tags'} = PropertyType::STRING; foreach ($doc->getFragments() as $name => $fragment) { // TODO model StructuredText/ImageView/Embed/Group etc. as children switch (get_class($fragment)) { case 'Prismic\\Fragment\\Date': $node->{$name} = $fragment->asText(); $node->{":{$name}"} = PropertyType::DATE; break; case 'Prismic\\Fragment\\Number': $node->{$name} = $fragment->asText(); $node->{":{$name}"} = PropertyType::LONG; break; case 'Prismic\\Fragment\\Image': $node->{$name} = $fragment->asText(); $node->{":{$name}"} = PropertyType::BINARY; break; case 'Prismic\\Fragment\\ImageView': $node->{":{$name}"} = PropertyType::URI; $node->{$name} = $fragment->getUrl(); break; default: $node->{$name} = $fragment->asText(); $node->{":{$name}"} = PropertyType::STRING; } } return $node; }
public function getDocument() { $json = json_decode(file_get_contents(__DIR__ . '/../../../fixtures/document.json')); return \Prismic\Document::parse($json); }
/** * @param Document $doc * * @return string */ public function resolveLink(Document $doc) { $link = new DocumentLink($doc->getId(), $doc->getType(), $doc->getTags(), $doc->getSlug(), false); return $this->getLinkResolver()->resolve($link); }
/** * Given a Prismic document, return an array suitable for generating a sitemap entry or null * @param Document $document * @return array|null */ protected function documentToArray(Document $document) { $type = $document->getType(); $data = array(); /** * If we can't work out the href from the link resolver, we're screwed */ $link = $this->linkGenerator->generate($document); $url = null; try { $url = $this->linkResolver->resolve($link); } catch (RoutingException $e) { // Likely, this URL needs additional parameters to be assembled } if (!$url) { return null; } $data['uri'] = $url; foreach ($this->propertyMap as $property => $fragment) { if (empty($fragment)) { continue; } $fragment = sprintf('%s.%s', $type, $fragment); $frag = $document->get($fragment); if ($frag) { $data[$property] = $frag->asText(); } } return $data; }
/** * @depends testDocumentIsAvailable */ public function testDocumentHasGroupFragment(Document $doc) { $fragment = $doc->get('article.group_frag'); $this->assertInstanceOf('\\Prismic\\Fragment\\Group', $fragment); return $fragment; }
public function setUp() { $json = json_decode(file_get_contents(__DIR__ . '/../../../fixtures/document.json')); $this->document = \Prismic\Document::parse($json); }
/** * This method convert a document into document link * * @param Document $document The document * * @return DocumentLink The document link */ private function asLink($document) { return new DocumentLink($document->getId(), $document->getUid(), $document->getType(), $document->getTags(), $document->getSlug(), $document->getFragments(), false); }
/** * Return a new link instance to the given Document * @param Document $doc * @return DocumentLink */ public function getDocumentLink(Document $doc) { return new DocumentLink($doc->getId(), $doc->getUid(), $doc->getType(), $doc->getTags(), $doc->getSlug(), array(), false); }