/** * 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.'); }
/** * @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')); }