public function WishlistItemTest::testDuplicate in Commerce Wishlist 8.3
Tests duplicating a wishlist item.
File
- tests/
src/ Functional/ WishlistItemTest.php, line 138
Class
- WishlistItemTest
- Tests the wishlist item UI.
Namespace
Drupal\Tests\commerce_wishlist\FunctionalCode
public function testDuplicate() {
$wishlist_item = $this
->createEntity('commerce_wishlist_item', [
'type' => 'commerce_product_variation',
'wishlist_id' => $this->wishList
->id(),
'purchasable_entity' => $this->firstVariation
->id(),
'quantity' => '2',
]);
$this
->drupalGet($wishlist_item
->toUrl('duplicate-form'));
$this
->assertSession()
->pageTextContains('Duplicate Standing desk');
$this
->submitForm([
'purchasable_entity[0][target_id]' => 'Regular desk (2)',
'quantity[0][value]' => '5',
'comment[0][value]' => 'Still regular is cheaper',
], 'Save');
$this
->assertSession()
->pageTextContains('The item Regular desk has been successfully saved.');
\Drupal::service('entity_type.manager')
->getStorage('commerce_wishlist_item')
->resetCache([
$wishlist_item
->id(),
]);
// Confirm that the original wishlist item is unchanged.
$wishlist_item_1 = WishlistItem::load(1);
$this
->assertEquals($this->wishList
->id(), $wishlist_item_1
->getWishListId());
$this
->assertEquals($this->firstVariation
->id(), $wishlist_item_1
->getPurchasableEntityId());
$this
->assertEquals('2', $wishlist_item_1
->getQuantity());
$this
->assertEmpty($wishlist_item_1
->getComment());
// Confirm that the new wishlist item has the expected data.
$wishlist_item_2 = WishlistItem::load(2);
$this
->assertEquals($this->wishList
->id(), $wishlist_item_2
->getWishListId());
$this
->assertEquals($this->secondVariation
->id(), $wishlist_item_2
->getPurchasableEntityId());
$this
->assertEquals('5', $wishlist_item_2
->getQuantity());
$this
->assertNotEmpty($wishlist_item_2
->getComment());
$this
->assertEqual($wishlist_item_2
->getComment(), 'Still regular is cheaper');
}