You are here

function UCRestrictQtyFunctionalTest::testGlobalLimit in Ubercart Restrict Qty 7

Same name and namespace in other branches
  1. 6.2 tests/uc_restrict_qty.test \UCRestrictQtyFunctionalTest::testGlobalLimit()

File

tests/uc_restrict_qty.test, line 186
UC Restrict Qty auto-tests.

Class

UCRestrictQtyFunctionalTest
@file UC Restrict Qty auto-tests.

Code

function testGlobalLimit() {
  $limit = 2;
  variable_set('uc_restrict_qty_global', $limit);
  $product = $this
    ->drupalCreateProduct();
  $this
    ->drupalPost('node/' . $product->nid, array(), t('Add to cart'));
  $this
    ->assertRaw(t('<strong>@product-title</strong> added to <a href="!url">your shopping cart</a>.', array(
    '@product-title' => $product->title,
    '!url' => url('cart'),
  )), 'Global limit [adding to cart below limit]');
  $product = $this
    ->drupalCreateProduct();
  $this
    ->drupalPost('node/' . $product->nid, array(), t('Add to cart'));
  $this
    ->assertRaw(t('<strong>@product-title</strong> added to <a href="!url">your shopping cart</a>.', array(
    '@product-title' => $product->title,
    '!url' => url('cart'),
  )), 'Global limit [close to limit]');
  $product = $this
    ->drupalCreateProduct();
  $this
    ->drupalPost('node/' . $product->nid, array(), t('Add to cart'));
  $this
    ->assertNoRaw(t('<strong>@product-title</strong> added to <a href="!url">your shopping cart</a>.', array(
    '@product-title' => $product->title,
    '!url' => url('cart'),
  )), 'Global limit [above the limit|not added]');
  $this
    ->assertRaw(format_plural($limit, "Sorry, you may only have a total of 1 item in your cart. You must <a href='@checkout'>checkout</a> or remove the item in <a href='@cart'>your cart</a> before adding a different item.", "Sorry, you may only have a total of @count items in your cart. You must <a href='@checkout'>checkout</a> or remove items from <a href='@cart'>your cart</a> before adding others.", array(
    '@cart' => url('cart'),
    '@checkout' => url('cart/checkout'),
  )), 'Global limit [above the limit|message shown]');
  variable_set('uc_restrict_qty_global', 0);
  $product = $this
    ->drupalCreateProduct();
  $this
    ->drupalPost('node/' . $product->nid, array(), t('Add to cart'));
  $this
    ->assertRaw(t('<strong>@product-title</strong> added to <a href="!url">your shopping cart</a>.', array(
    '@product-title' => $product->title,
    '!url' => url('cart'),
  )), 'Global limit [no limit]');
}