public function CommerceCartTestCaseAttributes::testCommerceCartSelectProductAdd in Commerce Core 7
Test the add to cart functional process with attributes.
File
- modules/
cart/ tests/ commerce_cart.test, line 410 - Functional tests for the commerce cart module.
Class
- CommerceCartTestCaseAttributes
- Test cart features for a product with attributes.
Code
public function testCommerceCartSelectProductAdd() {
// Go to product page.
$this
->drupalGet('node/' . $this->product_node->nid);
// Set the product that we are checking.
$product_wrapper = entity_metadata_wrapper('commerce_product', $this->products[3]);
// Select one of the attributes.
$this
->drupalPostAJAX(NULL, array(
'attributes[field_1]' => $product_wrapper->field_1
->value(),
), 'attributes[field_1]');
// Add product to the cart.
$this
->drupalPost(NULL, array(), t('Add to cart'));
// Ensure the add to cart message is displayed.
$message = t('%title added to <a href="!cart-url">your cart</a>.', array(
'%title' => 'field_1_value_2_field_2_value_1',
'!cart-url' => url('cart'),
));
$this
->assertRaw($message, t('Product add to cart message displayed.'));
// Go to cart url.
$this
->drupalGet($this
->getCommerceUrl('cart'));
// Test if the page resolves and there is something in the cart.
$this
->assertResponse(200);
$this
->assertNoText(t('Your shopping cart is empty.'), t('Cart is not empty'));
$this
->assertText('field_1_value_2_field_2_value_1', t('Product was added to the cart'));
}