示例#1
0
 /**
  * Tests deleting an order programaticaly and through the UI.
  */
 public function testDeleteOrder()
 {
     $line_item = $this->createEntity('commerce_line_item', ['type' => 'product_variation']);
     $order = $this->createEntity('commerce_order', ['type' => 'default', 'mail' => $this->loggedInUser->getEmail(), 'line_items' => [$line_item]]);
     $order->delete();
     $order_exists = (bool) Order::load($order->id());
     $line_item_exists = (bool) LineItem::load($line_item->id());
     $this->assertFalse($order_exists, 'The new order has been deleted from the database.');
     $this->assertFalse($line_item_exists, 'The matching line item has been deleted from the database.');
 }
示例#2
0
 /**
  * Tests deleting a order.
  */
 public function testDeleteOrder()
 {
     $order = $this->createEntity('commerce_order', ['type' => 'default', 'mail' => $this->loggedInUser->getEmail()]);
     $this->drupalGet($order->toUrl('delete-form'));
     $this->assertResponse(200, 'The order delete form can be accessed.');
     $this->assertRaw(t('Are you sure you want to delete the order %label?', ['%label' => $order->label()]));
     $this->assertText(t('This action cannot be undone.'), 'The order deletion confirmation form is available');
     $this->drupalPostForm(NULL, NULL, t('Delete'));
     \Drupal::service('entity_type.manager')->getStorage('commerce_order')->resetCache([$order->id()]);
     $order_exists = (bool) Order::load($order->id());
     $this->assertFalse($order_exists, 'The order has been deleted from the database.');
 }
示例#3
0
 /**
  * Tests deleting a order.
  */
 public function testDeleteOrder()
 {
     // Create a new order.
     $order = $this->createEntity('commerce_order', ['type' => 'default', 'mail' => $this->loggedInUser->getEmail()]);
     $order_exists = (bool) Order::load($order->id());
     $this->assertTrue($order_exists, 'The order has been created in the database.');
     $this->drupalGet('admin/commerce/orders/' . $order->id() . '/delete');
     $this->assertRaw(t('Are you sure you want to delete the order %label?', ['%label' => $order->label()]));
     $this->assertText(t('This action cannot be undone.'), 'The order deletion confirmation form is available');
     $this->drupalPostForm(NULL, NULL, t('Delete'));
     // Remove the entity from cache and check if the order is deleted.
     \Drupal::service('entity_type.manager')->getStorage('commerce_order')->resetCache([$order->id()]);
     $order_exists = (bool) Order::load('commerce_order', $order->id());
     $this->assertFalse($order_exists, 'The order has been deleted from the database.');
 }
 /**
  * Tests the reassign form with a new user.
  */
 public function testOrderReassign()
 {
     $line_item = $this->createEntity('commerce_line_item', ['type' => 'product_variation', 'unit_price' => ['amount' => '999', 'currency_code' => 'USD']]);
     /** @var \Drupal\commerce_order\Entity\OrderInterface $order */
     $order = $this->createEntity('commerce_order', ['type' => 'default', 'mail' => $this->loggedInUser->getEmail(), 'uid' => $this->loggedInUser->id(), 'line_items' => [$line_item]]);
     $this->assertTrue($order->hasLinkTemplate('reassign-form'));
     $this->drupalGet($order->toUrl('reassign-form')->toString());
     $values = ['customer_type' => 'new'];
     $this->drupalPostAjaxForm(NULL, $values, 'customer_type');
     $values = ['customer_type' => 'new', 'mail' => '*****@*****.**'];
     $this->drupalPostForm(NULL, $values, 'Reassign order');
     $this->assertUrl($order->toUrl('collection')->toString());
     // Reload the order.
     \Drupal::service('entity_type.manager')->getStorage('commerce_order')->resetCache([$order->id()]);
     $order = Order::load($order->id());
     $this->assertEqual($order->getOwner()->getEmail(), '*****@*****.**');
     $this->assertEqual($order->getEmail(), '*****@*****.**');
 }
 /**
  * Tests ability to expose line item fields on the add to cart form.
  */
 public function testExposedLineItemFields()
 {
     /** @var \Drupal\Core\Entity\Entity\EntityFormDisplay $line_item_form_display */
     $line_item_form_display = EntityFormDisplay::load('commerce_line_item.product_variation.add_to_cart');
     $line_item_form_display->setComponent('quantity', ['type' => 'number']);
     $line_item_form_display->save();
     // Get the existing product page and submit Add to cart form.
     $this->postAddToCart($this->variation->getProduct(), ['quantity[0][value]' => 3]);
     // Check if the quantity was increased for the existing line item.
     $this->cart = Order::load($this->cart->id());
     $line_items = $this->cart->getLineItems();
     /** @var \Drupal\commerce_order\Entity\LineItemInterface $line_item */
     $line_item = $line_items[0];
     $this->assertEqual($line_item->getTitle(), $this->variation->getLineItemTitle());
     $this->assertTrue($line_item->getQuantity() == 3, t('The product @product has been added to cart.', ['@product' => $line_item->getTitle()]));
 }