PriceTwigExtensionTest.php in Commerce Core 8.2
File
modules/price/tests/src/Kernel/PriceTwigExtensionTest.php
View source
<?php
namespace Drupal\Tests\commerce_price\Kernel;
use Drupal\commerce_price\Price;
use Drupal\Tests\commerce\Kernel\CommerceKernelTestBase;
class PriceTwigExtensionTest extends CommerceKernelTestBase {
public static $modules = [
'commerce_price_test',
];
public function testInvalidPrice() {
$theme = [
'#theme' => 'commerce_price_test',
'#price' => [
'numb' => '9.99',
'currency_co' => 'USD',
],
];
$this
->expectException('InvalidArgumentException');
$this
->render($theme);
}
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');
}
public function testEmptyPrice() {
$theme = [
'#theme' => 'commerce_price_test',
];
$this
->render($theme);
$this
->assertText('N/A');
}
}