You are here

public function UbercartCartSettingsTestCase::testAddToCartRedirect in Ubercart 7.3

Same name and namespace in other branches
  1. 6.2 uc_cart/uc_cart.test \UbercartCartSettingsTestCase::testAddToCartRedirect()

Tests add-to-cart redirection.

File

uc_cart/tests/uc_cart.test, line 630
Shopping cart and checkout tests.

Class

UbercartCartSettingsTestCase
Tests the cart settings page.

Code

public function testAddToCartRedirect() {
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->drupalGet('admin/store/settings/cart');
  $this
    ->assertField('uc_add_item_redirect', t('Add to cart redirect field exists'));
  $redirect = $this
    ->randomName(8);
  $this
    ->drupalPost('admin/store/settings/cart', array(
    'uc_add_item_redirect' => $redirect,
  ), t('Save configuration'));
  $this
    ->drupalPost('node/' . $this->product->nid, array(), t('Add to cart'));
  $url_pass = $this
    ->getUrl() == url($redirect, array(
    'absolute' => TRUE,
  ));
  $this
    ->assertTrue($url_pass, t('Add to cart redirect takes user to the correct URL.'));
  $this
    ->drupalPost('admin/store/settings/cart', array(
    'uc_add_item_redirect' => '<none>',
  ), t('Save configuration'));
  $this
    ->drupalPost('node/' . $this->product->nid, array(), t('Add to cart'), array(
    'query' => array(
      'test' => 'querystring',
    ),
  ));
  $url = url('node/' . $this->product->nid, array(
    'absolute' => TRUE,
    'query' => array(
      'test' => 'querystring',
    ),
  ));
  $this
    ->assertTrue($this
    ->getUrl() == $url, 'Add to cart no-redirect works with a query string.');
}