You are here

public function WishlistTest::testEdit in Commerce Wishlist 8.3

Tests editing a wishlist.

File

tests/src/Functional/WishlistTest.php, line 102

Class

WishlistTest
Tests the wishlist UI.

Namespace

Drupal\Tests\commerce_wishlist\Functional

Code

public function testEdit() {
  $wishlist = $this
    ->createEntity('commerce_wishlist', [
    'type' => 'default',
    'name' => $this
      ->randomMachineName(8),
    'is_public' => TRUE,
    'keep_purchased_items' => FALSE,
  ]);
  $code = $wishlist
    ->getCode();
  $this
    ->drupalGet($wishlist
    ->toUrl('edit-form'));
  $wishlist_tab_uri = Url::fromRoute('entity.commerce_wishlist_item.collection', [
    'commerce_wishlist' => $wishlist
      ->id(),
  ])
    ->toString();
  $this
    ->assertSession()
    ->linkByHrefExists($wishlist
    ->toUrl('edit-form')
    ->toString());
  $this
    ->assertSession()
    ->linkByHrefExists($wishlist
    ->toUrl('duplicate-form')
    ->toString());
  $this
    ->assertSession()
    ->linkByHrefExists($wishlist_tab_uri);
  $this
    ->submitForm([
    'name[0][value]' => 'Top secret gifts',
    'is_public[value]' => '0',
    'keep_purchased_items[value]' => '1',
  ], 'Save');
  $this
    ->assertSession()
    ->pageTextContains('The wishlist Top secret gifts has been successfully saved');
  \Drupal::service('entity_type.manager')
    ->getStorage('commerce_wishlist')
    ->resetCache([
    $wishlist
      ->id(),
  ]);
  $wishlist = Wishlist::load(1);
  $this
    ->assertEquals('Top secret gifts', $wishlist
    ->getName());
  $this
    ->assertFalse($wishlist
    ->isPublic());
  $this
    ->assertTrue($wishlist
    ->getKeepPurchasedItems());
  $this
    ->assertEmpty($wishlist
    ->hasItems());
  $this
    ->assertEquals($code, $wishlist
    ->getCode());
}