You are here

public function ProductCacheTest::testCache in Commerce Pricelist 8.2

Tests the caching.

File

tests/src/Functional/ProductCacheTest.php, line 103

Class

ProductCacheTest
Tests the interaction between price lists and product caches.

Namespace

Drupal\Tests\commerce_pricelist\Functional

Code

public function testCache() {
  $collection_url = Url::fromRoute('entity.commerce_pricelist_item.collection', [
    'commerce_pricelist' => $this->priceList
      ->id(),
  ]);
  $this
    ->drupalGet(Url::fromRoute('entity.commerce_product.canonical', [
    'commerce_product' => $this->product
      ->id(),
  ]));

  // We expect the page to contain the original price at this point.
  $this
    ->assertSession()
    ->pageTextContains('$12.00');
  $this
    ->drupalGet($collection_url
    ->toString());
  $this
    ->clickLink('Add price');
  $this
    ->submitForm([
    'purchasable_entity[0][target_id]' => 'Red shirt (1)',
    'quantity[0][value]' => '1',
    'price[0][number]' => 5,
  ], 'Save');
  $this
    ->assertSession()
    ->pageTextContains('Saved the Red shirt: $5.00 price.');
  $price_list_item = PriceListItem::load(1);
  $this
    ->assertEquals($this->priceList
    ->id(), $price_list_item
    ->getPriceListId());
  $this
    ->assertEquals($this->variation
    ->id(), $price_list_item
    ->getPurchasableEntityId());
  $this
    ->assertEquals('1', $price_list_item
    ->getQuantity());
  $this
    ->assertEquals(new Price('5', 'USD'), $price_list_item
    ->getPrice());
  $this
    ->drupalGet(Url::fromRoute('entity.commerce_product.canonical', [
    'commerce_product' => $this->product
      ->id(),
  ]));
  $this
    ->assertSession()
    ->pageTextContains('$5.00');
}