Esempio n. 1
0
 /**
  * Prepare preconditions for createOrder method invocation.
  *
  * @param int $productIdFromFixture
  * @param string $customerEmail
  * @param string $shippingMethod
  * @param int $shippingAddressAsBilling
  * @param array $paymentData
  * @param array $orderData
  * @param string $paymentMethod
  * @param int|null $customerIdFromFixture
  */
 protected function _preparePreconditionsForCreateOrder($productIdFromFixture, $customerEmail, $shippingMethod, $shippingAddressAsBilling, $paymentData, $orderData, $paymentMethod, $customerIdFromFixture = null)
 {
     /** Disable product options */
     /** @var \Magento\Catalog\Model\Product $product */
     $product = Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Product');
     $product->load($productIdFromFixture)->setHasOptions(false)->save();
     /** Set current customer */
     /** @var \Magento\Backend\Model\Session\Quote $session */
     $session = Bootstrap::getObjectManager()->get('Magento\\Backend\\Model\\Session\\Quote');
     if ($customerIdFromFixture !== null) {
         $session->setCustomerId($customerIdFromFixture);
         /** Unset fake IDs for default billing and shipping customer addresses */
         /** @var \Magento\Customer\Model\Customer $customer */
         $customer = Bootstrap::getObjectManager()->create('Magento\\Customer\\Model\\Customer');
         $customer->load($customerIdFromFixture)->setDefaultBilling(null)->setDefaultShipping(null)->save();
     } else {
         /**
          * Customer ID must be set to session to pass \Magento\Sales\Model\AdminOrder\Create::_validate()
          * This code emulates order placement via admin panel.
          */
         $session->setCustomerId(0);
     }
     /** Emulate availability of shipping method (all are disabled by default) */
     /** @var $rate \Magento\Quote\Model\Quote\Address\Rate */
     $rate = Bootstrap::getObjectManager()->create('Magento\\Quote\\Model\\Quote\\Address\\Rate');
     $rate->setCode($shippingMethod);
     $this->_model->getQuote()->getShippingAddress()->addShippingRate($rate);
     $this->_model->setShippingAsBilling($shippingAddressAsBilling);
     $this->_model->addProduct($productIdFromFixture, ['qty' => 1]);
     $this->_model->setPaymentData($paymentData);
     $this->_model->setIsValidate(true)->importPostData($orderData);
     /** Check preconditions */
     $this->assertEquals(0, $this->_messageManager->getMessages()->getCount(), "Precondition failed: Errors occurred before SUT execution.");
     /** Selectively check quote data */
     $createOrderData = $this->_model->getData();
     $this->assertEquals($shippingMethod, $createOrderData['shipping_method'], 'Precondition failed: Shipping method specified in create order model is invalid');
     $this->assertEquals('FirstName', $createOrderData['billing_address']['firstname'], 'Precondition failed: Address data is invalid in create order model');
     $this->assertEquals('Simple Product', $this->_model->getQuote()->getItemByProduct($product)->getData('name'), 'Precondition failed: Quote items data is invalid in create order model');
     $this->assertEquals($customerEmail, $this->_model->getQuote()->getCustomer()->getEmail(), 'Precondition failed: Customer data is invalid in create order model');
     $this->assertEquals($paymentMethod, $this->_model->getQuote()->getPayment()->getData('method'), 'Precondition failed: Payment method data is invalid in create order model');
 }