public function WishlistTest::testAddMultiple in Commerce Wishlist 8.3
Tests adding multiple wishlist.
File
- tests/
src/ Functional/ WishlistTest.php, line 49
Class
- WishlistTest
- Tests the wishlist UI.
Namespace
Drupal\Tests\commerce_wishlist\FunctionalCode
public function testAddMultiple() {
$this
->drupalGet(Url::fromRoute('entity.commerce_wishlist.collection')
->toString());
$this
->clickLink('Add wishlist');
$this
->submitForm([
'name[0][value]' => 'Special desire',
'is_public[value]' => '1',
'keep_purchased_items[value]' => '1',
], 'Save');
$this
->assertSession()
->pageTextContains('The wishlist Special desire has been successfully saved.');
$wishlist = Wishlist::load(1);
$this
->assertEquals('Special desire', $wishlist
->getName());
$this
->assertTrue($wishlist
->isPublic());
$this
->assertTrue($wishlist
->getKeepPurchasedItems());
$this
->assertEmpty($wishlist
->getItems());
$this
->assertNotEmpty($wishlist
->getCode());
// Add second wishlist.
$this
->drupalGet(Url::fromRoute('entity.commerce_wishlist.collection')
->toString());
$this
->clickLink('Add wishlist');
$this
->submitForm([
'name[0][value]' => 'Special desire 2',
'is_public[value]' => '1',
'keep_purchased_items[value]' => '1',
], 'Save');
$this
->assertSession()
->pageTextContains('The wishlist Special desire 2 has been successfully saved.');
$wishlist = Wishlist::load(2);
$this
->assertEquals('Special desire 2', $wishlist
->getName());
$this
->assertTrue($wishlist
->isPublic());
$this
->assertTrue($wishlist
->getKeepPurchasedItems());
$this
->assertEmpty($wishlist
->getItems());
$this
->assertNotEmpty($wishlist
->getCode());
// Change settings and don't allow multiple wishlists.
$this
->config('commerce_wishlist.settings')
->set('allow_multiple', 0)
->save();
$this
->drupalGet(Url::fromRoute('entity.commerce_wishlist.collection')
->toString());
$this
->clickLink('Add wishlist');
$this
->submitForm([
'name[0][value]' => 'Special desire 3',
'is_public[value]' => '1',
'keep_purchased_items[value]' => '1',
], 'Save');
$this
->assertSession()
->pageTextContains('Cannot create a new wishlist (Only a single wishlist per customer is allowed).');
}