public function CommerceOrderUIAdminTest::testCommerceOrderUIAddProductsToOrder in Commerce Core 7
Test adding products to an order via Admin UI.
File
- modules/
order/ tests/ commerce_order_ui.test, line 142 - Functional tests for the commerce order UI module.
Class
- CommerceOrderUIAdminTest
- Functional tests for the commerce order UI module.
Code
public function testCommerceOrderUIAddProductsToOrder() {
// Log in as store admin.
$this
->drupalLogin($this->store_admin);
// Access the edit page of the order.
$this
->drupalGet('admin/commerce/orders/' . $this->order->order_id . '/edit');
// Add a product line item to the order.
$this
->drupalPostAJAX(NULL, array(
'commerce_line_items[und][actions][line_item_type]' => 'product',
), array(
'op' => t('Add line item'),
));
$this
->assertFieldByXPath("//input[starts-with(@id, 'edit-commerce-line-items-und-actions-product-sku')]", NULL, t('Product select form is present in the order admin screen'));
$this
->assertFieldByXPath("//input[starts-with(@id, 'edit-commerce-line-items-und-actions-save-line-item')]", NULL, t('Add product button is present in the order admin screen'));
$this
->drupalPostAJAX(NULL, array(
'commerce_line_items[und][actions][product_sku]' => $this->product->sku,
), array(
'op' => t('Add product'),
));
$this
->drupalPost(NULL, array(), t('Save order', array(), array(
'context' => 'a drupal commerce order',
)));
// Reload the order directly from db.
$order = commerce_order_load_multiple(array(
$this->order->order_id,
), array(), TRUE);
// Reset the cache as we don't want to keep the lock.
entity_get_controller('commerce_order')
->resetCache();
// Check if the product has been added to the order.
foreach (entity_metadata_wrapper('commerce_order', reset($order))->commerce_line_items as $delta => $line_item_wrapper) {
if ($line_item_wrapper
->getBundle() == 'product') {
$product = $line_item_wrapper->commerce_product
->value();
$products[$product->product_id] = $product;
}
}
$this
->assertTrue(array_key_exists($this->product->product_id, $products), t('Added product is included in the order at the database level'));
// Access the edit page of the order and check if the product is present.
$this
->drupalGet('admin/commerce/orders/' . $this->order->order_id . '/edit');
$this
->assertText($this->product->sku, t('SKU from product is present in the order edit screen'));
$this
->assertText($this->product->title, t('Product title is present in the order edit screen'));
}