You are here

public function UbercartAttributeCheckoutTestCase::testAttributeAddToCart in Ubercart 7.3

Tests that product in cart has the selected attribute option.

File

uc_attribute/tests/uc_attribute_checkout.test, line 32
Ubercart attribute checkout tests.

Class

UbercartAttributeCheckoutTestCase
Tests the product attribute API.

Code

public function testAttributeAddToCart() {
  for ($display = 0; $display <= 3; ++$display) {

    // Set up an attribute.
    $data = array(
      'display' => $display,
    );
    $attribute = UbercartAttributeTestCase::createAttribute($data);
    if ($display) {

      // Give the attribute an option.
      $option = UbercartAttributeTestCase::createAttributeOption(array(
        'aid' => $attribute->aid,
      ));
    }
    $attribute = uc_attribute_load($attribute->aid);

    // Put the attribute on a product.
    $product = $this
      ->createProduct();
    uc_attribute_subject_save($attribute, 'product', $product->nid, TRUE);

    // Add the product to the cart.
    if ($display == 3) {
      $edit = array(
        "attributes[{$attribute->aid}][{$option->oid}]" => $option->oid,
      );
    }
    elseif (isset($option)) {
      $edit = array(
        "attributes[{$attribute->aid}]" => $option->oid,
      );
    }
    else {
      $option = new stdClass();
      $option->name = self::randomName();
      $option->price = 0;
      $edit = array(
        "attributes[{$attribute->aid}]" => $option->name,
      );
    }
    $this
      ->drupalPost('node/' . $product->nid, $edit, t('Add to cart'));
    $this
      ->assertText("{$attribute->label}: {$option->name}", t('Option selected on cart item.'));
    $this
      ->assertText(uc_currency_format($product->sell_price + $option->price), t('Product has adjusted price.'));
  }
}