Exemple #1
0
 /**
  * @magentoDataFixture Magento/Catalog/_files/multiple_products.php
  */
 public function testConvertAttributeWithMultipleProducts()
 {
     $productA = $this->objectManager->create('Magento\\Catalog\\Model\\Product');
     $productA->load(10);
     $productA->setTaxClassId($this->taxClasses['DefaultProductClass']);
     $productAGoogleShoppingEntry = $this->objectManager->create('Magento\\Framework\\Gdata\\Gshopping\\Entry');
     $productAEntry = $this->googleShoppingTaxAttribute->convertAttribute($productA, $productAGoogleShoppingEntry);
     $this->assertEquals(2, count($productAEntry->getTaxes()));
     foreach ($productAEntry->getTaxes() as $tax) {
         $this->assertEquals('US', $tax->__get('tax_country'));
         $this->assertEquals(7.5, round($tax->__get('tax_rate'), 1));
         $this->assertTrue($tax->__get('tax_region') == 'NM' || $tax->__get('tax_region') == 'CA');
     }
     $productB = $this->objectManager->create('Magento\\Catalog\\Model\\Product');
     $productB->load(11);
     $productB->setTaxClassId($this->taxClasses['HigherProductClass']);
     $productBGoogleShoppingEntry = $this->objectManager->create('Magento\\Framework\\Gdata\\Gshopping\\Entry');
     $productBEntry = $this->googleShoppingTaxAttribute->convertAttribute($productB, $productBGoogleShoppingEntry);
     $this->assertEquals(2, count($productBEntry->getTaxes()));
     foreach ($productBEntry->getTaxes() as $tax) {
         $this->assertEquals('US', $tax->__get('tax_country'));
         if ($tax->__get('tax_region') == 'NM') {
             $this->assertEquals(22.0, round($tax->__get('tax_rate'), 1));
         } elseif ($tax->__get('tax_region') == 'CA') {
             $this->assertEquals(10.0, round($tax->__get('tax_rate'), 1));
         } else {
             $this->fail('Invalid tax region');
         }
     }
     $productC = $this->objectManager->create('Magento\\Catalog\\Model\\Product');
     $productC->load(12);
     $productC->setTaxClassId($this->taxClasses['HighestProductClass']);
     $productCGoogleShoppingEntry = $this->objectManager->create('Magento\\Framework\\Gdata\\Gshopping\\Entry');
     $productCEntry = $this->googleShoppingTaxAttribute->convertAttribute($productC, $productCGoogleShoppingEntry);
     $this->assertEquals(2, count($productCEntry->getTaxes()));
     foreach ($productCEntry->getTaxes() as $tax) {
         $this->assertEquals('US', $tax->__get('tax_country'));
         if ($tax->__get('tax_region') == 'NM') {
             $this->assertEquals(22.5, round($tax->__get('tax_rate'), 1));
         } elseif ($tax->__get('tax_region') == 'CA') {
             $this->assertEquals(15.0, round($tax->__get('tax_rate'), 1));
         } else {
             $this->fail('Invalid tax_region');
         }
     }
 }
Exemple #2
0
 public function testConvertAttribute()
 {
     $productStoreId = 'product_store_id';
     $sku = 'sku';
     $price = 'price';
     $name = 'name';
     $productTaxClassId = 'product_tax_class_id';
     $customerTaxClassId = 'tax_class_id';
     $postCode = '90210';
     $this->setUpGetDefaultCustomerTaxClass($customerTaxClassId, $productStoreId);
     $this->setUpGetRegionsByRegionId($postCode, '*');
     $this->mockTaxHelper->expects($this->any())->method('getConfig')->will($this->returnSelf());
     $this->mockTaxHelper->expects($this->any())->method('priceIncludesTax')->will($this->returnValue(false));
     $mockTaxRate = $this->getMockBuilder('Magento\\Tax\\Service\\V1\\Data\\TaxRate')->disableOriginalConstructor()->getMock();
     $rates = [$mockTaxRate];
     $this->mockTaxRuleService->expects($this->once())->method('getRatesByCustomerAndProductTaxClassId')->with($customerTaxClassId, $productTaxClassId)->will($this->returnValue($rates));
     $targetCountry = 'target_country';
     $this->mockConfig->expects($this->once())->method('getTargetCountry')->with($productStoreId)->will($this->returnValue($targetCountry));
     $mockTaxRate->expects($this->once())->method('getCountryId')->will($this->returnValue($targetCountry));
     $mockTaxRate->expects($this->once())->method('getPostcode')->will($this->returnValue($postCode));
     $mockTaxRate->expects($this->any())->method('getRegionId')->will($this->returnValue($postCode));
     $this->mockQuoteDetailsBuilder->expects($this->once())->method('populateWithArray')->with(['billing_address' => ['country_id' => $targetCountry, 'region' => ['region_id' => $postCode], 'postcode' => $postCode], 'shipping_address' => ['country_id' => $targetCountry, 'region' => ['region_id' => $postCode], 'postcode' => $postCode], 'customer_tax_class_key' => ['type' => 'id', 'value' => $customerTaxClassId], 'items' => [['code' => $sku, 'type' => 'product', 'tax_class_key' => ['type' => 'id', 'value' => $productTaxClassId], 'unit_price' => $price, 'quantity' => 1, 'tax_included' => 1, 'short_description' => $name]]])->will($this->returnSelf());
     /** @var \Magento\Tax\Service\V1\Data\QuoteDetails
      * | \PHPUnit_Framework_MockObject_MockObject $quoteDetailsObject */
     $quoteDetailsObject = $this->getMockBuilder('Magento\\Tax\\Service\\V1\\Data\\QuoteDetails')->disableOriginalConstructor()->getMock();
     $this->mockQuoteDetailsBuilder->expects($this->once())->method('create')->will($this->returnValue($quoteDetailsObject));
     $taxDetailsObject = $this->getMockBuilder('\\Magento\\Tax\\Service\\V1\\Data\\TaxDetails')->disableOriginalConstructor()->getMock();
     $this->mockTaxCalculationService->expects($this->once())->method('calculateTax')->with($quoteDetailsObject, $productStoreId)->will($this->returnValue($taxDetailsObject));
     $taxAmount = 777;
     $subTotal = 555;
     $taxDetailsObject->expects($this->once())->method('getTaxAmount')->will($this->returnValue($taxAmount));
     $taxDetailsObject->expects($this->once())->method('getSubtotal')->will($this->returnValue($subTotal));
     $taxRate = $taxAmount / $subTotal * 100;
     // mock product
     $mockProduct = $this->getMockProduct($productStoreId, $productTaxClassId, $sku, $price, $name);
     $mockEntry = $this->getMockEntry();
     $mockEntry->expects($this->once())->method('addTax')->with(['tax_rate' => $taxRate, 'tax_country' => $targetCountry, 'tax_region' => $postCode]);
     $this->assertSame($mockEntry, $this->model->convertAttribute($mockProduct, $mockEntry));
 }