public function testUserCheckoutWithDifferentAddresses() { $this->order->addProduct($this->products[0], 1); $this->order->save(); $this->assertTrue($this->order->isShippingRequired()); $this->controller->setOrder($this->reloadOrder($this->order)); $request = $this->controller->getRequest(); $request->set('sameAsBilling', ''); $request->set('email', '*****@*****.**'); // shipping address not entered at all $request->set('billing_firstName', 'First'); $request->set('billing_lastName', 'Last'); $request->set('billing_companyName', 'CMP'); $request->set('billing_address1', 'Address 1'); $request->set('billing_state_text', 'State'); $request->set('billing_city', 'Some City'); $request->set('billing_country', 'LV'); $request->set('billing_postalCode', 'LV-1234'); $request->set('billing_phone', '1234'); $response = $this->controller->processCheckoutRegistration(); // last name was not entered, so we get back to user/checkout // with a bunch of errors for each shipping address field $this->assertIsA($response, 'ActionRedirectResponse'); $this->assertEqual($response->getControllerName(), 'user'); $this->assertEqual($response->getActionName(), 'checkout'); $this->assertTrue(1 < count($this->controller->checkout()->get('form')->getValidator()->getErrorList())); // let's forget the last name again $request->set('shipping_firstName', 'Recipient'); $request->set('shipping_companyName', 'CMP'); $request->set('shipping_address1', 'Rec Street'); $request->set('shipping_city', 'Rec City'); $request->set('shipping_state_text', 'State'); $request->set('shipping_country', 'LT'); $request->set('shipping_postalCode', 'LT-4321'); $request->set('shipping_phone', '4321'); $this->assertEqual($response->getControllerName(), 'user'); $this->assertEqual($response->getActionName(), 'checkout'); // enter that last name at last $request->set('shipping_lastName', 'Last'); $response = $this->controller->processCheckoutRegistration(); $this->assertIsA($response, 'ActionRedirectResponse'); $this->assertEqual($response->getControllerName(), 'checkout'); $this->assertEqual($response->getActionName(), 'shipping'); // verify user data $user = SessionUser::getUser(); $user->reload(true); $this->assertEquals($user->firstName->get(), 'First'); $this->assertEquals($user->defaultShippingAddress->get()->userAddress->get()->firstName->get(), 'Recipient'); $this->assertEquals($user->defaultBillingAddress->get()->userAddress->get()->countryID->get(), 'LV'); $this->assertEquals($user->defaultShippingAddress->get()->userAddress->get()->countryID->get(), 'LT'); // order address ActiveRecord::clearPool(); $order = CustomerOrder::getInstanceByID($this->order->getID(), true); $order->loadAll(); $this->assertEquals($order->shippingAddress->get()->countryID->get(), 'LT'); }
public function testSetSingleAddress() { $this->order->addProduct($this->products[0], 1); $this->controller->setOrder($this->order); $this->controller->setMultiAddress(); $shipment1 = Shipment::getNewInstance($this->order); $shipment1->save(); $shipment2 = Shipment::getNewInstance($this->order); $shipment2->save(); $this->order->addProduct($this->products[0], 1, true, $shipment1); $this->order->addProduct($this->products[1], 2, true, $shipment2); $this->order->save(); $order = $this->reloadOrder($this->order); $this->assertEqual($order->getShipments()->size(), 2); $this->assertEqual(count($order->getOrderedItems()), 3); $this->controller->setOrder($order = $this->reloadOrder($this->order)); $response = $this->controller->setSingleAddress(); $order = $this->reloadOrder($order); $this->assertIsA($response, 'ActionRedirectResponse'); $this->assertEqual($order->isMultiAddress->get(), '0'); $this->assertEqual($order->getShipments()->size(), 1); $this->assertEqual(count($order->getOrderedItems()), 2); }