/**
  * Order simple product with different shipping address
  *
  * @test
  * @group adds_testdata
  */
 public function orderWithDifferentShippingAddress()
 {
     /* @var $cart MagentoComponents_Pages_Cart */
     $cart = Menta_ComponentManager::get('MagentoComponents_Pages_Cart');
     $cart->clearCart();
     $productSingleView = Menta_ComponentManager::get('MagentoComponents_Pages_ProductSingleView');
     /* @var $productSingleView MagentoComponents_Pages_ProductSingleView */
     $productSingleView->putProductsIntoCart($this->getConfiguration()->getValue('testing.simple.product.id'));
     $onePageCheckout = Menta_ComponentManager::get('MagentoComponents_Pages_OnePageCheckout');
     /* @var $onePageCheckout MagentoComponents_Pages_OnePageCheckout */
     $onePageCheckout->open();
     $onePageCheckout->setCheckoutMethod('register');
     $onePageCheckout->finishStep('checkoutMethod');
     $onePageCheckout->addAddress('uk', 'billing');
     $this->getHelperAssert()->assertElementPresent('billing:customer_password');
     $onePageCheckout->saveAccountForLaterUse();
     $onePageCheckout->toggleShipToDifferentAddress();
     /* @var $customerAccount MagentoComponents_Pages_CustomerAccount */
     $customerAccount = Menta_ComponentManager::get('MagentoComponents_Pages_CustomerAccount');
     $onePageCheckout->finishStep('billingAddress');
     $onePageCheckout->addAddress('uk', 'shipping');
     $onePageCheckout->finishStep('shippingAddress');
     $onePageCheckout->finishStep('shippingMethod');
     $onePageCheckout->selectPaymentMethodCheckmo();
     $onePageCheckout->finishStep('paymentMethod');
     $onePageCheckout->submitForm();
     $this->lastOrderId = $onePageCheckout->getOrderIdFromSuccessPage();
     $lastOrderNumber = $onePageCheckout->getOrderNumberFromSuccessPage();
     $this->getHelperCommon()->open('/sales/order/history/?limit=50');
     $viewOrderLinkPath = '//*[@id="my-orders-table"]/tbody/tr/td/span/a[contains(@href, "view/order_id/' . $this->lastOrderId . '")]';
     $this->getHelperCommon()->click($viewOrderLinkPath);
     $this->getHelperWait()->waitForElementPresent('//h1[ ' . Menta_Util_Div::containsText("Order #{$lastOrderNumber}") . ']');
     $this->getHelperAssert()->assertTextPresent($this->lastOrderId);
     $addressProvider = new MagentoComponents_Provider_Address();
     $shippingAddress = $addressProvider->getAddressField('shipping', 'uk');
     $billingAddress = $addressProvider->getAddressField('billing', 'uk');
     $this->getHelperAssert()->assertTextPresent($shippingAddress['firstname']);
     $this->getHelperAssert()->assertTextPresent($shippingAddress['lastname']);
     $this->getHelperAssert()->assertTextPresent($shippingAddress['street1']);
     if (isset($shippingAddress['region']) && $shippingAddress['region']) {
         $this->getHelperAssert()->assertTextPresent($shippingAddress['region']);
     }
     $this->getHelperAssert()->assertTextPresent($shippingAddress['country']);
     $this->getHelperAssert()->assertTextPresent($shippingAddress['phone']);
     $this->getHelperAssert()->assertTextPresent($billingAddress['firstname']);
     $this->getHelperAssert()->assertTextPresent($billingAddress['lastname']);
     $this->getHelperAssert()->assertTextPresent($billingAddress['street1']);
     if (isset($billingAddress['region']) && $billingAddress['region']) {
         $this->getHelperAssert()->assertTextPresent($billingAddress['region']);
     }
     $this->getHelperAssert()->assertTextPresent($billingAddress['country']);
     $this->getHelperAssert()->assertTextPresent($billingAddress['phone']);
     return $lastOrderNumber;
 }
 /**
  * Add shipping|billing address
  *
  * @param string $country
  * @param $type
  * @param array $address
  * @throws Exception
  * @return array complete address data that was used
  */
 public function addAddress($country = 'us', $type, array $address = null)
 {
     if (!in_array($type, array('billing', 'shipping'))) {
         throw new Exception('Invalid address type');
     }
     if (is_null($address)) {
         $addressProvider = new MagentoComponents_Provider_Address();
         $address = $addressProvider->getAddressField($type, $country);
     }
     if ($type == 'billing' && !isset($address['email'])) {
         $address['email'] = Menta_ComponentManager::get('MagentoComponents_Pages_CustomerAccount')->createNewMailAddress('oscbillling');
     }
     foreach ($address as $field => $value) {
         if (in_array($field, array('country', 'region'))) {
             $this->getHelperCommon()->select("id={$type}:{$field}_id", "label=" . $value);
         } else {
             try {
                 $this->getHelperCommon()->type("id={$type}:{$field}", $value);
             } catch (WebDriver\Exception\NoSuchElement $e) {
                 // field was renamed
                 if ($field == 'phone') {
                     $this->getHelperCommon()->type("id={$type}:telephone", $value);
                 } else {
                     throw $e;
                 }
             }
         }
     }
     return $address;
 }