public function BundleItemOrderItemTest::testBundleItemOrderItem in Commerce Product Bundle 8
@covers ::getTitle @covers ::getCreatedTime @covers ::getQuantity @covers ::getUnitPrice @covers ::getBundleItem @covers ::getPurchasedEntity
File
- tests/
src/ Kernel/ Entity/ BundleItemOrderItemTest.php, line 91
Class
- BundleItemOrderItemTest
- Test the Product Bundle Item entity.
Namespace
Drupal\Tests\commerce_product_bundle\Kernel\EntityCode
public function testBundleItemOrderItem() {
$created = new \DateTime('now');
$bundleItemOrderItem = BundleItemOrderItem::create([
'title' => 'TestTitle',
'created' => $created
->getTimestamp(),
'bundle_item' => $this->productBundleItem,
'purchased_entity' => $this->productVariation,
'unit_price' => new Price('222.33', 'USD'),
'quantity' => '3',
'total_price' => new Price('444.66', 'USD'),
]);
self::assertEquals(new Price('444.66', 'USD'), $bundleItemOrderItem
->getTotalPrice());
$bundleItemOrderItem
->save();
$bundleItemOrderItem = $this
->reloadEntity($bundleItemOrderItem);
// Wether the total gets recalculation on presave.
self::assertEquals(new Price('666.99', 'USD'), $bundleItemOrderItem
->getTotalPrice());
self::assertEquals('TestTitle', $bundleItemOrderItem
->getTitle());
$priceToTest = $bundleItemOrderItem
->getUnitPrice();
self::assertEquals(new Price('222.33', 'USD'), $priceToTest);
self::assertEquals('222.33', $priceToTest
->getNumber());
self::assertEquals('USD', $priceToTest
->getCurrencyCode());
$price = new Price('55.55', 'USD');
$bundleItemOrderItem
->setUnitPrice($price);
self::assertEquals($price, $bundleItemOrderItem
->getUnitPrice());
self::assertEquals('55.55', $price
->getNumber());
self::assertEquals('USD', $price
->getCurrencyCode());
self::assertEquals(new Price('166.65', 'USD'), $bundleItemOrderItem
->getTotalPrice());
self::assertEquals($created
->getTimestamp(), $bundleItemOrderItem
->getCreatedTime());
self::assertEquals('3', $bundleItemOrderItem
->getQuantity());
self::assertEquals($this->productVariation
->id(), $bundleItemOrderItem
->getPurchasedEntityId());
self::assertEquals($this->productBundleItem
->id(), $bundleItemOrderItem
->getBundleItem()
->id());
}