public function WishlistTest::testDuplicate in Commerce Wishlist 8.3
Tests duplicating a wishlist.
File
- tests/
src/ Functional/ WishlistTest.php, line 137
Class
- WishlistTest
- Tests the wishlist UI.
Namespace
Drupal\Tests\commerce_wishlist\FunctionalCode
public function testDuplicate() {
$wishlist = $this
->createEntity('commerce_wishlist', [
'type' => 'default',
'name' => 'Secret gifts',
'is_public' => TRUE,
'keep_purchased_items' => TRUE,
]);
$this
->drupalGet($wishlist
->toUrl('duplicate-form'));
$this
->assertSession()
->pageTextContains('Duplicate Secret gifts');
$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]' => 'Secret gits duplicated',
'is_public[value]' => '0',
], 'Save');
$this
->assertSession()
->pageTextContains('The wishlist Secret gits duplicated has been successfully saved.');
\Drupal::service('entity_type.manager')
->getStorage('commerce_wishlist')
->resetCache([
$wishlist
->id(),
]);
// Confirm that the original wishlist is unchanged.
$wishlist_1 = Wishlist::load(1);
$this
->assertEquals('Secret gifts', $wishlist_1
->getName());
$this
->assertTrue($wishlist_1
->isPublic());
// Confirm that the new wishlist has the expected data.
$wishlist_2 = Wishlist::load(2);
$this
->assertEquals('Secret gits duplicated', $wishlist_2
->getName());
$this
->assertNotTrue($wishlist_2
->isPublic());
// Check that there is no attached items.
$this
->assertEmpty($wishlist_2
->hasItems());
// Check that codes are different.
$this
->assertNotSame($wishlist_1
->getCode(), $wishlist_2
->getCode());
}