You are here

public function CommerceWishlistTest::testCommerceWishlistAnonymousUi in Commerce Wishlist 7.3

Anonymous usage of the Wish list module.

File

./commerce_wishlist.test, line 183
Tests for Commerce Wishlist.

Class

CommerceWishlistTest
Testing commerce wishlist UI and functionality.

Code

public function testCommerceWishlistAnonymousUi() {
  $this
    ->drupalLogout();

  // Load a product page.
  $this
    ->drupalGet('node/' . $this->productNode->nid);

  // Make sure Add to Wishlist is on the page.
  $this
    ->assertRaw('Add to Wishlist');

  // Submit the button.
  $edit = array(
    'product_id' => 1,
  );
  $this
    ->drupalPost($this
    ->getUrl(), $edit, t('Add to Wishlist'));
  $message = t('Please <a href="@login">log in</a> or <a href="@register">register</a> to add this product to your wish list.', array(
    '@login' => url('user/login', array(
      'query' => array(
        'destination' => 'node/1',
      ),
    )),
    '@register' => url('user/register'),
  ));
  $this
    ->assertRaw($message, t('Error adding to wish list displayed.'));
  $this
    ->drupalLogin($this->storeCustomer);
  $message = t('Product <em>@product</em> has been added to <a href="@url">your wish list</a>.', array(
    '@product' => $this->product->title,
    '@url' => url('user/' . $this->storeCustomer->uid . '/wishlist', array(
      'absolute' => TRUE,
    )),
  ));
  $this
    ->assertRaw($message, t('Product added to wish list after login.'));
  $this
    ->drupalLogout();

  // Check to see if the error will show when we try to add it again.
  $this
    ->drupalGet('node/' . $this->productNode->uid);

  // Make sure Add to Wishlist is on the page.
  $this
    ->assertRaw('Add to Wishlist');

  // Submit the button.
  $edit = array(
    'product_id' => 1,
  );
  $this
    ->drupalPost($this
    ->getUrl(), $edit, t('Add to Wishlist'));
  $message = t('Please <a href="@login">log in</a> or <a href="@register">register</a> to add this product to your wish list.', array(
    '@login' => url('user/login', array(
      'query' => array(
        'destination' => 'node/1',
      ),
    )),
    '@register' => url('user/register'),
  ));
  $this
    ->assertRaw($message, t('Error adding to wish list displayed.'));
  $this
    ->drupalLogin($this->storeCustomer);
  $message = t('Product <em>@product</em> was already in <a href="@url">your wish list</a>.', array(
    '@product' => $this->product->title,
    '@url' => url('user/' . $this->storeCustomer->uid . '/wishlist', array(
      'absolute' => TRUE,
    )),
  ));
  $this
    ->assertRaw($message, t('Product was already in the wish list.'));
  $this
    ->drupalGet('node/' . $this->productNode2->nid);
  $this
    ->assertRaw('Add to Wishlist');
  $edit = array(
    'product_id' => 2,
  );
  $this
    ->drupalPost($this
    ->getUrl(), $edit, t('Add to Wishlist'));
  $message = t('Product <em>@product</em> has been added to <a href="@url">your wish list</a>.', array(
    '@product' => $this->product2->title,
    '@url' => url('user/' . $this->storeCustomer->uid . '/wishlist', array(
      'absolute' => TRUE,
    )),
  ));
  $this
    ->assertRaw($message, t('Product added to wish list after login.'));
  $this
    ->drupalGet('user/' . $this->storeCustomer->uid . '/wishlist');
  $this
    ->assertText('Product One', t('Product one is listed.'));
  $this
    ->assertText('Product Two', t('Product two is listed.'));
}