You are here

public function PriceListItemTest::testPriceListItem in Commerce Pricelist 8.2

@covers ::getPriceList @covers ::getPriceListId @covers ::getPurchasableEntity @covers ::setPurchasableEntity @covers ::getPurchasableEntityId @covers ::setPurchasableEntityId @covers ::getQuantity @covers ::setQuantity @covers ::getListPrice @covers ::setListPrice @covers ::getPrice @covers ::setPrice @covers ::isEnabled @covers ::setEnabled

File

tests/src/Kernel/Entity/PriceListItemTest.php, line 83

Class

PriceListItemTest
Tests the price list item entity.

Namespace

Drupal\Tests\commerce_pricelist\Kernel\Entity

Code

public function testPriceListItem() {
  $price_list_item = PriceListItem::create([
    'type' => 'commerce_product_variation',
    'price_list_id' => $this->priceList
      ->id(),
  ]);
  $this
    ->assertEquals($this->priceList, $price_list_item
    ->getPriceList());
  $this
    ->assertEquals($this->priceList
    ->id(), $price_list_item
    ->getPriceListId());
  $price_list_item
    ->setPurchasableEntity($this->variation);
  $this
    ->assertEquals($this->variation, $price_list_item
    ->getPurchasableEntity());
  $price_list_item
    ->set('purchasable_entity', NULL);
  $price_list_item
    ->setPurchasableEntityId($this->variation
    ->id());
  $this
    ->assertEquals($this->variation
    ->id(), $price_list_item
    ->getPurchasableEntityId());
  $price_list_item
    ->setQuantity('10');
  $this
    ->assertEquals('10', $price_list_item
    ->getQuantity());
  $list_price = new Price('11', 'USD');
  $price_list_item
    ->setListPrice($list_price);
  $this
    ->assertEquals($list_price, $price_list_item
    ->getListPrice());
  $price = new Price('9', 'USD');
  $price_list_item
    ->setPrice($price);
  $this
    ->assertEquals($price, $price_list_item
    ->getPrice());
  $this
    ->assertTrue($price_list_item
    ->isEnabled());
  $price_list_item
    ->setEnabled(FALSE);
  $this
    ->assertFalse($price_list_item
    ->isEnabled());
}