/**
  * Helper function that sets up some default rules
  */
 private function setUpDefaultRules()
 {
     $this->taxClasses = $this->taxRuleFixtureFactory->createTaxClasses([['name' => 'DefaultCustomerClass', 'type' => ClassModel::TAX_CLASS_TYPE_CUSTOMER], ['name' => 'DefaultProductClass', 'type' => ClassModel::TAX_CLASS_TYPE_PRODUCT], ['name' => 'HigherProductClass', 'type' => ClassModel::TAX_CLASS_TYPE_PRODUCT]]);
     $this->taxRates = $this->taxRuleFixtureFactory->createTaxRates([['percentage' => 7.5, 'country' => 'US', 'region' => 42], ['percentage' => 7.5, 'country' => 'US', 'region' => 12]]);
     $higherRates = $this->taxRuleFixtureFactory->createTaxRates([['percentage' => 22, 'country' => 'US', 'region' => 42], ['percentage' => 10, 'country' => 'US', 'region' => 12]]);
     $this->taxRules = $this->taxRuleFixtureFactory->createTaxRules([['code' => 'Default Rule', 'customer_tax_class_ids' => [$this->taxClasses['DefaultCustomerClass'], 3], 'product_tax_class_ids' => [$this->taxClasses['DefaultProductClass']], 'tax_rate_ids' => array_values($this->taxRates), 'sort_order' => 0, 'priority' => 0, 'calculate_subtotal' => 1], ['code' => 'Higher Rate Rule', 'customer_tax_class_ids' => [$this->taxClasses['DefaultCustomerClass'], 3], 'product_tax_class_ids' => [$this->taxClasses['HigherProductClass']], 'tax_rate_ids' => array_values($higherRates), 'sort_order' => 0, 'priority' => 0, 'calculate_subtotal' => 1], ['code' => 'Highest Rate', 'customer_tax_class_ids' => [$this->taxClasses['DefaultCustomerClass'], 3], 'product_tax_class_ids' => [$this->taxClasses['HigherProductClass']], 'tax_rate_ids' => array_values($higherRates), 'sort_order' => 1, 'priority' => 1, 'calculate_subtotal' => 0]]);
     // For cleanup
     $this->taxRates = array_merge($this->taxRates, $higherRates);
 }
 /**
  * Helper function that sets up some default rules
  */
 private function setUpDefaultRules()
 {
     $this->taxClassIds = $this->taxRuleFixtureFactory->createTaxClasses([['name' => 'DefaultCustomerClass', 'type' => ClassModel::TAX_CLASS_TYPE_CUSTOMER], ['name' => 'DefaultProductClass', 'type' => ClassModel::TAX_CLASS_TYPE_PRODUCT], ['name' => 'HigherProductClass', 'type' => ClassModel::TAX_CLASS_TYPE_PRODUCT], ['name' => 'MultipleRulesProductClass', 'type' => ClassModel::TAX_CLASS_TYPE_PRODUCT]]);
     $this->taxRates = $this->taxRuleFixtureFactory->createTaxRates([['percentage' => 7.5, 'country' => 'US', 'region' => 42], ['percentage' => 7.5, 'country' => 'US', 'region' => 12]]);
     $multiTaxRates1 = $this->taxRuleFixtureFactory->createTaxRates([['percentage' => 8.25, 'country' => 'US', 'region' => 42], ['percentage' => 12, 'country' => 'US', 'region' => 12]]);
     $multiTaxRatesSamePriority = $this->taxRuleFixtureFactory->createTaxRates([['percentage' => 5, 'country' => 'US', 'region' => 42, 'postcode' => '55555']]);
     $multiTaxRatesDifferentPriority = $this->taxRuleFixtureFactory->createTaxRates([['percentage' => 11, 'country' => 'US', 'region' => 42, 'postcode' => '55555']]);
     $higherRates = $this->taxRuleFixtureFactory->createTaxRates([['percentage' => 22, 'country' => 'US', 'region' => 42], ['percentage' => 10, 'country' => 'US', 'region' => 12]]);
     $this->taxRules = $this->taxRuleFixtureFactory->createTaxRules([['code' => 'Default Rule', 'customer_tax_class_ids' => [$this->taxClassIds['DefaultCustomerClass'], 3], 'product_tax_class_ids' => [$this->taxClassIds['DefaultProductClass']], 'tax_rate_ids' => array_values($this->taxRates), 'sort_order' => 0, 'priority' => 0], ['code' => 'Higher Rate Rule', 'customer_tax_class_ids' => [$this->taxClassIds['DefaultCustomerClass'], 3], 'product_tax_class_ids' => [$this->taxClassIds['HigherProductClass']], 'tax_rate_ids' => array_values($higherRates), 'sort_order' => 0, 'priority' => 0], ['code' => 'MultiRule-1', 'customer_tax_class_ids' => [$this->taxClassIds['DefaultCustomerClass'], 3], 'product_tax_class_ids' => [$this->taxClassIds['MultipleRulesProductClass']], 'tax_rate_ids' => array_values($multiTaxRates1), 'sort_order' => 0, 'priority' => 0], ['code' => 'MultiRule-2', 'customer_tax_class_ids' => [$this->taxClassIds['DefaultCustomerClass'], 3], 'product_tax_class_ids' => [$this->taxClassIds['MultipleRulesProductClass']], 'tax_rate_ids' => array_values($multiTaxRatesSamePriority), 'sort_order' => 0, 'priority' => 0], ['code' => 'MultiRule-3', 'customer_tax_class_ids' => [$this->taxClassIds['DefaultCustomerClass'], 3], 'product_tax_class_ids' => [$this->taxClassIds['MultipleRulesProductClass']], 'tax_rate_ids' => array_values($multiTaxRatesDifferentPriority), 'sort_order' => 0, 'priority' => 1]]);
     // For cleanup
     $this->taxRates = array_merge($this->taxRates, $higherRates);
     $this->taxRates = array_merge($this->taxRates, $multiTaxRates1);
     $this->taxRates = array_merge($this->taxRates, $multiTaxRatesSamePriority);
     $this->taxRates = array_merge($this->taxRates, $multiTaxRatesDifferentPriority);
 }
 /**
  *
  * @param \Magento\Framework\Api\Filter[] $filters
  * @param \Magento\Framework\Api\Filter[] $filterGroup
  * @param $expectedRateCodes
  *
  * @magentoDbIsolation enabled
  * @dataProvider searchTaxRatesDataProvider
  * @SuppressWarnings(PHPMD.UnusedLocalVariable)
  */
 public function testGetList($filters, $filterGroup, $expectedRateCodes)
 {
     $taxRates = $this->taxRateFixtureFactory->createTaxRates([['percentage' => 7.5, 'country' => 'US', 'region' => '42'], ['percentage' => 7.5, 'country' => 'US', 'region' => '12'], ['percentage' => 22.0, 'country' => 'US', 'region' => '42'], ['percentage' => 10.0, 'country' => 'US', 'region' => '12']]);
     /** @var \Magento\Framework\Api\SearchCriteriaBuilder $searchBuilder */
     $searchBuilder = Bootstrap::getObjectManager()->create('Magento\\Framework\\Api\\SearchCriteriaBuilder');
     foreach ($filters as $filter) {
         $searchBuilder->addFilters([$filter]);
     }
     if ($filterGroup !== null) {
         $searchBuilder->addFilters($filterGroup);
     }
     $searchCriteria = $searchBuilder->create();
     $searchResults = $this->rateRepository->getList($searchCriteria);
     $this->assertEquals($searchCriteria, $searchResults->getSearchCriteria());
     $this->assertEquals(count($expectedRateCodes), $searchResults->getTotalCount());
     foreach ($searchResults->getItems() as $rate) {
         $this->assertContains($rate->getCode(), $expectedRateCodes);
     }
 }