コード例 #1
0
ファイル: Twitter.php プロジェクト: kinkinweb/lhvb
 /**
  * Add the meta information.
  *
  * @param SeoPageInterface $seoPage
  * @param ProductInterface $product
  */
 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));
     }
 }
コード例 #2
0
 /**
  * @param SeoPageInterface $seoPage
  * @param ProductInterface $product
  */
 public function alterPage(SeoPageInterface $seoPage, ProductInterface $product)
 {
     $this->registerHeaders($seoPage);
     $seoPage->addMeta('property', 'og:type', 'og:product')->addMeta('property', 'og:title', $product->getName())->addMeta('property', 'og:description', $product->getDescription())->addMeta('property', 'og:url', $this->router->generate('sonata_product_view', array('slug' => $product->getSlug(), 'productId' => $product->getId()), true))->addMeta('property', 'product:price:amount', $this->numberHelper->formatDecimal($product->getPrice()))->addMeta('property', 'product:price:currency', $this->currencyDetector->getCurrency());
     // If a media is available, we add the opengraph image data
     if ($image = $product->getImage()) {
         $this->addImageInfo($image, $seoPage);
     }
 }
コード例 #3
0
 public function testArguments()
 {
     $localeDetector = $this->getMock('Sonata\\IntlBundle\\Locale\\LocaleDetectorInterface');
     $localeDetector->expects($this->any())->method('getLocale')->will($this->returnValue('fr'));
     $helper = new NumberHelper('UTF-8', $localeDetector, array('fraction_digits' => 2), array('negative_prefix' => 'MINUS'));
     // Check that the 'default' options are used
     $this->assertEquals('1,34', $helper->formatDecimal(1.337));
     $this->assertEquals('MINUS1,34', $helper->formatDecimal(-1.337));
     // Check that the options are overwritten
     $this->assertEquals('1,337', $helper->formatDecimal(1.337, array('fraction_digits' => 3)));
     $this->assertEquals('MIN1,34', $helper->formatDecimal(-1.337, array(), array('negative_prefix' => 'MIN')));
     // Check that exception are thrown on non-existing class constant
     $exceptionThrown = false;
     try {
         $helper->formatDecimal(1.337, array('non_existant' => 3));
     } catch (\InvalidArgumentException $e) {
         $exceptionThrown = true;
     }
     $this->assertTrue($exceptionThrown);
     $exceptionThrown = false;
     try {
         $helper->formatDecimal(1.337, array(), array('non_existant' => 'MIN'));
     } catch (\InvalidArgumentException $e) {
         $exceptionThrown = true;
     }
     $this->assertTrue($exceptionThrown);
 }
コード例 #4
0
 public function testFormatSpellout()
 {
     $localeDetector = $this->createLocaleDetectorMock();
     $helper = new NumberHelper('UTF-8', $localeDetector);
     $extension = new NumberExtension($helper);
     $this->assertEquals('un', $extension->formatSpellout(1));
     $this->assertEquals('quarante-deux', $extension->formatSpellout(42));
     if (version_compare(NumberHelper::getICUDataVersion(), '52', '>=')) {
         $this->assertEquals('un million deux cent vingt-quatre mille cinq cent cinquante-sept virgule un deux cinq quatre', $extension->formatSpellout(1224557.1254));
     } else {
         $this->assertEquals('un million deux-cent-vingt-quatre-mille-cinq-cent-cinquante-sept virgule un deux cinq quatre', $extension->formatSpellout(1224557.1254));
     }
 }
コード例 #5
0
 /**
  * @param float $number
  * @param array $attributes
  * @param array $textAttributes
  * @param null  $locale
  *
  * @return string
  */
 public function formatOrdinal($number, array $attributes = array(), array $textAttributes = array(), $locale = null)
 {
     return $this->helper->formatOrdinal($number, $attributes, $textAttributes, $locale);
 }
コード例 #6
0
 /**
  * @expectedException \RuntimeException
  */
 public function testExceptionOnInvalidParams()
 {
     // https://wiki.php.net/rfc/internal_constructor_behaviour
     $formatter = new \NumberFormatter('FR', -1);
     $this->assertNull($formatter);
     $localeDetector = $this->getMock('Sonata\\IntlBundle\\Locale\\LocaleDetectorInterface');
     $localeDetector->expects($this->any())->method('getLocale')->will($this->returnValue('fr'));
     $helper = new NumberHelper('UTF-8', $localeDetector, array('fraction_digits' => 2), array('negative_prefix' => 'MINUS'));
     $helper->format(10.49, -1);
 }