public alterPage ( Sonata\SeoBundle\Seo\SeoPageInterface $seoPage, Sonata\Component\Product\ProductInterface $product ) | ||
$seoPage | Sonata\SeoBundle\Seo\SeoPageInterface | |
$product | Sonata\Component\Product\ProductInterface |
public function alterPage(SeoPageInterface $seoPage, ProductInterface $product)
{
$seoPage->addMeta('name', 'twitter:card', 'product')->addMeta('name', 'twitter:title', $product->getName())->addMeta('name', 'twitter:description', substr($product->getDescription(), 0, 200))->addMeta('name', 'twitter:label1', 'Price')->addMeta('name', 'twitter:data1', $this->numberHelper->formatCurrency($product->getPrice(), $this->currencyDetector->getCurrency()))->addMeta('name', 'twitter:label2', 'SKU')->addMeta('name', 'twitter:data2', $product->getSku())->addMeta('name', 'twitter:site', $this->site)->addMeta('name', 'twitter:creator', $this->creator)->addMeta('name', 'twitter:domain', $this->domain);
if ($image = $product->getImage()) {
$provider = $this->mediaPool->getProvider($image->getProviderName());
$seoPage->addMeta('property', 'twitter:image:src', $provider->generatePublicUrl($image, $this->mediaFormat));
}
}
public function testAlterPage() { $mediaPool = $this->getMockBuilder('Sonata\\MediaBundle\\Provider\\Pool')->disableOriginalConstructor()->getMock(); $seoPage = new SeoPage('test'); $extension = new SeoExtension($seoPage, 'UTF-8'); $numberHelper = $this->getMockBuilder('Sonata\\IntlBundle\\Templating\\Helper\\NumberHelper')->disableOriginalConstructor()->getMock(); $currencyDetector = $this->getMockBuilder('Sonata\\Component\\Currency\\CurrencyDetectorInterface')->disableOriginalConstructor()->getMock(); $product = new ProductTwitterMock(); $twitterService = new Twitter($mediaPool, $numberHelper, $currencyDetector, 'test', 'test', 'test', 'test', 'reference'); ob_start(); $twitterService->alterPage($seoPage, $product, null); $extension->renderMetadatas(); $content = ob_get_contents(); ob_end_clean(); $this->assertContains('twitter:label1', $content); $this->assertNotContains('twitter:image:src', $content); }