You are here

public function PriceListItemTest::testDelete in Commerce Pricelist 8.2

Tests deleting a price list item.

File

tests/src/Functional/PriceListItemTest.php, line 190

Class

PriceListItemTest
Tests the price list item UI.

Namespace

Drupal\Tests\commerce_pricelist\Functional

Code

public function testDelete() {
  $price_list_item = $this
    ->createEntity('commerce_pricelist_item', [
    'type' => 'commerce_product_variation',
    'price_list_id' => $this->priceList
      ->id(),
    'purchasable_entity' => $this->firstVariation
      ->id(),
    'quantity' => '10',
    'price' => new Price('50', 'USD'),
  ]);
  $this
    ->drupalGet($price_list_item
    ->toUrl('delete-form'));
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->pageTextContains('This action cannot be undone.');
  $this
    ->submitForm([], t('Delete'));
  \Drupal::service('entity_type.manager')
    ->getStorage('commerce_pricelist_item')
    ->resetCache([
    $price_list_item
      ->id(),
  ]);
  $price_list_item_exists = (bool) PriceListItem::load($price_list_item
    ->id());
  $this
    ->assertFalse($price_list_item_exists);
}