function it_throws_exception_if_trying_to_render_unsupported_metadata(MetadataRendererInterface $firstRenderer, MetadataRendererInterface $secondRenderer, MetadataInterface $metadata) { $firstRenderer->supports($metadata, ['bar' => 'baz'])->shouldBeCalled()->willReturn(false); $secondRenderer->supports($metadata, ['bar' => 'baz'])->shouldBeCalled()->willReturn(false); $firstRenderer->render(Argument::cetera())->shouldNotBeCalled(); $secondRenderer->render(Argument::cetera())->shouldNotBeCalled(); $this->shouldThrow('\\InvalidArgumentException')->duringRender($metadata, ['bar' => 'baz']); }
/** * @param MetadataSubjectInterface $metadataSubject * @param string|null $propertyPath * @param array $options * * @return string */ public function renderProperty(MetadataSubjectInterface $metadataSubject, $propertyPath = null, array $options = []) { $metadataProperty = $this->metadataAccessor->getProperty($metadataSubject, $propertyPath); if (null === $metadataProperty) { return null; } return $this->metadataRenderer->render($metadataProperty, $options); }
function it_delegates_twitter_metadata_rendering_to_another_renderer(MetadataRendererInterface $universalRenderer, OptionsResolver $optionsResolver, PropertyAccessorInterface $propertyAccessor, PageMetadataInterface $pageMetadata, CardInterface $twitterMetadata) { $optionsResolver->resolve([])->shouldBeCalled()->willReturn($this->defaultOptions); $data = ['twitter' => $twitterMetadata]; $this->setupPropertyAccessor($propertyAccessor, $pageMetadata, $data, $this->defaultOptions); $pageMetadata->toArray()->shouldBeCalled()->willReturn($data); $universalRenderer->render($twitterMetadata)->shouldBeCalled()->willReturn('Rendered Twitter metadata'); $this->render($pageMetadata)->shouldReturn('Rendered Twitter metadata'); }
private function declareSubrenderers() { $this->addSubrenderer('title', function ($value) { return sprintf('<title>%s</title>', $value); }); $this->addSubrenderer(['description', 'author'], function ($value, $key) { return sprintf('<meta name="%s" content="%s" />', $key, $value); }); $this->addSubrenderer('keywords', function ($value) { return sprintf('<meta name="keywords" content="%s" />', implode(', ', $value)); }); $this->addSubrenderer('charset', function ($value) { return sprintf('<meta charset="%s" />', $value); }); $this->addSubrenderer('twitter', function ($value) { return $this->twitterRenderer->render($value); }); }
function it_does_not_proxy_render_property_to_Metadata_Renderer_if_there_is_no_metadata(MetadataAccessorInterface $metadataAccessor, MetadataRendererInterface $metadataRenderer, MetadataSubjectInterface $metadataSubject) { $metadataRenderer->render(Argument::cetera())->shouldNotBeCalled(); $metadataAccessor->getProperty($metadataSubject, 'property')->shouldBeCalled()->willReturn(null); $this->renderProperty($metadataSubject, 'property')->shouldReturn(null); }