public function WishlistAnonymousTest::testAddWishlist in Commerce Wishlist 8.3
Tests adding wishlist.
File
- tests/
src/ FunctionalJavascript/ WishlistAnonymousTest.php, line 131
Class
- WishlistAnonymousTest
- Tests the wishlist anonymous access.
Namespace
Drupal\Tests\commerce_wishlist\FunctionalJavascriptCode
public function testAddWishlist() {
// Allow adding wishlist for anonymous user.
$wishlist_type = WishlistType::load('default');
$wishlist_type
->setAllowAnonymous(TRUE);
$wishlist_type
->save();
$this
->reloadEntity($wishlist_type);
$this
->drupalLogout();
$this
->drupalGet('product/1');
$this
->getSession()
->getPage()
->hasButton('edit-wishlist');
$this
->getSession()
->getPage()
->findButton('Add to wishlist')
->click();
$this
->assertSession()
->assertWaitOnAjaxRequest();
$this
->drupalGet('wishlist');
$this
->assertSession()
->elementExists('css', 'input[data-drupal-selector="edit-header-add-all-to-cart"]');
$this
->assertSession()
->elementExists('css', 'a[data-drupal-selector="edit-header-share"]');
$this
->assertSession()
->pageTextContains('First variation');
$this
->assertSession()
->pageTextContains('Quantity: 1');
$this
->assertSession()
->elementExists('css', 'a[data-drupal-selector="edit-items-1-details-edit"]');
$this
->assertSession()
->elementExists('css', 'input[name="add-to-cart-1"]');
$this
->assertSession()
->elementExists('css', 'input[name="remove-1"]');
$this
->getSession()
->getPage()
->clickLink('Edit details');
$this
->assertSession()
->assertWaitOnAjaxRequest();
$this
->assertSession()
->buttonExists('Update details');
// Clear session, to verify access for anonymous user which is not owner.
$this
->getSession()
->reset();
$wishlist = Wishlist::load(1);
$this
->assertNotEmpty($wishlist);
$this
->drupalGet($wishlist
->toUrl('user-form'));
$this
->assertSession()
->elementExists('css', 'input[data-drupal-selector="edit-header-add-all-to-cart"]');
$this
->assertSession()
->elementNotExists('css', 'a[data-drupal-selector="edit-header-share"]');
$this
->assertSession()
->pageTextContains('First variation');
$this
->assertSession()
->pageTextContains('Quantity: 1');
$this
->assertSession()
->elementNotExists('css', 'a[data-drupal-selector="edit-items-1-details-edit"]');
$this
->assertSession()
->elementExists('css', 'input[name="add-to-cart-1"]');
$this
->assertSession()
->elementNotExists('css', 'input[name="remove-1"]');
}