You are here

public function CommerceWishlistTest::testCommerceWishlistUi in Commerce Wishlist 7.3

Access to Commerce wish list admin.

File

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

Class

CommerceWishlistTest
Testing commerce wishlist UI and functionality.

Code

public function testCommerceWishlistUi() {

  // Login with store admin.
  $this
    ->drupalLogin($this->storeAdmin);

  // Check the access to the profiles listing.
  $this
    ->drupalGet('admin/commerce/config/wishlist');
  $this
    ->assertResponse(200, 'The store admin has access to wish list configuration.');
  $this
    ->assertField('commerce_wishlist_weight', t('Weight field exists.'));
  $this
    ->assertField('commerce_wishlist_element', t('Element field exists.'));
  $this
    ->assertField('commerce_wishlist_product_types[product]', t('Product type checkbox exists.'));

  // Login with customer.
  $this
    ->drupalLogin($this->storeCustomer);

  // Check the access to the profiles listing.
  $this
    ->drupalGet('admin/commerce/config/wishlist');
  $this
    ->assertResponse(403, 'The store customer has no access to wish list configuration.');

  // Test the UI.
  $this
    ->drupalGet('user/' . $this->storeCustomer->uid . '/wishlist');
  $this
    ->assertResponse(200, 'The customer can access the wish list view.');
  $this
    ->assertText('Nothing in your wish list.');

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

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

  // Submit the button.
  $this
    ->drupalPost('node/' . $this->productNode->uid, array(), t('Add to Wishlist'));

  // Upon refresh, the item should be in our wishlist.
  $this
    ->assertText('Already in your wish list.');

  // Make sure our message shows up.
  $this
    ->assertRaw(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,
    )),
  )), 'Added to wish list message is present.');

  // Make sure the product is actually in the cart.
  $this
    ->drupalGet('user/' . $this->storeCustomer->uid . '/wishlist');

  // Our remove link.
  $this
    ->assertLink('Remove');

  // This form shouldn't have any form elements in it.
  $this
    ->assertNoText('Already in your wishlist.', 'Wish list form elements are not present.');

  // Our product, linked to it's node, should be visible.
  $this
    ->assertLink($this->product->title);
  $this
    ->assertRaw(l($this->product->title, 'node/' . $this->productNode->nid), 'Item links to the original node.');

  // Remove it from the wishlist.
  $this
    ->clickLink('Remove');

  // Ensure that there are no items in the wishlist.
  $this
    ->assertText('Nothing in your wish list.', 'No more products in the listing.');
}