You are here

public function WishlistItemTest::testDelete in Commerce Wishlist 8.3

Tests deleting a wishlist item.

File

tests/src/Functional/WishlistItemTest.php, line 174

Class

WishlistItemTest
Tests the wishlist item UI.

Namespace

Drupal\Tests\commerce_wishlist\Functional

Code

public function testDelete() {
  $wishlist_item = $this
    ->createEntity('commerce_wishlist_item', [
    'type' => 'commerce_product_variation',
    'wishlist_id' => $this->wishList
      ->id(),
    'purchasable_entity' => $this->firstVariation
      ->id(),
    'quantity' => '1',
    'comment' => 'You are gonna delete me',
  ]);
  $this
    ->drupalGet($wishlist_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_wishlist_item')
    ->resetCache([
    $wishlist_item
      ->id(),
  ]);
  $wishlist_item_exists = (bool) WishlistItem::load($wishlist_item
    ->id());
  $this
    ->assertFalse($wishlist_item_exists);
}