Exemplo n.º 1
0
 protected function setUp()
 {
     /** @var $storeManager \Magento\Framework\StoreManagerInterface */
     $storeManager = self::$_objectManager->get('Magento\\Framework\\StoreManagerInterface');
     $this->_store = $storeManager->getStore();
     $this->_model = self::$_objectManager->create('Magento\\Catalog\\Model\\Category');
 }
Exemplo n.º 2
0
 /**
  * @magentoDataFixture Magento/Catalog/_files/product_simple.php
  */
 public function testSetGetProduct()
 {
     $this->assertSame($this->product, $this->block->getProduct());
     $product = $this->objectManager->create('Magento\\Catalog\\Model\\Product');
     $this->block->setProduct($product);
     $this->assertSame($product, $this->block->getProduct());
 }
 /**
  * @magentoApiDataFixture Magento/GiftMessage/_files/quote_with_item_message.php
  */
 public function testSave()
 {
     // sales/gift_options/allow_items must be set to 1 in system configuration
     // @todo remove next statement when \Magento\TestFramework\TestCase\WebapiAbstract::_updateAppConfig is fixed
     $this->markTestIncomplete('This test relies on system configuration state.');
     /** @var \Magento\Quote\Model\Quote $quote */
     $quote = $this->objectManager->create('Magento\\Quote\\Model\\Quote');
     $quote->load('test_order_item_with_message', 'reserved_order_id');
     $product = $this->objectManager->create('Magento\\Catalog\\Model\\Product');
     $product->load($product->getIdBySku('simple_with_message'));
     $itemId = $quote->getItemByProduct($product)->getId();
     $cartId = $quote->getId();
     /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */
     $quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Quote\\Model\\QuoteIdMaskFactory')->create();
     $quoteIdMask->load($cartId, 'quote_id');
     //Use masked cart Id
     $cartId = $quoteIdMask->getMaskedId();
     $serviceInfo = ['rest' => ['resourcePath' => self::RESOURCE_PATH . $cartId . '/gift-message/' . $itemId, 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST], 'soap' => ['service' => self::SERVICE_NAME, 'serviceVersion' => self::SERVICE_VERSION, 'operation' => self::SERVICE_NAME . 'Save']];
     $requestData = ['cartId' => $cartId, 'itemId' => $itemId, 'giftMessage' => ['recipient' => 'John Doe', 'sender' => 'Jane Roe', 'message' => 'Gift Message Text New']];
     $this->assertTrue($this->_webApiCall($serviceInfo, $requestData));
     //        $quote->load('test_order_item_with_message', 'reserved_order_id');
     $messageId = $quote->getItemByProduct($product)->getGiftMessageId();
     /** @var  \Magento\GiftMessage\Model\Message $message */
     $message = $this->objectManager->create('Magento\\GiftMessage\\Model\\Message')->load($messageId);
     $this->assertEquals('John Doe', $message->getRecipient());
     $this->assertEquals('Jane Roe', $message->getSender());
     $this->assertEquals('Gift Message Text New', $message->getMessage());
 }
 /**
  * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
  */
 public function testSetAddress()
 {
     /** @var \Magento\Quote\Model\Quote $quote */
     $quote = $this->objectManager->create('Magento\\Quote\\Model\\Quote');
     $quote->load('test_order_1', 'reserved_order_id');
     $cartId = $this->getQuoteMaskedId($quote->getId());
     $serviceInfo = ['rest' => ['resourcePath' => self::RESOURCE_PATH . $cartId . '/billing-address', 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST], 'soap' => ['service' => self::SERVICE_NAME, 'serviceVersion' => self::SERVICE_VERSION, 'operation' => self::SERVICE_NAME . 'Assign']];
     $addressData = ['firstname' => 'John', 'lastname' => 'Smith', 'email' => '', 'company' => 'Magento Commerce Inc.', 'street' => ['Typical Street', 'Tiny House 18'], 'city' => 'Big City', 'region_id' => 12, 'region' => 'California', 'region_code' => 'CA', 'postcode' => '0985432', 'country_id' => 'US', 'telephone' => '88776655', 'fax' => '44332255'];
     $requestData = ["cartId" => $cartId, 'address' => $addressData];
     $addressId = $this->_webApiCall($serviceInfo, $requestData);
     //reset $quote to reload data
     $quote = $this->objectManager->create('Magento\\Quote\\Model\\Quote');
     $quote->load('test_order_1', 'reserved_order_id');
     $address = $quote->getBillingAddress();
     $address->getRegionCode();
     $savedData = $address->getData();
     $this->assertEquals($addressId, $savedData['address_id']);
     //custom checks for street, region and address_type
     foreach ($addressData['street'] as $streetLine) {
         $this->assertContains($streetLine, $quote->getBillingAddress()->getStreet());
     }
     unset($addressData['street']);
     unset($addressData['email']);
     $this->assertEquals('billing', $savedData['address_type']);
     //check the rest of fields
     foreach ($addressData as $key => $value) {
         $this->assertEquals($value, $savedData[$key]);
     }
 }
Exemplo n.º 5
0
 protected function setUp()
 {
     /** @var $objectManager \Magento\TestFramework\ObjectManager */
     $this->_objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     $this->_model = $this->_objectManager->create('Magento\\Tax\\Model\\Calculation');
     $this->customerRepository = $this->_objectManager->create('Magento\\Customer\\Api\\CustomerRepositoryInterface');
     $this->addressRepository = $this->_objectManager->create('Magento\\Customer\\Api\\AddressRepositoryInterface');
     $this->groupRepository = $this->_objectManager->create('Magento\\Customer\\Api\\GroupRepositoryInterface');
 }
Exemplo n.º 6
0
 protected function setUp()
 {
     /** @var $objectManager \Magento\TestFramework\ObjectManager */
     $this->_objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     $this->_model = $this->_objectManager->create('Magento\\Tax\\Model\\Calculation');
     $this->_customerAccountService = $this->_objectManager->create('Magento\\Customer\\Service\\V1\\CustomerAccountService');
     $this->_addressService = $this->_objectManager->create('Magento\\Customer\\Service\\V1\\CustomerAddressService');
     $this->_groupService = $this->_objectManager->create('Magento\\Customer\\Service\\V1\\CustomerGroupService');
 }
 /**
  * Retrieve quote by given reserved order ID
  *
  * @param string $reservedOrderId
  * @return \Magento\Quote\Model\Quote
  * @throws \InvalidArgumentException
  */
 protected function getCart($reservedOrderId)
 {
     /** @var $cart \Magento\Quote\Model\Quote */
     $cart = $this->objectManager->get('Magento\\Quote\\Model\\Quote');
     $cart->load($reservedOrderId, 'reserved_order_id');
     if (!$cart->getId()) {
         throw new \InvalidArgumentException('There is no quote with provided reserved order ID.');
     }
     return $cart;
 }
Exemplo n.º 8
0
 /**
  * @covers \Magento\Catalog\Model\Product\Gallery\ReadHandler::execute
  */
 public function testExecute()
 {
     /** @var \Magento\Catalog\Model\Product $product */
     $product = $this->objectManager->create('Magento\\Catalog\\Model\\Product');
     $product->setId(1);
     $this->readHandler->execute('Magento\\Catalog\\Api\\Data\\ProductInterface', $product);
     $data = $product->getData();
     $this->assertArrayHasKey('media_gallery', $data);
     $this->assertArrayHasKey('images', $data['media_gallery']);
     $this->assertEquals('Image Alt Text', $data['media_gallery']['images'][0]['label']);
 }
 /**
  * Receive product options with values
  *
  * @return array
  */
 protected function getOptions()
 {
     /** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
     $productRepository = $this->objectManager->create('Magento\\Catalog\\Api\\ProductRepositoryInterface');
     $product = $productRepository->get(self::SIMPLE_PRODUCT_SKU);
     $options = [];
     /** @var ProductCustomOptionInterface $option */
     foreach ($product->getOptions() as $option) {
         $options[] = ['option_id' => $option->getId(), 'option_value' => $this->getOptionRequestValue($option)];
     }
     return $options;
 }
Exemplo n.º 10
0
 /**
  * @magentoAppIsolation enabled
  * @magentoDataFixture Magento/Tax/_files/tax_classes.php
  */
 public function testCheckClassCanBeDeletedProductClassUsedInTaxRule()
 {
     /** @var $registry \Magento\Framework\Registry */
     $registry = $this->_objectManager->get('Magento\\Framework\\Registry');
     /** @var $taxRule \Magento\Tax\Model\Calculation\Rule */
     $taxRule = $registry->registry('_fixture/Magento_Tax_Model_Calculation_Rule');
     $productClasses = $taxRule->getProductTaxClasses();
     /** @var $model \Magento\Tax\Model\ClassModel */
     $model = $this->_objectManager->create('Magento\\Tax\\Model\\ClassModel')->load($productClasses[0]);
     $this->setExpectedException('Magento\\Framework\\Exception\\CouldNotDeleteException', 'You cannot delete this tax class because it is used in' . ' Tax Rules. You have to delete the rules it is used in first.');
     $model->delete();
 }
Exemplo n.º 11
0
 /**
  * @magentoApiDataFixture Magento/Sales/_files/order.php
  */
 public function testGet()
 {
     /** @var \Magento\Sales\Model\Order $order */
     $order = $this->objectManager->create('Magento\\Sales\\Model\\Order');
     $order->loadByIncrementId(self::ORDER_INCREMENT_ID);
     /** @var \Magento\Sales\Model\Order\Item $orderItem */
     $orderItem = current($order->getItems());
     $serviceInfo = ['rest' => ['resourcePath' => self::RESOURCE_PATH . '/' . $orderItem->getId(), 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET], 'soap' => ['service' => self::SERVICE_NAME, 'serviceVersion' => self::SERVICE_VERSION, 'operation' => self::SERVICE_NAME . 'get']];
     $response = $this->_webApiCall($serviceInfo, ['id' => $orderItem->getId()]);
     $this->assertTrue(is_array($response));
     $this->assertOrderItem($orderItem, $response);
 }
 /**
  * @magentoApiDataFixture Magento/Checkout/_files/quote_with_shipping_method.php
  */
 public function testGetTotals()
 {
     /** @var \Magento\Quote\Model\Quote $quote */
     $quote = $this->objectManager->create('Magento\\Quote\\Model\\Quote');
     $quote->load('test_order_1', 'reserved_order_id');
     $cartId = $this->getQuoteMaskedId($quote->getId());
     /** @var \Magento\Quote\Model\Quote\Address $shippingAddress */
     $shippingAddress = $quote->getShippingAddress();
     $data = [Totals::KEY_BASE_GRAND_TOTAL => $quote->getBaseGrandTotal(), Totals::KEY_GRAND_TOTAL => $quote->getGrandTotal(), Totals::KEY_BASE_SUBTOTAL => $quote->getBaseSubtotal(), Totals::KEY_SUBTOTAL => $quote->getSubtotal(), Totals::KEY_BASE_SUBTOTAL_WITH_DISCOUNT => $quote->getBaseSubtotalWithDiscount(), Totals::KEY_SUBTOTAL_WITH_DISCOUNT => $quote->getSubtotalWithDiscount(), Totals::KEY_DISCOUNT_AMOUNT => $shippingAddress->getDiscountAmount(), Totals::KEY_BASE_DISCOUNT_AMOUNT => $shippingAddress->getBaseDiscountAmount(), Totals::KEY_SHIPPING_AMOUNT => $shippingAddress->getShippingAmount(), Totals::KEY_BASE_SHIPPING_AMOUNT => $shippingAddress->getBaseShippingAmount(), Totals::KEY_SHIPPING_DISCOUNT_AMOUNT => $shippingAddress->getShippingDiscountAmount(), Totals::KEY_BASE_SHIPPING_DISCOUNT_AMOUNT => $shippingAddress->getBaseShippingDiscountAmount(), Totals::KEY_TAX_AMOUNT => $shippingAddress->getTaxAmount(), Totals::KEY_BASE_TAX_AMOUNT => $shippingAddress->getBaseTaxAmount(), Totals::KEY_SHIPPING_TAX_AMOUNT => $shippingAddress->getShippingTaxAmount(), Totals::KEY_BASE_SHIPPING_TAX_AMOUNT => $shippingAddress->getBaseShippingTaxAmount(), Totals::KEY_SUBTOTAL_INCL_TAX => $shippingAddress->getSubtotalInclTax(), Totals::KEY_BASE_SUBTOTAL_INCL_TAX => $shippingAddress->getBaseSubtotalTotalInclTax(), Totals::KEY_SHIPPING_INCL_TAX => $shippingAddress->getShippingInclTax(), Totals::KEY_BASE_SHIPPING_INCL_TAX => $shippingAddress->getBaseShippingInclTax(), Totals::KEY_BASE_CURRENCY_CODE => $quote->getBaseCurrencyCode(), Totals::KEY_QUOTE_CURRENCY_CODE => $quote->getQuoteCurrencyCode(), Totals::KEY_ITEMS => [$this->getQuoteItemTotalsData($quote)]];
     $requestData = ['cartId' => $cartId];
     $data = $this->formatTotalsData($data);
     $this->assertEquals($data, $this->_webApiCall($this->getServiceInfoForTotalsService($cartId), $requestData));
 }
Exemplo n.º 13
0
 protected function setUp()
 {
     $this->_objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     $this->_model = $this->_objectManager->get('Magento\\Framework\\Session\\SaveHandler\\DbTable');
     /** @var $resource \Magento\Framework\App\Resource */
     $resource = $this->_objectManager->get('Magento\\Framework\\App\\Resource');
     $this->_connection = $resource->getConnection('core_write');
     $this->_sessionTable = $resource->getTableName('session');
     // session stores serialized objects with protected properties
     // we need to test this case to ensure that DB adapter successfully processes "\0" symbols in serialized data
     foreach ($this->_sourceData as $key => $data) {
         $this->_sessionData[$key] = new \Magento\Framework\Object($data);
     }
 }
Exemplo n.º 14
0
 /**
  * Get customer ID token
  *
  * @return string
  */
 protected function getCustomerToken()
 {
     /** @var \Magento\Integration\Api\CustomerTokenServiceInterface $customerTokenService */
     $customerTokenService = $this->objectManager->create('Magento\\Integration\\Api\\CustomerTokenServiceInterface');
     $token = $customerTokenService->createCustomerAccessToken('*****@*****.**', 'password');
     return $token;
 }
 /**
  * @param string $behavior
  * @param string $sourceFile
  * @param array $dataBefore
  * @param array $dataAfter
  * @param array $errors
  *
  * @magentoDataFixture Magento/Customer/_files/import_export/customers_for_address_import.php
  * @magentoAppIsolation enabled
  *
  * @dataProvider importDataDataProvider
  */
 public function testImportData($behavior, $sourceFile, array $dataBefore, array $dataAfter, array $errors = [])
 {
     \Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea(\Magento\Framework\App\Area::AREA_FRONTEND);
     // set entity adapter parameters
     $this->_entityAdapter->setParameters(['behavior' => $behavior]);
     /** @var \Magento\Framework\Filesystem $filesystem */
     $filesystem = $this->_objectManager->create('Magento\\Framework\\Filesystem');
     $rootDirectory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
     $this->_entityAdapter->getErrorAggregator()->initValidationStrategy(ProcessingErrorAggregatorInterface::VALIDATION_STRATEGY_STOP_ON_ERROR, 10);
     // set fixture CSV file
     $result = $this->_entityAdapter->setSource(\Magento\ImportExport\Model\Import\Adapter::findAdapterFor($sourceFile, $rootDirectory))->validateData()->hasToBeTerminated();
     if ($errors) {
         $this->assertTrue($result);
     } else {
         $this->assertFalse($result);
     }
     // assert validation errors
     // can't use error codes because entity adapter gathers only error messages from aggregated adapters
     $actualErrors = array_values($this->_entityAdapter->getErrorAggregator()->getRowsGroupedByErrorCode());
     $this->assertEquals($errors, $actualErrors);
     // assert data before import
     $this->_assertCustomerData($dataBefore);
     // import data
     $this->_entityAdapter->importData();
     // assert data after import
     $this->_assertCustomerData($dataAfter);
 }
 /**
  * @magentoApiDataFixture Magento/Checkout/_files/quote_with_payment_saved.php
  */
 public function testGet()
 {
     /** @var \Magento\Quote\Model\Quote $quote */
     $quote = $this->objectManager->create('Magento\\Quote\\Model\\Quote');
     $quote->load('test_order_1_with_payment', 'reserved_order_id');
     $cartId = $quote->getId();
     $serviceInfo = ['rest' => ['resourcePath' => self::RESOURCE_PATH . $cartId . '/selected-payment-methods', 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET], 'soap' => ['service' => self::SERVICE_NAME, 'serviceVersion' => self::SERVICE_VERSION, 'operation' => self::SERVICE_NAME . 'get']];
     $requestData = ["cartId" => $cartId];
     $requestResponse = $this->_webApiCall($serviceInfo, $requestData);
     $this->assertArrayHasKey('method', $requestResponse);
     $this->assertArrayHasKey('po_number', $requestResponse);
     $this->assertArrayHasKey('cc_owner', $requestResponse);
     $this->assertArrayHasKey('cc_type', $requestResponse);
     $this->assertArrayHasKey('cc_exp_year', $requestResponse);
     $this->assertArrayHasKey('cc_exp_month', $requestResponse);
     $this->assertArrayHasKey('additional_data', $requestResponse);
     $this->assertNotNull($requestResponse['method']);
     $this->assertNotNull($requestResponse['po_number']);
     $this->assertNotNull($requestResponse['cc_owner']);
     $this->assertNotNull($requestResponse['cc_type']);
     $this->assertNotNull($requestResponse['cc_exp_year']);
     $this->assertNotNull($requestResponse['cc_exp_month']);
     $this->assertNotNull($requestResponse['additional_data']);
     $this->assertEquals('checkmo', $requestResponse['method']);
 }
Exemplo n.º 17
0
 /**
  * @magentoDataFixture Magento/Newsletter/_files/subscribers.php
  */
 public function testSaveActionExistingCustomerUnsubscribeNewsletter()
 {
     $customerId = 1;
     /** @var \Magento\Newsletter\Model\Subscriber $subscriber */
     $subscriber = $this->objectManager->get('Magento\\Newsletter\\Model\\SubscriberFactory')->create();
     $this->assertEmpty($subscriber->getId());
     $subscriber->loadByCustomerId($customerId);
     $this->assertNotEmpty($subscriber->getId());
     $this->assertEquals(1, $subscriber->getStatus());
     $post = ['customer' => ['entity_id' => $customerId], 'subscription' => 'false'];
     $this->getRequest()->setPostValue($post);
     $this->getRequest()->setParam('id', 1);
     $this->dispatch('backend/customer/index/save');
     /** @var \Magento\Newsletter\Model\Subscriber $subscriber */
     $subscriber = $this->objectManager->get('Magento\\Newsletter\\Model\\SubscriberFactory')->create();
     $this->assertEmpty($subscriber->getId());
     $subscriber->loadByCustomerId($customerId);
     $this->assertNotEmpty($subscriber->getId());
     $this->assertEquals(3, $subscriber->getStatus());
     /**
      * Check that success message is set
      */
     $this->assertSessionMessages($this->equalTo(['You saved the customer.']), \Magento\Framework\Message\MessageInterface::TYPE_SUCCESS);
     $this->assertRedirect($this->stringStartsWith($this->_baseControllerUrl . 'index/key/'));
 }
 /**
  * @magentoApiDataFixture Magento/Sales/_files/quote.php
  * @magentoApiDataFixture Magento/Checkout/_files/discount_10percent.php
  */
 public function testSetCouponSuccess()
 {
     /** @var \Magento\Quote\Model\Quote $quote */
     $quote = $this->objectManager->create('Magento\\Quote\\Model\\Quote');
     $quote->load('test01', 'reserved_order_id');
     $cartId = $quote->getId();
     $salesRule = $this->objectManager->create('Magento\\SalesRule\\Model\\Rule');
     $salesRule->load('Test Coupon', 'name');
     $couponCode = $salesRule->getCouponCode();
     $serviceInfo = ['rest' => ['resourcePath' => self::RESOURCE_PATH . $cartId . '/coupons/' . $couponCode, 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT], 'soap' => ['service' => self::SERVICE_NAME, 'serviceVersion' => self::SERVICE_VERSION, 'operation' => self::SERVICE_NAME . 'Set']];
     $requestData = ["cartId" => $cartId, "couponCode" => $couponCode];
     $this->assertTrue($this->_webApiCall($serviceInfo, $requestData));
     $quoteWithCoupon = $this->objectManager->create('Magento\\Quote\\Model\\Quote');
     $quoteWithCoupon->load('test01', 'reserved_order_id');
     $this->assertEquals($quoteWithCoupon->getCouponCode(), $couponCode);
 }
 /**
  * @magentoApiDataFixture Magento/Customer/_files/customer.php
  * @magentoApiDataFixture Magento/Sales/_files/quote.php
  * @magentoApiDataFixture Magento/Checkout/_files/discount_10percent_generalusers.php
  */
 public function testSetMyCouponSuccess()
 {
     $this->_markTestAsRestOnly();
     // get customer ID token
     /** @var \Magento\Integration\Api\CustomerTokenServiceInterface $customerTokenService */
     $customerTokenService = $this->objectManager->create('Magento\\Integration\\Api\\CustomerTokenServiceInterface');
     $token = $customerTokenService->createCustomerAccessToken('*****@*****.**', 'password');
     /** @var \Magento\Quote\Model\Quote $quote */
     $quote = $this->objectManager->create('Magento\\Quote\\Model\\Quote');
     $quote->load('test01', 'reserved_order_id');
     $cartId = $quote->getId();
     /** @var \Magento\SalesRule\Model\Rule $salesRule */
     $salesRule = $this->objectManager->create('Magento\\SalesRule\\Model\\Rule');
     $salesRuleId = $this->objectManager->get('Magento\\Framework\\Registry')->registry('Magento/Checkout/_file/discount_10percent_generalusers');
     $salesRule->load($salesRuleId);
     $couponCode = $salesRule->getPrimaryCoupon()->getCode();
     /* Since this isn't a full quote fixture, need to assign it to the right customer */
     $cartManagementService = $this->objectManager->create('Magento\\Quote\\Api\\CartManagementInterface');
     $cartManagementService->assignCustomer($cartId, 1, 1);
     $serviceInfo = ['rest' => ['resourcePath' => self::RESOURCE_PATH . 'mine/coupons/' . $couponCode, 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT, 'token' => $token]];
     $requestData = ["couponCode" => $couponCode];
     $this->assertTrue($this->_webApiCall($serviceInfo, $requestData));
     $quoteWithCoupon = $this->objectManager->create('Magento\\Quote\\Model\\Quote');
     $quoteWithCoupon->load('test01', 'reserved_order_id');
     $this->assertEquals($quoteWithCoupon->getCouponCode(), $couponCode);
 }
Exemplo n.º 20
0
 /**
  * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
  */
 public function testSaveAddresses()
 {
     /** @var \Magento\Quote\Model\Quote $quote */
     $quote = $this->objectManager->create('Magento\\Quote\\Model\\Quote');
     $quote->load('test_order_1', 'reserved_order_id');
     $serviceInfo = ['rest' => ['resourcePath' => self::RESOURCE_PATH . 'mine/addresses', 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST], 'soap' => ['service' => self::SERVICE_NAME, 'serviceVersion' => self::SERVICE_VERSION, 'operation' => self::SERVICE_NAME . 'SaveAddresses']];
     $addressData = ['firstname' => 'John', 'lastname' => 'Smith', 'email' => '*****@*****.**', 'company' => 'eBay Inc', 'street' => ['Typical Street', 'Tiny House 18'], 'city' => 'Big City', 'region_id' => 12, 'region' => 'California', 'region_code' => 'CA', 'postcode' => '0985432', 'country_id' => 'US', 'telephone' => '88776655', 'fax' => '44332255'];
     $requestData = ['cart_id' => $quote->getId(), 'billingAddress' => $addressData, 'shippingAddress' => $addressData];
     $response = $this->_webApiCall($serviceInfo, $requestData);
     $this->assertArrayHasKey('shipping_methods', $response);
     $this->assertCount(1, $response['shipping_methods']);
     $this->assertEquals('flatrate', $response['shipping_methods'][0]['method_code']);
     $this->assertArrayHasKey('payment_methods', $response);
     $this->assertCount(2, $response['payment_methods']);
     $this->assertEquals('checkmo', $response['payment_methods'][0]['code']);
 }
Exemplo n.º 21
0
 /**
  * @param string $behavior
  * @param string $sourceFile
  * @param array $dataBefore
  * @param array $dataAfter
  * @param array $errors
  *
  * @magentoDataFixture Magento/Customer/_files/import_export/customers_for_address_import.php
  * @magentoAppIsolation enabled
  *
  * @dataProvider importDataDataProvider
  */
 public function testImportData($behavior, $sourceFile, array $dataBefore, array $dataAfter, array $errors = array())
 {
     \Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea(\Magento\Framework\App\Area::AREA_FRONTEND);
     // set entity adapter parameters
     $this->_entityAdapter->setParameters(array('behavior' => $behavior));
     /** @var \Magento\Framework\App\Filesystem $filesystem */
     $filesystem = $this->_objectManager->create('Magento\\Framework\\App\\Filesystem');
     $rootDirectory = $filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem::ROOT_DIR);
     // set fixture CSV file
     $result = $this->_entityAdapter->setSource(\Magento\ImportExport\Model\Import\Adapter::findAdapterFor($sourceFile, $rootDirectory))->isDataValid();
     if ($errors) {
         $this->assertFalse($result);
     } else {
         $this->assertTrue($result);
     }
     // assert validation errors
     // can't use error codes because entity adapter gathers only error messages from aggregated adapters
     $actualErrors = array_values($this->_entityAdapter->getErrorMessages());
     $this->assertEquals($errors, $actualErrors);
     // assert data before import
     $this->_assertCustomerData($dataBefore);
     // import data
     $this->_entityAdapter->importData();
     // assert data after import
     $this->_assertCustomerData($dataAfter);
 }
 /**
  * @magentoApiDataFixture Magento/Checkout/_files/quote_with_shipping_method.php
  */
 public function testGetMyTotals()
 {
     $this->_markTestAsRestOnly();
     // get customer ID token
     /** @var \Magento\Integration\Api\CustomerTokenServiceInterface $customerTokenService */
     $customerTokenService = $this->objectManager->create('Magento\\Integration\\Api\\CustomerTokenServiceInterface');
     $token = $customerTokenService->createCustomerAccessToken('*****@*****.**', 'password');
     /** @var \Magento\Quote\Model\Quote $quote */
     $quote = $this->objectManager->create('Magento\\Quote\\Model\\Quote');
     $quote->load('test_order_1', 'reserved_order_id');
     $serviceInfo = ['rest' => ['resourcePath' => '/V1/carts/mine/totals', 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET, 'token' => $token]];
     /** @var \Magento\Quote\Model\Quote\Address $shippingAddress */
     $shippingAddress = $quote->getShippingAddress();
     $data = [Totals::KEY_GRAND_TOTAL => $quote->getGrandTotal(), Totals::KEY_BASE_GRAND_TOTAL => $quote->getBaseGrandTotal(), Totals::KEY_SUBTOTAL => $quote->getSubtotal(), Totals::KEY_BASE_SUBTOTAL => $quote->getBaseSubtotal(), Totals::KEY_DISCOUNT_AMOUNT => $shippingAddress->getDiscountAmount(), Totals::KEY_BASE_DISCOUNT_AMOUNT => $shippingAddress->getBaseDiscountAmount(), Totals::KEY_SUBTOTAL_WITH_DISCOUNT => $quote->getSubtotalWithDiscount(), Totals::KEY_BASE_SUBTOTAL_WITH_DISCOUNT => $quote->getBaseSubtotalWithDiscount(), Totals::KEY_SHIPPING_AMOUNT => $shippingAddress->getShippingAmount(), Totals::KEY_BASE_SHIPPING_AMOUNT => $shippingAddress->getBaseShippingAmount(), Totals::KEY_SHIPPING_DISCOUNT_AMOUNT => $shippingAddress->getShippingDiscountAmount(), Totals::KEY_BASE_SHIPPING_DISCOUNT_AMOUNT => $shippingAddress->getBaseShippingDiscountAmount(), Totals::KEY_TAX_AMOUNT => $shippingAddress->getTaxAmount(), Totals::KEY_BASE_TAX_AMOUNT => $shippingAddress->getBaseTaxAmount(), Totals::KEY_SHIPPING_TAX_AMOUNT => $shippingAddress->getShippingTaxAmount(), Totals::KEY_BASE_SHIPPING_TAX_AMOUNT => $shippingAddress->getBaseShippingTaxAmount(), Totals::KEY_SUBTOTAL_INCL_TAX => $shippingAddress->getSubtotalInclTax(), Totals::KEY_BASE_SUBTOTAL_INCL_TAX => $shippingAddress->getBaseSubtotalTotalInclTax(), Totals::KEY_SHIPPING_INCL_TAX => $shippingAddress->getShippingInclTax(), Totals::KEY_BASE_SHIPPING_INCL_TAX => $shippingAddress->getBaseShippingInclTax(), Totals::KEY_BASE_CURRENCY_CODE => $quote->getBaseCurrencyCode(), Totals::KEY_QUOTE_CURRENCY_CODE => $quote->getQuoteCurrencyCode(), Totals::KEY_ITEMS_QTY => $quote->getItemsQty(), Totals::KEY_ITEMS => [$this->getQuoteItemTotalsData($quote)]];
     $data = $this->formatTotalsData($data);
     $actual = $this->_webApiCall($serviceInfo);
     unset($actual['items'][0]['options']);
     unset($actual['weee_tax_applied_amount']);
     /** TODO: cover total segments with separate test */
     unset($actual['total_segments']);
     if (array_key_exists('extension_attributes', $actual)) {
         unset($actual['extension_attributes']);
     }
     $this->assertEquals($data, $actual);
 }
 /**
  * @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php
  */
 public function testUpdateItem()
 {
     /** @var \Magento\Quote\Model\Quote  $quote */
     $quote = $this->objectManager->create('Magento\\Quote\\Model\\Quote');
     $quote->load('test_order_item_with_items', 'reserved_order_id');
     $cartId = $quote->getId();
     /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */
     $quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Quote\\Model\\QuoteIdMaskFactory')->create();
     $quoteIdMask->load($cartId, 'quote_id');
     //Use masked cart Id
     $cartId = $quoteIdMask->getMaskedId();
     $product = $this->objectManager->create('Magento\\Catalog\\Model\\Product');
     $productId = $product->getIdBySku('simple_one');
     $product->load($productId);
     $itemId = $quote->getItemByProduct($product)->getId();
     $serviceInfo = ['rest' => ['resourcePath' => self::RESOURCE_PATH . $cartId . '/items/' . $itemId, 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT], 'soap' => ['service' => self::SERVICE_NAME, 'serviceVersion' => self::SERVICE_VERSION, 'operation' => self::SERVICE_NAME . 'Save']];
     if (TESTS_WEB_API_ADAPTER == self::ADAPTER_SOAP) {
         $requestData = ["cartItem" => ["qty" => 5, "quote_id" => $cartId, "itemId" => $itemId]];
     } else {
         $requestData = ["cartItem" => ["qty" => 5, "quote_id" => $cartId]];
     }
     $this->_webApiCall($serviceInfo, $requestData);
     $quote = $this->objectManager->create('Magento\\Quote\\Model\\Quote');
     $quote->load('test_order_item_with_items', 'reserved_order_id');
     $this->assertTrue($quote->hasProductId(1));
     $item = $quote->getItemByProduct($product);
     $this->assertEquals(5, $item->getQty());
     $this->assertEquals($itemId, $item->getItemId());
 }
 /**
  * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
  */
 public function testSetMyAddress()
 {
     $this->_markTestAsRestOnly();
     // get customer ID token
     /** @var \Magento\Integration\Api\CustomerTokenServiceInterface $customerTokenService */
     $customerTokenService = $this->objectManager->create('Magento\\Integration\\Api\\CustomerTokenServiceInterface');
     $token = $customerTokenService->createCustomerAccessToken('*****@*****.**', 'password');
     /** @var \Magento\Quote\Model\Quote $quote */
     $quote = $this->objectManager->create('Magento\\Quote\\Model\\Quote');
     $quote->load('test_order_1', 'reserved_order_id');
     $serviceInfo = ['rest' => ['resourcePath' => self::RESOURCE_PATH . 'mine/billing-address', 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST, 'token' => $token]];
     $addressData = ['firstname' => 'John', 'lastname' => 'Smith', 'company' => 'Magento Commerce Inc.', 'street' => ['Typical Street', 'Tiny House 18'], 'city' => 'Big City', 'region_id' => 12, 'region' => 'California', 'region_code' => 'CA', 'postcode' => '0985432', 'country_id' => 'US', 'telephone' => '88776655', 'fax' => '44332255'];
     $requestData = ['address' => $addressData];
     $addressId = $this->_webApiCall($serviceInfo, $requestData);
     //reset $quote to reload data
     $quote = $this->objectManager->create('Magento\\Quote\\Model\\Quote');
     $quote->load('test_order_1', 'reserved_order_id');
     $address = $quote->getBillingAddress();
     $address->getRegionCode();
     $savedData = $address->getData();
     $this->assertEquals($addressId, $savedData['address_id']);
     //custom checks for street, region and address_type
     foreach ($addressData['street'] as $streetLine) {
         $this->assertContains($streetLine, $quote->getBillingAddress()->getStreet());
     }
     unset($addressData['street']);
     $this->assertEquals('billing', $savedData['address_type']);
     //check the rest of fields
     foreach ($addressData as $key => $value) {
         $this->assertEquals($value, $savedData[$key]);
     }
 }
Exemplo n.º 25
0
 /**
  * @magentoApiDataFixture Magento/GiftMessage/_files/quote_with_item_message.php
  */
 public function testSaveForMyCart()
 {
     $this->_markTestAsRestOnly();
     // get customer ID token
     /** @var \Magento\Integration\Api\CustomerTokenServiceInterface $customerTokenService */
     $customerTokenService = $this->objectManager->create('Magento\\Integration\\Api\\CustomerTokenServiceInterface');
     $token = $customerTokenService->createCustomerAccessToken('*****@*****.**', 'password');
     // sales/gift_options/allow_items must be set to 1 in system configuration
     // @todo remove next statement when \Magento\TestFramework\TestCase\WebapiAbstract::_updateAppConfig is fixed
     $this->markTestIncomplete('This test relies on system configuration state.');
     /** @var \Magento\Quote\Model\Quote $quote */
     $quote = $this->objectManager->create('Magento\\Quote\\Model\\Quote');
     $quote->load('test_order_item_with_message', 'reserved_order_id');
     $product = $this->objectManager->create('Magento\\Catalog\\Model\\Product');
     $product->load($product->getIdBySku('simple_with_message'));
     $itemId = $quote->getItemByProduct($product)->getId();
     $serviceInfo = ['rest' => ['resourcePath' => self::RESOURCE_PATH . 'mine/gift-message/' . $itemId, 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST, 'token' => $token]];
     $requestData = ['itemId' => $itemId, 'giftMessage' => ['recipient' => 'John Doe', 'sender' => 'Jane Roe', 'message' => 'Gift Message Text New']];
     $this->assertTrue($this->_webApiCall($serviceInfo, $requestData));
     //        $quote->load('test_order_item_with_message', 'reserved_order_id');
     $messageId = $quote->getItemByProduct($product)->getGiftMessageId();
     /** @var  \Magento\GiftMessage\Model\Message $message */
     $message = $this->objectManager->create('Magento\\GiftMessage\\Model\\Message')->load($messageId);
     $this->assertEquals('John Doe', $message->getRecipient());
     $this->assertEquals('Jane Roe', $message->getSender());
     $this->assertEquals('Gift Message Text New', $message->getMessage());
 }
Exemplo n.º 26
0
 /**
  * @covers \Magento\Catalog\Model\Product\Gallery\ReadHandler::execute
  */
 public function testExecute()
 {
     /** @var \Magento\Catalog\Model\Product $product */
     $product = $this->objectManager->create('Magento\\Catalog\\Model\\Product');
     /**
      * @var $entityMetadata \Magento\Framework\Model\Entity\EntityMetadata
      */
     $entityMetadata = $this->objectManager->get(MetadataPool::class)->getMetadata(ProductInterface::class);
     $productRepository = $this->objectManager->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
     $linkFieldId = $productRepository->get('simple')->getData($entityMetadata->getLinkField());
     $product->setData($entityMetadata->getLinkField(), $linkFieldId);
     $this->readHandler->execute('Magento\\Catalog\\Api\\Data\\ProductInterface', $product);
     $data = $product->getData();
     $this->assertArrayHasKey('media_gallery', $data);
     $this->assertArrayHasKey('images', $data['media_gallery']);
     $this->assertEquals('Image Alt Text', $data['media_gallery']['images'][0]['label']);
 }
Exemplo n.º 27
0
 /**
  * @magentoDataFixture Magento/Store/_files/core_fixturestore.php
  * @magentoComponentsDir Magento/Email/Model/_files/design
  * @magentoAppIsolation enabled
  * @magentoDbIsolation enabled
  * @dataProvider inlinecssDirectiveThrowsExceptionWhenMissingParameterDataProvider
  *
  * @param string $templateText
  */
 public function testInlinecssDirectiveThrowsExceptionWhenMissingParameter($templateText)
 {
     /** @var \Magento\Theme\Model\Theme\Registration $registration */
     $registration = $this->objectManager->get('Magento\\Theme\\Model\\Theme\\Registration');
     $registration->register();
     $this->setUpDesignParams();
     $this->model->filter($templateText);
 }
Exemplo n.º 28
0
 /**
  * @magentoDataFixture Magento/Store/_files/store.php
  * @magentoDataFixture Magento/Tax/_files/tax_classes.php
  */
 public function testGetTitles()
 {
     /** @var \Magento\Tax\Model\Calculation\Rate $rate */
     $rate = $this->_objectManager->create('Magento\\Tax\\Model\\Calculation\\Rate');
     $rate->load(1);
     /** @var \Magento\Store\Model\Store $store */
     $store = $this->_objectManager->get('Magento\\Store\\Model\\Store');
     $store->load('test', 'code');
     $title = 'title';
     $rate->saveTitles([$store->getId() => $title]);
     $coreRegistry = $this->_objectManager->create('Magento\\Framework\\Registry');
     $coreRegistry->register(RegistryConstants::CURRENT_TAX_RATE_ID, 1);
     /** @var \Magento\Tax\Block\Adminhtml\Rate\Title $block */
     $block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Tax\\Block\\Adminhtml\\Rate\\Title', ['coreRegistry' => $coreRegistry]);
     $titles = $block->getTitles();
     $this->assertArrayHasKey($store->getId(), $titles, 'Store was not created');
     $this->assertEquals($title, $titles[$store->getId()], 'Invalid Tax Title');
 }
 /**
  * Set address to quote with virtual products only
  *
  * @expectedException \Exception
  * @expectedExceptionMessage Cart contains virtual product(s) only. Shipping address is not applicable
  *
  * @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_and_address.php
  */
 public function testSetAddressForVirtualQuote()
 {
     /** @var \Magento\Quote\Model\Quote $quote */
     $quote = $this->objectManager->create('Magento\\Quote\\Model\\Quote');
     $quote->load('test_order_with_virtual_product', 'reserved_order_id');
     $serviceInfo = ['rest' => ['resourcePath' => self::RESOURCE_PATH . $quote->getId() . '/shipping-address', 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST], 'soap' => ['service' => self::SERVICE_NAME, 'serviceVersion' => self::SERVICE_VERSION, 'operation' => self::SERVICE_NAME . 'Assign']];
     $addressData = ['firstname' => 'John', 'lastname' => 'Smith', 'email' => '*****@*****.**', 'company' => 'eBay Inc', 'street' => ['Typical Street', 'Tiny House 18'], 'city' => 'Big City', 'region_id' => 12, 'region' => 'California', 'region_code' => 'CA', 'postcode' => '0985432', 'country_id' => 'US', 'telephone' => '88776655', 'fax' => '44332255'];
     $requestData = ["cartId" => $quote->getId(), 'address' => $addressData];
     $this->_webApiCall($serviceInfo, $requestData);
 }
 /**
  * @magentoApiDataFixture Magento/Sales/_files/order.php
  */
 public function testGetList()
 {
     /** @var \Magento\Sales\Model\Order $order */
     $order = $this->objectManager->create('Magento\\Sales\\Model\\Order');
     $order->loadByIncrementId(self::ORDER_INCREMENT_ID);
     /** @var $searchCriteriaBuilder  \Magento\Framework\Api\SearchCriteriaBuilder */
     $searchCriteriaBuilder = $this->objectManager->create('Magento\\Framework\\Api\\SearchCriteriaBuilder');
     /** @var $filterBuilder  \Magento\Framework\Api\FilterBuilder */
     $filterBuilder = $this->objectManager->create('Magento\\Framework\\Api\\FilterBuilder');
     $searchCriteriaBuilder->addFilters([$filterBuilder->setField('order_id')->setValue($order->getId())->create()]);
     $requestData = ['criteria' => $searchCriteriaBuilder->create()->__toArray()];
     $serviceInfo = ['rest' => ['resourcePath' => self::RESOURCE_PATH . '?' . http_build_query($requestData), 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET], 'soap' => ['service' => self::SERVICE_NAME, 'serviceVersion' => self::SERVICE_VERSION, 'operation' => self::SERVICE_NAME . 'getList']];
     $response = $this->_webApiCall($serviceInfo, $requestData);
     $this->assertTrue(is_array($response));
     $this->assertArrayHasKey('items', $response);
     $this->assertCount(1, $response['items']);
     $this->assertTrue(is_array($response['items'][0]));
     $this->assertOrderItem(current($order->getItems()), $response['items'][0]);
 }