You are here

public function PriceTwigExtensionTest::testValidPrice in Commerce Core 8.2

Tests passing a valid value.

File

modules/price/tests/src/Kernel/PriceTwigExtensionTest.php, line 41

Class

PriceTwigExtensionTest
Tests the price twig filter.

Namespace

Drupal\Tests\commerce_price\Kernel

Code

public function testValidPrice() {
  $theme = [
    '#theme' => 'commerce_price_test',
    '#price' => [
      'number' => '9.99',
      'currency_code' => 'USD',
    ],
  ];
  $this
    ->render($theme);
  $this
    ->assertText('$9.99');
  $theme = [
    '#theme' => 'commerce_price_test',
    '#price' => new Price('20.99', 'USD'),
  ];
  $this
    ->render($theme);
  $this
    ->assertText('$20.99');
  $theme = [
    '#theme' => 'commerce_price_test',
    '#price' => new Price('20', 'USD'),
    '#options' => [
      'currency_display' => 'code',
      'minimum_fraction_digits' => 0,
    ],
  ];
  $this
    ->render($theme);
  $this
    ->assertNoText('USD20.00');
  $this
    ->assertText('USD20');
}