public function PriceCalculatedFormatterTest::testRender in Commerce Core 8.2
Tests the rendered output.
File
- modules/
order/ tests/ src/ Kernel/ Formatter/ PriceCalculatedFormatterTest.php, line 131
Class
- PriceCalculatedFormatterTest
- Tests the calculated price formatter.
Namespace
Drupal\Tests\commerce_order\Kernel\FormatterCode
public function testRender() {
$variation_display = commerce_get_entity_display('commerce_product_variation', 'default', 'view');
$variation_display
->setComponent('price', [
'label' => 'above',
'type' => 'commerce_price_calculated',
'settings' => [],
]);
$variation_display
->save();
$variation_build = $this->viewBuilder
->view($this->firstVariation);
$this
->render($variation_build);
$this
->assertEscaped('$3.00');
$variation_build = $this->viewBuilder
->view($this->secondVariation);
$this
->render($variation_build);
$this
->assertEscaped('$4.00');
$variation_display
->setComponent('price', [
'label' => 'above',
'type' => 'commerce_price_calculated',
'settings' => [
'adjustment_types' => [
'tax' => 'tax',
],
],
]);
$variation_display
->save();
$variation_build = $this->viewBuilder
->view($this->firstVariation);
$this
->render($variation_build);
$this
->assertEscaped('$3.60');
// The test commerce-price-calculated template outputs the adjustments as
// well.
$this
->assertEscaped('Tax: $0.60');
$variation_build = $this->viewBuilder
->view($this->secondVariation);
$this
->render($variation_build);
$this
->assertEscaped('$4.80');
$this
->assertEscaped('Tax: $0.80');
$variation_display
->setComponent('price', [
'label' => 'above',
'type' => 'commerce_price_calculated',
'settings' => [
'adjustment_types' => [
'tax' => 'tax',
'promotion' => 'promotion',
],
],
]);
$variation_display
->save();
$variation_build = $this->viewBuilder
->view($this->firstVariation);
$this
->render($variation_build);
$this
->assertEscaped('$1.80');
$this
->assertEscaped('Discount: -$1.80');
$this
->assertEscaped('Tax: $0.60');
$variation_build = $this->viewBuilder
->view($this->secondVariation);
$this
->render($variation_build);
$this
->assertEscaped('$2.40');
$this
->assertEscaped('Discount: -$2.40');
$this
->assertEscaped('Tax: $0.80');
}