/** * Returns data for Web API params. * * @param TaxRule $fixture * @return array */ protected function prepareData(TaxRule $fixture) { $data = $fixture->getData(); $data = $this->taxRuleCurl->prepareFieldData($fixture, $data, 'tax_rate', 'tax_rate_ids'); $data = $this->taxRuleCurl->prepareFieldData($fixture, $data, 'tax_product_class', 'product_tax_class_ids'); $data = $this->taxRuleCurl->prepareFieldData($fixture, $data, 'tax_customer_class', 'customer_tax_class_ids'); return ['rule' => $data]; }
/** * Delete Tax Rule Entity test. * * @param TaxRule $taxRule * @return void */ public function testDeleteTaxRule(TaxRule $taxRule) { // Precondition $taxRule->persist(); // Steps $this->taxRuleIndexPage->open(); $this->taxRuleIndexPage->getTaxRuleGrid()->searchAndOpen(['code' => $taxRule->getCode()]); $this->taxRuleNewPage->getFormPageActions()->delete(); }
/** * Update Tax Rule Entity test. * * @param TaxRule $initialTaxRule * @param TaxRule $taxRule * @return void */ public function testUpdateTaxRule(TaxRule $initialTaxRule, TaxRule $taxRule) { // Precondition $initialTaxRule->persist(); // Steps $this->taxRuleIndexPage->open(); $this->taxRuleIndexPage->getTaxRuleGrid()->searchAndOpen(['code' => $initialTaxRule->getCode()]); $this->taxRuleNewPage->getTaxRuleForm()->fill($taxRule); $this->taxRuleNewPage->getFormPageActions()->save(); }
/** * Assert tax rule availability in Tax Rule grid * * @param TaxRuleIndex $taxRuleIndex * @param TaxRule $taxRule * @param TaxRule $initialTaxRule */ public function processAssert(TaxRuleIndex $taxRuleIndex, TaxRule $taxRule, TaxRule $initialTaxRule = null) { if ($initialTaxRule !== null) { $taxRuleCode = $taxRule->hasData('code') ? $taxRule->getCode() : $initialTaxRule->getCode(); } else { $taxRuleCode = $taxRule->getCode(); } $filter = ['code' => $taxRuleCode]; $taxRuleIndex->open(); \PHPUnit_Framework_Assert::assertTrue($taxRuleIndex->getTaxRuleGrid()->isRowVisible($filter), 'Tax Rule \'' . $filter['code'] . '\' is absent in Tax Rule grid.'); }
/** * 1. Creating product simple with custom tax product class * 2. Log In as customer * 3. Add product to shopping cart * 4. Estimate Shipping and Tax * 5. Implementation assert * * @param FixtureFactory $fixtureFactory * @param TaxRule $taxRule * @param Customer $customer * @param CatalogProductView $catalogProductView * @param CheckoutCart $checkoutCart * @param Address $address * @param array $shipping * @param BrowserInterface $browser * @param TaxRule $initialTaxRule * @return void */ public function processAssert(FixtureFactory $fixtureFactory, TaxRule $taxRule, Customer $customer, CatalogProductView $catalogProductView, CheckoutCart $checkoutCart, Address $address, array $shipping, BrowserInterface $browser, TaxRule $initialTaxRule = null) { $this->initialTaxRule = $initialTaxRule; $this->taxRule = $taxRule; $this->checkoutCart = $checkoutCart; $this->shipping = $shipping; if ($this->initialTaxRule !== null) { $this->taxRuleCode = $this->taxRule->hasData('code') ? $this->taxRule->getCode() : $this->initialTaxRule->getCode(); } else { $this->taxRuleCode = $this->taxRule->getCode(); } // Creating simple product with custom tax class /** @var \Magento\Tax\Test\Fixture\TaxClass $taxProductClass */ $taxProductClass = $taxRule->getDataFieldConfig('tax_product_class')['source']->getFixture()[0]; $this->productSimple = $fixtureFactory->createByCode('catalogProductSimple', ['dataSet' => 'product_100_dollar_for_tax_rule', 'data' => ['tax_class_id' => ['tax_product_class' => $taxProductClass]]]); $this->productSimple->persist(); // Customer login $this->objectManager->create('Magento\\Customer\\Test\\TestStep\\LoginCustomerOnFrontendStep', ['customer' => $customer])->run(); // Clearing shopping cart and adding product to shopping cart $checkoutCart->open()->getCartBlock()->clearShoppingCart(); $browser->open($_ENV['app_frontend_url'] . $this->productSimple->getUrlKey() . '.html'); $catalogProductView->getViewBlock()->clickAddToCart(); $catalogProductView->getMessagesBlock()->waitSuccessMessage(); // Estimate Shipping and Tax $checkoutCart->open(); $checkoutCart->getShippingBlock()->openEstimateShippingAndTax(); $checkoutCart->getShippingBlock()->fill($address); $checkoutCart->getShippingBlock()->clickGetQuote(); $checkoutCart->getShippingBlock()->selectShippingMethod($shipping); $this->assert(); }
/** * Prepare tax rule field data using new field. * * @param TaxRule $fixture * @param array $data * @param string $fixtureField * @param string $newField * @return array */ public function prepareFieldData(TaxRule $fixture, array $data, $fixtureField, $newField = null) { $newField = $newField === null ? $fixtureField : $newField; unset($data[$fixtureField]); if (!$fixture->hasData($fixtureField)) { $data[$newField][] = $this->defaultTaxClasses[$fixtureField]; } else { foreach ($fixture->getDataFieldConfig($fixtureField)['source']->getFixture() as $taxField) { if (!$taxField->hasData('id')) { $taxField->persist(); } $data[$newField][] = $taxField->getId(); } } return $data; }
/** * Assert that tax rule form filled right * * @param TaxRuleNew $taxRuleNew * @param TaxRuleIndex $taxRuleIndex * @param TaxRule $taxRule * @param TaxRule $initialTaxRule */ public function processAssert(TaxRuleNew $taxRuleNew, TaxRuleIndex $taxRuleIndex, TaxRule $taxRule, TaxRule $initialTaxRule = null) { $data = $taxRule->getData(); if ($initialTaxRule !== null) { $taxRuleCode = $taxRule->hasData('code') ? $taxRule->getCode() : $initialTaxRule->getCode(); } else { $taxRuleCode = $taxRule->getCode(); } $filter = ['code' => $taxRuleCode]; $taxRuleIndex->open(); $taxRuleIndex->getTaxRuleGrid()->searchAndOpen($filter); $taxRuleNew->getTaxRuleForm()->openAdditionalSettings(); $formData = $taxRuleNew->getTaxRuleForm()->getData($taxRule); $dataDiff = $this->verifyForm($formData, $data); \PHPUnit_Framework_Assert::assertTrue(empty($dataDiff), 'Tax Rule form was filled not right.' . "\nLog:\n" . implode(";\n", $dataDiff)); }
/** * Automatic Apply Tax Based on VAT ID. * * @param ConfigData $vatConfig * @param OrderInjectable $order * @param TaxRule $taxRule * @param Cart $cart * @param string $configData * @param string $customerGroup * @return array */ public function test(ConfigData $vatConfig, OrderInjectable $order, TaxRule $taxRule, Cart $cart, $configData, $customerGroup) { // Preconditions $this->configData = $configData; $this->objectManager->create('Magento\\Config\\Test\\TestStep\\SetupConfigurationStep', ['configData' => $this->configData])->run(); $taxRule->persist(); // Prepare data $this->customer = $order->getDataFieldConfig('customer_id')['source']->getCustomer(); $address = $this->customer->getDataFieldConfig('address')['source']->getAddresses()[0]; $this->prepareVatConfig($vatConfig, $customerGroup); $poducts = $order->getEntityId()['products']; $cart = $this->fixtureFactory->createByCode('cart', ['data' => array_merge($cart->getData(), ['items' => ['products' => $poducts]])]); // Steps $order->persist(); $this->objectManager->create('Magento\\Customer\\Test\\TestStep\\LoginCustomerOnFrontendStep', ['customer' => $this->customer])->run(); $this->objectManager->create('Magento\\Checkout\\Test\\TestStep\\AddProductsToTheCartStep', $order->getEntityId())->run(); $this->checkoutCart->open(); $this->checkoutCart->getCartBlock()->waitCartContainerLoading(); $this->checkoutCart->getShippingBlock()->fillEstimateShippingAndTax($address); $this->checkoutCart->getCartBlock()->waitCartContainerLoading(); return ['customer' => $this->customer, 'address' => $address, 'orderId' => $order->getId(), 'cart' => $cart, 'products' => $poducts]; }
/** * Assert existing tax rule on manage tax rule grid * * @param TaxRule $fixture */ protected function _assertOnGrid(TaxRule $fixture) { //Data $filter = ['code' => $fixture->getCode(), 'tax_rate' => implode(', ', $fixture->getTaxRate())]; if ($fixture->getTaxCustomerClass() !== null) { $filter['tax_customer_class'] = implode(', ', $fixture->getTaxCustomerClass()); } if ($fixture->getTaxProductClass() !== null) { $filter['tax_product_class'] = implode(', ', $fixture->getTaxProductClass()); } //Verification $taxGridPage = Factory::getPageFactory()->getTaxRuleIndex(); $taxGridPage->open(); $this->assertTrue($taxGridPage->getTaxRuleGrid()->isRowVisible($filter), 'New tax rule was not found.'); }
/** * Assert that tax rule not available in Tax Rule grid * * @param TaxRuleIndex $taxRuleIndex * @param TaxRule $taxRule * @return void */ public function processAssert(TaxRuleIndex $taxRuleIndex, TaxRule $taxRule) { $filter = ['code' => $taxRule->getCode()]; $taxRuleIndex->open(); \PHPUnit_Framework_Assert::assertFalse($taxRuleIndex->getTaxRuleGrid()->isRowVisible($filter), 'Tax Rule \'' . $filter['code'] . '\' is present in Tax Rule grid.'); }
/** * Method to add new tax rate. * * @param TaxRule $taxRule * @return void */ protected function addNewTaxRates($taxRule) { $rootForm = $this; $taxRateMultiSelectList = $this->taxRateMultiSelectList; $taxRateDefaultMultiSelect = $this->taxRateDefaultMultiSelect; $this->browser->waitUntil(function () use($rootForm, $taxRateDefaultMultiSelect) { $element = $rootForm->browser->find($taxRateDefaultMultiSelect); return $element->isVisible() ? null : true; }); $this->browser->waitUntil(function () use($rootForm, $taxRateMultiSelectList) { $element = $rootForm->browser->find($taxRateMultiSelectList); return $element->isVisible() ? true : null; }); $taxRateBlock = $this->_rootElement->find($this->taxRateBlock, Locator::SELECTOR_CSS, 'multiselectlist'); /** @var \Magento\Tax\Test\Block\Adminhtml\Rule\Edit\TaxRate $taxRateForm */ $taxRateForm = $this->blockFactory->create('Magento\\Tax\\Test\\Block\\Adminhtml\\Rule\\Edit\\TaxRate', ['element' => $this->browser->find($this->taxRateForm)]); /** @var \Magento\Tax\Test\Fixture\TaxRule\TaxRate $taxRatesFixture */ $taxRatesFixture = $taxRule->getDataFieldConfig('tax_rate')['source']; $taxRatesFixture = $taxRatesFixture->getFixture(); $taxRatesData = $taxRule->getTaxRate(); foreach ($taxRatesData as $key => $taxRate) { $option = $taxRateBlock->find(sprintf($this->optionMaskElement, $taxRate), Locator::SELECTOR_XPATH); if (!$option->isVisible()) { $taxRate = $taxRatesFixture[$key]; $this->clickAddNewButton($taxRateBlock); $taxRateForm->fill($taxRate); $taxRateForm->saveTaxRate(); /** @var \Magento\Tax\Test\Fixture\TaxRate $taxRate */ $code = $taxRate->getCode(); $this->waitUntilOptionIsVisible($taxRateBlock, $code); } } }
/** * Update Tax Rule Entity test * * @param TaxRule $initialTaxRule * @param TaxRule $taxRule * @param AddressInjectable $address * @param array $shipping * @return void * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function testUpdateTaxRule(TaxRule $initialTaxRule, TaxRule $taxRule, AddressInjectable $address, array $shipping) { // Precondition $initialTaxRule->persist(); // Steps $filters = ['code' => $initialTaxRule->getCode()]; $this->taxRuleIndexPage->open(); $this->taxRuleIndexPage->getTaxRuleGrid()->searchAndOpen($filters); $this->taxRuleNewPage->getTaxRuleForm()->fill($taxRule); $this->taxRuleNewPage->getFormPageActions()->save(); }
/** * 1. Creating product simple with custom tax product class * 2. Log In as customer * 3. Add product to shopping cart * 4. Estimate Shipping and Tax * 5. Implementation assert * * @param FixtureFactory $fixtureFactory * @param TaxRule $taxRule * @param CustomerAccountLogin $customerAccountLogin * @param CustomerAccountLogout $customerAccountLogout * @param CustomerInjectable $customer * @param CatalogProductView $catalogProductView * @param CheckoutCart $checkoutCart * @param AddressInjectable $address * @param array $shipping * @param TaxRule $initialTaxRule * @return void * * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function processAssert(FixtureFactory $fixtureFactory, TaxRule $taxRule, CustomerAccountLogin $customerAccountLogin, CustomerAccountLogout $customerAccountLogout, CustomerInjectable $customer, CatalogProductView $catalogProductView, CheckoutCart $checkoutCart, AddressInjectable $address, array $shipping, TaxRule $initialTaxRule = null) { $this->initialTaxRule = $initialTaxRule; $this->taxRule = $taxRule; $this->checkoutCart = $checkoutCart; $this->shipping = $shipping; if ($this->initialTaxRule !== null) { $this->taxRuleCode = $this->taxRule->hasData('code') ? $this->taxRule->getCode() : $this->initialTaxRule->getCode(); } else { $this->taxRuleCode = $this->taxRule->getCode(); } // Creating simple product with custom tax class /** @var \Magento\Tax\Test\Fixture\TaxClass $taxProductClass */ $taxProductClass = $taxRule->getDataFieldConfig('tax_product_class')['source']->getFixture()[0]; $this->productSimple = $fixtureFactory->createByCode('catalogProductSimple', ['dataSet' => '100_dollar_product_for_tax_rule', 'data' => ['tax_class_id' => ['tax_product_class' => $taxProductClass]]]); $this->productSimple->persist(); // Customer login $customerAccountLogout->open(); $customerAccountLogin->open(); $customerAccountLogin->getLoginBlock()->login($customer); // Clearing shopping cart and adding product to shopping cart $checkoutCart->open()->getCartBlock()->clearShoppingCart(); $catalogProductView->init($this->productSimple); $catalogProductView->open(); $catalogProductView->getViewBlock()->clickAddToCart(); // Estimate Shipping and Tax $checkoutCart->getShippingBlock()->openEstimateShippingAndTax(); $checkoutCart->getShippingBlock()->fill($address); $checkoutCart->getShippingBlock()->clickGetQuote(); $checkoutCart->getShippingBlock()->selectShippingMethod($shipping); $this->assert(); }
/** * Create tax report entity. * * @param OrderInjectable $order * @param TaxRule $taxRule * @param array $report * @param string $orderSteps * @return void */ public function test(OrderInjectable $order, TaxRule $taxRule, array $report, $orderSteps) { // Precondition $taxRule->persist(); $this->taxRule = $taxRule; $order->persist(); $this->orderIndex->open(); $this->orderIndex->getSalesOrderGrid()->searchAndOpen(['id' => $order->getId()]); $this->processOrder($orderSteps, $order); $this->reportStatistic->open(); $this->reportStatistic->getGridBlock()->massaction([['report' => 'Tax']], 'Refresh Statistics for the Last Day', true); // Steps $this->salesTaxReport->open(); $this->salesTaxReport->getFilterBlock()->viewsReport($report); $this->salesTaxReport->getActionBlock()->showReport(); }
/** * Assert sales info in report: Tax, Rate, Orders, Tax Amount on tax report page * * @param SalesTaxReport $salesTaxReport * @param OrderInjectable $order * @param TaxRule $taxRule * @param string $taxAmount * @return void */ public function processAssert(SalesTaxReport $salesTaxReport, OrderInjectable $order, TaxRule $taxRule, $taxAmount) { $filter = ['tax' => $taxRule->getTaxRate()[0], 'rate' => $taxRule->getDataFieldConfig('tax_rate')['source']->getFixture()[0]->getRate(), 'orders' => count($order->getEntityId()['products']), 'tax_amount' => $taxAmount]; \PHPUnit_Framework_Assert::assertTrue($salesTaxReport->getGridBlock()->isRowVisible($filter, false), "Tax Report is not visible in grid on tax report page."); }