You are here

public function WishlistItemTest::testEdit in Commerce Wishlist 8.3

Tests editing a wishlist item.

File

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

Class

WishlistItemTest
Tests the wishlist item UI.

Namespace

Drupal\Tests\commerce_wishlist\Functional

Code

public function testEdit() {
  $wishlist_item = $this
    ->createEntity('commerce_wishlist_item', [
    'type' => 'commerce_product_variation',
    'wishlist_id' => $this->wishList
      ->id(),
    'purchasable_entity' => $this->firstVariation
      ->id(),
    'quantity' => '1',
  ]);
  $this
    ->drupalGet($wishlist_item
    ->toUrl('edit-form'));
  $this
    ->submitForm([
    'purchasable_entity[0][target_id]' => 'Regular desk (2)',
    'quantity[0][value]' => '5',
    'comment[0][value]' => 'My updated comment',
  ], 'Save');
  $this
    ->assertSession()
    ->pageTextNotContains('The item Regular desk has been successfully saved.');
  \Drupal::service('entity_type.manager')
    ->getStorage('commerce_wishlist_item')
    ->resetCache([
    $wishlist_item
      ->id(),
  ]);
  $wishlist_item = WishlistItem::load(1);

  // It is not possible to change product variation on edit.
  $this
    ->assertNotEquals($this->secondVariation
    ->id(), $wishlist_item
    ->getPurchasableEntityId());
  $this
    ->assertEqual($wishlist_item
    ->getComment(), 'My updated comment');
  $this
    ->assertEquals('5', $wishlist_item
    ->getQuantity());
}