You are here

public function PriceFormattersTest::testDefaultFormatter in Commerce Core 8.2

Tests the default formatter.

File

modules/price/tests/src/Kernel/PriceFormattersTest.php, line 92

Class

PriceFormattersTest
Tests price formatters provided by Price module.

Namespace

Drupal\Tests\commerce_price\Kernel

Code

public function testDefaultFormatter() {
  $this->productVariationDefaultDisplay
    ->setComponent('list_price', [
    'type' => 'commerce_price_default',
    'settings' => [],
  ]);
  $this->productVariationDefaultDisplay
    ->setComponent('price', [
    'type' => 'commerce_price_default',
    'settings' => [],
  ]);
  $this->productVariationDefaultDisplay
    ->save();
  $build = $this->productVariationViewBuilder
    ->viewField($this->variation1->list_price, 'default');
  $this
    ->render($build);
  $this
    ->assertText('$14.00');
  $build = $this->productVariationViewBuilder
    ->viewField($this->variation1->price, 'default');
  $this
    ->render($build);
  $this
    ->assertText('$12.00');
  $this->productVariationDefaultDisplay
    ->setComponent('list_price', [
    'type' => 'commerce_price_default',
    'settings' => [
      'currency_display' => 'code',
    ],
  ]);
  $this->productVariationDefaultDisplay
    ->setComponent('price', [
    'type' => 'commerce_price_default',
    'settings' => [
      'currency_display' => 'code',
    ],
  ]);
  $this->productVariationDefaultDisplay
    ->save();
  $build = $this->productVariationViewBuilder
    ->viewField($this->variation2->list_price, 'default');
  $this
    ->render($build);
  $this
    ->assertText('USD26.00');
  $build = $this->productVariationViewBuilder
    ->viewField($this->variation2->price, 'default');
  $this
    ->render($build);
  $this
    ->assertText('USD24.00');
}