PriceEqualsTest.php in Commerce Core 8.2
File
modules/price/tests/src/Kernel/PriceEqualsTest.php
View source
<?php
namespace Drupal\Tests\commerce_price\Kernel;
use Drupal\commerce_price\Price;
use Drupal\commerce_product\Entity\ProductVariation;
use Drupal\Tests\commerce\Kernel\CommerceKernelTestBase;
class PriceEqualsTest extends CommerceKernelTestBase {
public static $modules = [
'commerce_price_test',
'commerce_product',
];
protected $variation1;
protected $variation2;
protected function setUp() : void {
parent::setUp();
$this
->installEntitySchema('commerce_product_attribute');
$this
->installEntitySchema('commerce_product_attribute_value');
$this
->installEntitySchema('commerce_product_variation');
$this
->installEntitySchema('commerce_product');
$this
->installConfig([
'commerce_product',
]);
}
public function testPriceItemListEquals() {
$variation1 = ProductVariation::create([
'type' => 'default',
'sku' => strtolower($this
->randomMachineName()),
'price' => new Price('12.00', 'USD'),
]);
$variation1
->save();
$variation2 = ProductVariation::create([
'type' => 'default',
'sku' => 'TEST_' . strtolower($this
->randomMachineName()),
'price' => new Price('12', 'USD'),
]);
$variation2
->save();
$this
->assertTrue($variation1
->get('price')
->equals($variation2
->get('price')));
}
public function testPriceItemListNotEquals() {
$variation1 = ProductVariation::create([
'type' => 'default',
'sku' => strtolower($this
->randomMachineName()),
'price' => new Price('13.00', 'USD'),
]);
$variation1
->save();
$variation2 = ProductVariation::create([
'type' => 'default',
'sku' => 'TEST_' . strtolower($this
->randomMachineName()),
'price' => new Price('12', 'USD'),
]);
$variation2
->save();
$this
->assertFalse($variation1
->get('price')
->equals($variation2
->get('price')));
}
}