예제 #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
 /**
  * @covers ::getState
  * @covers ::getOrderNumber
  * @covers ::setOrderNumber
  * @covers ::getEmail
  * @covers ::setEmail
  * @covers ::getIpAddress
  * @covers ::setIpAddress
  * @covers ::getLineItems
  * @covers ::setLineItems
  * @covers ::hasLineItems
  * @covers ::addLineItem
  * @covers ::removeLineItem
  * @covers ::hasLineItem
  * @covers ::getBillingProfile
  * @covers ::setBillingProfile
  * @covers ::getBillingProfileId
  * @covers ::setBillingProfileId
  * @covers ::getCreatedTime
  * @covers ::setCreatedTime
  */
 public function testOrder()
 {
     // @todo Test the store and owner getters/setters as well.
     $profile = Profile::create(['type' => 'billing', 'address' => ['country' => 'FR', 'postal_code' => '75002', 'locality' => 'Paris', 'address_line1' => 'A french street', 'recipient' => 'John LeSmith']]);
     $profile->save();
     $line_item = LineItem::create(['type' => 'test']);
     $line_item->save();
     $order = Order::create(['type' => 'default', 'state' => 'completed', 'order_number' => '6', 'mail' => '*****@*****.**', 'ip_address' => '127.0.0.1', 'billing_profile' => $profile, 'line_items' => [$line_item]]);
     $order->save();
     // getState() returns a StateItem.
     $this->assertEquals('completed', $order->getState()->value);
     $this->assertEquals('6', $order->getOrderNumber());
     $order->setOrderNumber(7);
     $this->assertEquals('7', $order->getOrderNumber());
     $this->assertEquals('*****@*****.**', $order->getEmail());
     $order->setEmail('*****@*****.**');
     $this->assertEquals('*****@*****.**', $order->getEmail());
     $this->assertEquals('127.0.0.1', $order->getIpAddress());
     $order->setIpAddress('127.0.0.2');
     $this->assertEquals('127.0.0.2', $order->getIpAddress());
     // Avoid passing an entire entity to assertEquals(), causes a crash.
     $profiles_match = $profile === $order->getBillingProfile();
     $this->assertTrue($profiles_match);
     $this->assertEquals($profile->id(), $order->getBillingProfileId());
     $another_profile = Profile::create(['type' => 'billing', 'address' => ['country' => 'FR', 'postal_code' => '75003', 'locality' => 'Paris', 'address_line1' => 'A different french street', 'recipient' => 'Pierre Bertrand']]);
     $another_profile->save();
     $order->setBillingProfileId($another_profile->id());
     $this->assertEquals($another_profile->id(), $order->getBillingProfileId());
     $order->setBillingProfile($profile);
     $this->assertEquals($profile->id(), $order->getBillingProfileId());
     // An initially saved line item won't be the same as the loaded one.
     $line_item = LineItem::load($line_item->id());
     $line_items_match = [$line_item] == $order->getLineItems();
     $this->assertTrue($line_items_match);
     $this->assertTrue($order->hasLineItem($line_item));
     $order->removeLineItem($line_item);
     $this->assertFalse($order->hasLineItems());
     $this->assertFalse($order->hasLineItem($line_item));
     $order->addLineItem($line_item);
     $this->assertTrue($order->hasLineItem($line_item));
     $another_line_item = LineItem::create(['type' => 'test']);
     $another_line_item->save();
     $another_line_item = LineItem::load($another_line_item->id());
     $new_line_items = [$line_item, $another_line_item];
     $order->setLineItems($new_line_items);
     $line_items_match = $new_line_items == $order->getLineItems();
     $this->assertTrue($line_items_match);
     $this->assertTrue($order->hasLineItems());
     $order->setCreatedTime('635879700');
     $this->assertEquals('635879700', $order->getCreatedTime('635879700'));
 }
예제 #4
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.');
 }
예제 #5
0
 /**
  * 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(), '*****@*****.**');
 }
예제 #6
0
 /**
  * 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()]));
 }