From 9519a4697a5c1ee409a00ec456295e7bfdbbec0d Mon Sep 17 00:00:00 2001 From: Ctucker9233 Date: Sat, 6 Apr 2019 10:54:26 -0700 Subject: [PATCH 01/10] Update Utility.php --- app/code/Magento/SalesRule/Model/Utility.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/code/Magento/SalesRule/Model/Utility.php b/app/code/Magento/SalesRule/Model/Utility.php index a3876a9d7e046..3cbcf45361301 100644 --- a/app/code/Magento/SalesRule/Model/Utility.php +++ b/app/code/Magento/SalesRule/Model/Utility.php @@ -189,6 +189,8 @@ public function deltaRoundingFix( ) { $discountAmount = $discountData->getAmount(); $baseDiscountAmount = $discountData->getBaseAmount(); + $rowTotalInclTax = $item->getRowTotalInclTax(); + $baseRowTotalInclTax = $item->getBaseRowTotalInclTax(); //TODO Seems \Magento\Quote\Model\Quote\Item\AbstractItem::getDiscountPercent() returns float value //that can not be used as array index @@ -205,6 +207,20 @@ public function deltaRoundingFix( - $this->priceCurrency->round($baseDiscountAmount); } + /** + * When we have 100% discount check if totals will not be negative + */ + if ($percentKey == 100) { + $discountDelta = $rowTotalInclTax - $discountAmount; + $baseDiscountDelta = $baseRowTotalInclTax - $baseDiscountAmount; + if ($discountDelta < 0) { + $discountAmount += $discountDelta; + } + if ($baseDiscountDelta < 0) { + $baseDiscountAmount += $baseDiscountDelta; + } + } + $discountData->setAmount($this->priceCurrency->round($discountAmount)); $discountData->setBaseAmount($this->priceCurrency->round($baseDiscountAmount)); From 73051bac4d8839d7ef5cc4916c4ff49fe8da2097 Mon Sep 17 00:00:00 2001 From: Ctucker9233 Date: Sat, 6 Apr 2019 10:56:33 -0700 Subject: [PATCH 02/10] Update AbstractAggregateCalculator.php --- .../Tax/Model/Calculation/AbstractAggregateCalculator.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/Tax/Model/Calculation/AbstractAggregateCalculator.php b/app/code/Magento/Tax/Model/Calculation/AbstractAggregateCalculator.php index afcfa1bbebcb0..9ec599cc67616 100644 --- a/app/code/Magento/Tax/Model/Calculation/AbstractAggregateCalculator.php +++ b/app/code/Magento/Tax/Model/Calculation/AbstractAggregateCalculator.php @@ -149,6 +149,7 @@ protected function calculateWithTaxNotInPrice(QuoteDetailsItemInterface $item, $ $rowTaxBeforeDiscount = array_sum($rowTaxesBeforeDiscount); $rowTotalInclTax = $rowTotal + $rowTaxBeforeDiscount; $priceInclTax = $rowTotalInclTax / $quantity; + if ($round) { $priceInclTax = $this->calculationTool->round($priceInclTax); } From 2edcbc36eb6f6897312177516f70e739b5c5c4f9 Mon Sep 17 00:00:00 2001 From: Ctucker9233 Date: Sat, 6 Apr 2019 10:59:22 -0700 Subject: [PATCH 03/10] Update TaxTest.php --- .../Tax/Model/Sales/Total/Quote/TaxTest.php | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/dev/tests/integration/testsuite/Magento/Tax/Model/Sales/Total/Quote/TaxTest.php b/dev/tests/integration/testsuite/Magento/Tax/Model/Sales/Total/Quote/TaxTest.php index 0513dd1c7d3c4..fd3a4dd1be75c 100644 --- a/dev/tests/integration/testsuite/Magento/Tax/Model/Sales/Total/Quote/TaxTest.php +++ b/dev/tests/integration/testsuite/Magento/Tax/Model/Sales/Total/Quote/TaxTest.php @@ -11,6 +11,7 @@ require_once __DIR__ . '/SetupUtil.php'; require_once __DIR__ . '/../../../../_files/tax_calculation_data_aggregated.php'; +require_once __DIR__ . '/../../../../_files/full_discount_with_tax.php'; /** * Class TaxTest @@ -124,6 +125,34 @@ public function testCollect() ); } + /** + * Test taxes collection with full discount for quote. + * + * Test tax calculation and price when the discount may be bigger than total + * This method will test the collector through $quote->collectTotals() method + * + * @see \Magento\SalesRule\Model\Utility::deltaRoundingFix + * @magentoDataFixture Magento/Tax/_files/full_discount_with_tax.php + * @magentoDbIsolation enabled + * @magentoAppIsolation enabled + */ + public function testFullDiscountWithDeltaRoundingFix() + { + global $fullDiscountIncTax; + $configData = $fullDiscountIncTax['config_data']; + $quoteData = $fullDiscountIncTax['quote_data']; + $expectedResults = $fullDiscountIncTax['expected_result']; + /** @var \Magento\Framework\ObjectManagerInterface $objectManager */ + $objectManager = Bootstrap::getObjectManager(); + //Setup tax configurations + $this->setupUtil = new SetupUtil($objectManager); + $this->setupUtil->setupTax($configData); + $quote = $this->setupUtil->setupQuote($quoteData); + $quote->collectTotals(); + $quoteAddress = $quote->getShippingAddress(); + $this->verifyResult($quoteAddress, $expectedResults); + } + /** * Verify fields in quote item * From f0a01e42261414c45b8326a5971906c27dcac46e Mon Sep 17 00:00:00 2001 From: Ctucker9233 Date: Sat, 6 Apr 2019 11:01:35 -0700 Subject: [PATCH 04/10] Create full_discount_with_tax.php --- .../Tax/_files/full_discount_with_tax.php | 118 ++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 dev/tests/integration/testsuite/Magento/Tax/_files/full_discount_with_tax.php diff --git a/dev/tests/integration/testsuite/Magento/Tax/_files/full_discount_with_tax.php b/dev/tests/integration/testsuite/Magento/Tax/_files/full_discount_with_tax.php new file mode 100644 index 0000000000000..abb0611d8ef06 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Tax/_files/full_discount_with_tax.php @@ -0,0 +1,118 @@ + [ + 'config_overrides' => [ + Config::CONFIG_XML_PATH_APPLY_AFTER_DISCOUNT => 0, + Config::CONFIG_XML_PATH_DISCOUNT_TAX => 1, + Config::XML_PATH_ALGORITHM => 'ROW_BASE_CALCULATION', + Config::CONFIG_XML_PATH_SHIPPING_TAX_CLASS => SetupUtil::SHIPPING_TAX_CLASS, + ], + 'tax_rate_overrides' => [ + SetupUtil::TAX_RATE_TX => 18, + SetupUtil::TAX_RATE_SHIPPING => 0, + ], + 'tax_rule_overrides' => [ + [ + 'code' => 'Product Tax Rule', + 'product_tax_class_ids' => [ + SetupUtil::PRODUCT_TAX_CLASS_1 + ], + ], + [ + 'code' => 'Shipping Tax Rule', + 'product_tax_class_ids' => [ + SetupUtil::SHIPPING_TAX_CLASS + ], + 'tax_rate_ids' => [ + SetupUtil::TAX_RATE_SHIPPING, + ], + ], + ], + ], + 'quote_data' => [ + 'billing_address' => [ + 'region_id' => SetupUtil::REGION_TX, + ], + 'shipping_address' => [ + 'region_id' => SetupUtil::REGION_TX, + ], + 'items' => [ + [ + 'sku' => 'simple1', + 'price' => 2542.37, + 'qty' => 2, + ] + ], + 'shipping_method' => 'free', + 'shopping_cart_rules' => [ + [ + 'discount_amount' => 100 + ], + ], + ], + 'expected_result' => [ + 'address_data' => [ + 'subtotal' => 5084.74, + 'base_subtotal' => 5084.74, + 'subtotal_incl_tax' => 5999.99, + 'base_subtotal_incl_tax' => 5999.99, + 'tax_amount' => 915.25, + 'base_tax_amount' => 915.25, + 'shipping_amount' => 0, + 'base_shipping_amount' => 0, + 'shipping_incl_tax' => 0, + 'base_shipping_incl_tax' => 0, + 'shipping_tax_amount' => 0, + 'base_shipping_tax_amount' => 0, + 'discount_amount' => -5999.99, + 'base_discount_amount' => -5999.99, + 'discount_tax_compensation_amount' => 0, + 'base_discount_tax_compensation_amount' => 0, + 'shipping_discount_tax_compensation_amount' => 0, + 'base_shipping_discount_tax_compensation_amount' => 0, + 'grand_total' => 0, + 'base_grand_total' => 0, + 'applied_taxes' => [ + SetupUtil::TAX_RATE_TX => [ + 'percent' => 18, + 'amount' => 915.25, + 'base_amount' => 915.25, + 'rates' => [ + [ + 'code' => SetupUtil::TAX_RATE_TX, + 'title' => SetupUtil::TAX_RATE_TX, + 'percent' => 18, + ], + ], + ] + ], + ], + 'items_data' => [ + 'simple1' => [ + 'row_total' => 5084.74, + 'base_row_total' => 5084.74, + 'tax_percent' => 18, + 'price' => 2542.37, + 'base_price' => 2542.37, + 'price_incl_tax' => 3000, + 'base_price_incl_tax' => 3000, + 'row_total_incl_tax' => 5999.99, + 'base_row_total_incl_tax' => 5999.99, + 'tax_amount' => 915.25, + 'base_tax_amount' => 915.25, + 'discount_amount' => 5999.99, + 'base_discount_amount' => 5999.99, + 'discount_percent' => 100, + 'discount_tax_compensation_amount' => 0, + 'base_discount_tax_compensation_amount' => 0, + ], + ], + ] +]; From 16ec2c9cdeade15fd46c2b508b341facde7d7b33 Mon Sep 17 00:00:00 2001 From: Ctucker9233 Date: Sat, 13 Apr 2019 14:37:24 -0700 Subject: [PATCH 05/10] Revert "Update Utility.php" --- app/code/Magento/SalesRule/Model/Utility.php | 16 --- .../AbstractAggregateCalculator.php | 1 - .../Tax/Model/Sales/Total/Quote/TaxTest.php | 29 ----- .../Tax/_files/full_discount_with_tax.php | 118 ------------------ 4 files changed, 164 deletions(-) delete mode 100644 dev/tests/integration/testsuite/Magento/Tax/_files/full_discount_with_tax.php diff --git a/app/code/Magento/SalesRule/Model/Utility.php b/app/code/Magento/SalesRule/Model/Utility.php index 3cbcf45361301..a3876a9d7e046 100644 --- a/app/code/Magento/SalesRule/Model/Utility.php +++ b/app/code/Magento/SalesRule/Model/Utility.php @@ -189,8 +189,6 @@ public function deltaRoundingFix( ) { $discountAmount = $discountData->getAmount(); $baseDiscountAmount = $discountData->getBaseAmount(); - $rowTotalInclTax = $item->getRowTotalInclTax(); - $baseRowTotalInclTax = $item->getBaseRowTotalInclTax(); //TODO Seems \Magento\Quote\Model\Quote\Item\AbstractItem::getDiscountPercent() returns float value //that can not be used as array index @@ -207,20 +205,6 @@ public function deltaRoundingFix( - $this->priceCurrency->round($baseDiscountAmount); } - /** - * When we have 100% discount check if totals will not be negative - */ - if ($percentKey == 100) { - $discountDelta = $rowTotalInclTax - $discountAmount; - $baseDiscountDelta = $baseRowTotalInclTax - $baseDiscountAmount; - if ($discountDelta < 0) { - $discountAmount += $discountDelta; - } - if ($baseDiscountDelta < 0) { - $baseDiscountAmount += $baseDiscountDelta; - } - } - $discountData->setAmount($this->priceCurrency->round($discountAmount)); $discountData->setBaseAmount($this->priceCurrency->round($baseDiscountAmount)); diff --git a/app/code/Magento/Tax/Model/Calculation/AbstractAggregateCalculator.php b/app/code/Magento/Tax/Model/Calculation/AbstractAggregateCalculator.php index 73511c89eab6c..b50b6fa707ffe 100644 --- a/app/code/Magento/Tax/Model/Calculation/AbstractAggregateCalculator.php +++ b/app/code/Magento/Tax/Model/Calculation/AbstractAggregateCalculator.php @@ -156,7 +156,6 @@ protected function calculateWithTaxNotInPrice(QuoteDetailsItemInterface $item, $ $rowTaxBeforeDiscount = array_sum($rowTaxesBeforeDiscount); $rowTotalInclTax = $rowTotal + $rowTaxBeforeDiscount; $priceInclTax = $rowTotalInclTax / $quantity; - if ($round) { $priceInclTax = $this->calculationTool->round($priceInclTax); } diff --git a/dev/tests/integration/testsuite/Magento/Tax/Model/Sales/Total/Quote/TaxTest.php b/dev/tests/integration/testsuite/Magento/Tax/Model/Sales/Total/Quote/TaxTest.php index fd3a4dd1be75c..0513dd1c7d3c4 100644 --- a/dev/tests/integration/testsuite/Magento/Tax/Model/Sales/Total/Quote/TaxTest.php +++ b/dev/tests/integration/testsuite/Magento/Tax/Model/Sales/Total/Quote/TaxTest.php @@ -11,7 +11,6 @@ require_once __DIR__ . '/SetupUtil.php'; require_once __DIR__ . '/../../../../_files/tax_calculation_data_aggregated.php'; -require_once __DIR__ . '/../../../../_files/full_discount_with_tax.php'; /** * Class TaxTest @@ -125,34 +124,6 @@ public function testCollect() ); } - /** - * Test taxes collection with full discount for quote. - * - * Test tax calculation and price when the discount may be bigger than total - * This method will test the collector through $quote->collectTotals() method - * - * @see \Magento\SalesRule\Model\Utility::deltaRoundingFix - * @magentoDataFixture Magento/Tax/_files/full_discount_with_tax.php - * @magentoDbIsolation enabled - * @magentoAppIsolation enabled - */ - public function testFullDiscountWithDeltaRoundingFix() - { - global $fullDiscountIncTax; - $configData = $fullDiscountIncTax['config_data']; - $quoteData = $fullDiscountIncTax['quote_data']; - $expectedResults = $fullDiscountIncTax['expected_result']; - /** @var \Magento\Framework\ObjectManagerInterface $objectManager */ - $objectManager = Bootstrap::getObjectManager(); - //Setup tax configurations - $this->setupUtil = new SetupUtil($objectManager); - $this->setupUtil->setupTax($configData); - $quote = $this->setupUtil->setupQuote($quoteData); - $quote->collectTotals(); - $quoteAddress = $quote->getShippingAddress(); - $this->verifyResult($quoteAddress, $expectedResults); - } - /** * Verify fields in quote item * diff --git a/dev/tests/integration/testsuite/Magento/Tax/_files/full_discount_with_tax.php b/dev/tests/integration/testsuite/Magento/Tax/_files/full_discount_with_tax.php deleted file mode 100644 index abb0611d8ef06..0000000000000 --- a/dev/tests/integration/testsuite/Magento/Tax/_files/full_discount_with_tax.php +++ /dev/null @@ -1,118 +0,0 @@ - [ - 'config_overrides' => [ - Config::CONFIG_XML_PATH_APPLY_AFTER_DISCOUNT => 0, - Config::CONFIG_XML_PATH_DISCOUNT_TAX => 1, - Config::XML_PATH_ALGORITHM => 'ROW_BASE_CALCULATION', - Config::CONFIG_XML_PATH_SHIPPING_TAX_CLASS => SetupUtil::SHIPPING_TAX_CLASS, - ], - 'tax_rate_overrides' => [ - SetupUtil::TAX_RATE_TX => 18, - SetupUtil::TAX_RATE_SHIPPING => 0, - ], - 'tax_rule_overrides' => [ - [ - 'code' => 'Product Tax Rule', - 'product_tax_class_ids' => [ - SetupUtil::PRODUCT_TAX_CLASS_1 - ], - ], - [ - 'code' => 'Shipping Tax Rule', - 'product_tax_class_ids' => [ - SetupUtil::SHIPPING_TAX_CLASS - ], - 'tax_rate_ids' => [ - SetupUtil::TAX_RATE_SHIPPING, - ], - ], - ], - ], - 'quote_data' => [ - 'billing_address' => [ - 'region_id' => SetupUtil::REGION_TX, - ], - 'shipping_address' => [ - 'region_id' => SetupUtil::REGION_TX, - ], - 'items' => [ - [ - 'sku' => 'simple1', - 'price' => 2542.37, - 'qty' => 2, - ] - ], - 'shipping_method' => 'free', - 'shopping_cart_rules' => [ - [ - 'discount_amount' => 100 - ], - ], - ], - 'expected_result' => [ - 'address_data' => [ - 'subtotal' => 5084.74, - 'base_subtotal' => 5084.74, - 'subtotal_incl_tax' => 5999.99, - 'base_subtotal_incl_tax' => 5999.99, - 'tax_amount' => 915.25, - 'base_tax_amount' => 915.25, - 'shipping_amount' => 0, - 'base_shipping_amount' => 0, - 'shipping_incl_tax' => 0, - 'base_shipping_incl_tax' => 0, - 'shipping_tax_amount' => 0, - 'base_shipping_tax_amount' => 0, - 'discount_amount' => -5999.99, - 'base_discount_amount' => -5999.99, - 'discount_tax_compensation_amount' => 0, - 'base_discount_tax_compensation_amount' => 0, - 'shipping_discount_tax_compensation_amount' => 0, - 'base_shipping_discount_tax_compensation_amount' => 0, - 'grand_total' => 0, - 'base_grand_total' => 0, - 'applied_taxes' => [ - SetupUtil::TAX_RATE_TX => [ - 'percent' => 18, - 'amount' => 915.25, - 'base_amount' => 915.25, - 'rates' => [ - [ - 'code' => SetupUtil::TAX_RATE_TX, - 'title' => SetupUtil::TAX_RATE_TX, - 'percent' => 18, - ], - ], - ] - ], - ], - 'items_data' => [ - 'simple1' => [ - 'row_total' => 5084.74, - 'base_row_total' => 5084.74, - 'tax_percent' => 18, - 'price' => 2542.37, - 'base_price' => 2542.37, - 'price_incl_tax' => 3000, - 'base_price_incl_tax' => 3000, - 'row_total_incl_tax' => 5999.99, - 'base_row_total_incl_tax' => 5999.99, - 'tax_amount' => 915.25, - 'base_tax_amount' => 915.25, - 'discount_amount' => 5999.99, - 'base_discount_amount' => 5999.99, - 'discount_percent' => 100, - 'discount_tax_compensation_amount' => 0, - 'base_discount_tax_compensation_amount' => 0, - ], - ], - ] -]; From ce685a9fcdcfb1b535adde0e3ffa4fe975ecc7d9 Mon Sep 17 00:00:00 2001 From: Ctucker9233 Date: Sat, 13 Apr 2019 16:09:53 -0700 Subject: [PATCH 06/10] Update Cache.php --- .../Setup/Model/ConfigOptionsList/Cache.php | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/setup/src/Magento/Setup/Model/ConfigOptionsList/Cache.php b/setup/src/Magento/Setup/Model/ConfigOptionsList/Cache.php index 04ec83a3d0ca2..454b7ba977263 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptionsList/Cache.php +++ b/setup/src/Magento/Setup/Model/ConfigOptionsList/Cache.php @@ -27,12 +27,14 @@ class Cache implements ConfigOptionsListInterface const INPUT_KEY_CACHE_BACKEND_REDIS_DATABASE = 'cache-backend-redis-db'; const INPUT_KEY_CACHE_BACKEND_REDIS_PORT = 'cache-backend-redis-port'; const INPUT_KEY_CACHE_BACKEND_REDIS_PASSWORD = 'cache-backend-redis-password'; + const INPUT_KEY_CACHE_ID_PREFIX = 'cache-id-prefix'; const CONFIG_PATH_CACHE_BACKEND = 'cache/frontend/default/backend'; const CONFIG_PATH_CACHE_BACKEND_SERVER = 'cache/frontend/default/backend_options/server'; const CONFIG_PATH_CACHE_BACKEND_DATABASE = 'cache/frontend/default/backend_options/database'; const CONFIG_PATH_CACHE_BACKEND_PORT = 'cache/frontend/default/backend_options/port'; const CONFIG_PATH_CACHE_BACKEND_PASSWORD = 'cache/frontend/default/backend_options/password'; + const CONFIG_PATH_CACHE_ID_PREFIX = 'cache/frontend/default/id_prefix'; /** * @var array @@ -77,7 +79,7 @@ public function __construct(RedisConnectionValidator $redisValidator) } /** - * {@inheritdoc} + * @inheritdoc */ public function getOptions() { @@ -112,7 +114,12 @@ public function getOptions() TextConfigOption::FRONTEND_WIZARD_TEXT, self::CONFIG_PATH_CACHE_BACKEND_PASSWORD, 'Redis server password' - ) + ), + new TextConfigOption( + self::INPUT_KEY_CACHE_ID_PREFIX, + TextConfigOption::FRONTEND_WIZARD_TEXT, + self::CONFIG_PATH_CACHE_ID_PREFIX, + 'ID prefix for cache keys' ]; } @@ -124,6 +131,11 @@ public function createConfig(array $options, DeploymentConfig $deploymentConfig) $configData = new ConfigData(ConfigFilePool::APP_ENV); if (isset($options[self::INPUT_KEY_CACHE_BACKEND])) { + if (isset($options[self::INPUT_KEY_CACHE_ID_PREFIX])) { + $configData->set(self::CONFIG_PATH_CACHE_ID_PREFIX, $options[self::INPUT_KEY_CACHE_ID_PREFIX]); + } else { + $configData->set(self::CONFIG_PATH_CACHE_ID_PREFIX, $this->generateCachePrefix()); + } if ($options[self::INPUT_KEY_CACHE_BACKEND] == self::INPUT_VALUE_CACHE_REDIS) { $configData->set(self::CONFIG_PATH_CACHE_BACKEND, self::CONFIG_VALUE_CACHE_REDIS); $this->setDefaultRedisConfig($deploymentConfig, $configData); @@ -241,4 +253,14 @@ private function getDefaultConfigValue($inputKey) return ''; } } + + /** + * Generate default cache ID prefix based on installation dir + * + * @return string + */ + private function generateCachePrefix(): string + { + return substr(\md5(dirname(__DIR__, 6)), 0, 3) . '_'; + } } From 3c9b366460e1ce60d43077559b6cf499a90038a1 Mon Sep 17 00:00:00 2001 From: Ctucker9233 Date: Sat, 13 Apr 2019 16:15:18 -0700 Subject: [PATCH 07/10] Update PageCache.php --- .../Model/ConfigOptionsList/PageCache.php | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/setup/src/Magento/Setup/Model/ConfigOptionsList/PageCache.php b/setup/src/Magento/Setup/Model/ConfigOptionsList/PageCache.php index 944c543495751..0c6a7ac0a3bdf 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptionsList/PageCache.php +++ b/setup/src/Magento/Setup/Model/ConfigOptionsList/PageCache.php @@ -28,6 +28,7 @@ class PageCache implements ConfigOptionsListInterface const INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_PORT = 'page-cache-redis-port'; const INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_COMPRESS_DATA = 'page-cache-redis-compress-data'; const INPUT_KEY_PAGE_CACHE_BACKEND_REDIS_PASSWORD = 'page-cache-redis-password'; + const INPUT_KEY_PAGE_CACHE_ID_PREFIX = 'page-cache-id-prefix'; const CONFIG_PATH_PAGE_CACHE_BACKEND = 'cache/frontend/page_cache/backend'; const CONFIG_PATH_PAGE_CACHE_BACKEND_SERVER = 'cache/frontend/page_cache/backend_options/server'; @@ -35,6 +36,7 @@ class PageCache implements ConfigOptionsListInterface const CONFIG_PATH_PAGE_CACHE_BACKEND_PORT = 'cache/frontend/page_cache/backend_options/port'; const CONFIG_PATH_PAGE_CACHE_BACKEND_COMPRESS_DATA = 'cache/frontend/page_cache/backend_options/compress_data'; const CONFIG_PATH_PAGE_CACHE_BACKEND_PASSWORD = 'cache/frontend/page_cache/backend_options/password'; + const CONFIG_PATH_PAGE_CACHE_ID_PREFIX = 'cache/frontend/page_cache/id_prefix'; /** * @var array @@ -81,7 +83,7 @@ public function __construct(RedisConnectionValidator $redisValidator) } /** - * {@inheritdoc} + * @inheritdoc */ public function getOptions() { @@ -122,7 +124,12 @@ public function getOptions() TextConfigOption::FRONTEND_WIZARD_TEXT, self::CONFIG_PATH_PAGE_CACHE_BACKEND_PASSWORD, 'Redis server password' - ) + ), + new TextConfigOption( + self::INPUT_KEY_PAGE_CACHE_ID_PREFIX, + TextConfigOption::FRONTEND_WIZARD_TEXT, + self::CONFIG_PATH_PAGE_CACHE_ID_PREFIX, + 'ID prefix for cache keys' ]; } @@ -132,7 +139,12 @@ public function getOptions() public function createConfig(array $options, DeploymentConfig $deploymentConfig) { $configData = new ConfigData(ConfigFilePool::APP_ENV); - + if (isset($options[self::INPUT_KEY_PAGE_CACHE_ID_PREFIX])) { + $configData->set(self::CONFIG_PATH_PAGE_CACHE_ID_PREFIX, $options[self::INPUT_KEY_PAGE_CACHE_ID_PREFIX]); + } else { + $configData->set(self::CONFIG_PATH_PAGE_CACHE_ID_PREFIX, $this->generateCachePrefix()); + } + if (isset($options[self::INPUT_KEY_PAGE_CACHE_BACKEND])) { if ($options[self::INPUT_KEY_PAGE_CACHE_BACKEND] == self::INPUT_VALUE_PAGE_CACHE_REDIS) { $configData->set(self::CONFIG_PATH_PAGE_CACHE_BACKEND, self::CONFIG_VALUE_PAGE_CACHE_REDIS); @@ -252,4 +264,14 @@ private function getDefaultConfigValue($inputKey) return ''; } } + + /** + * Generate default cache ID prefix based on installation dir + * + * @return string + */ + private function generateCachePrefix(): string + { + return substr(\md5(dirname(__DIR__, 6)), 0, 3) . '_'; + } } From 1e44444b703993c33ab03de15e4e9d1b2c893f67 Mon Sep 17 00:00:00 2001 From: Ctucker9233 Date: Sat, 13 Apr 2019 16:20:08 -0700 Subject: [PATCH 08/10] Update CacheTest.php --- .../Model/ConfigOptionsList/CacheTest.php | 63 ++++++++++++++++++- 1 file changed, 60 insertions(+), 3 deletions(-) diff --git a/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/CacheTest.php b/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/CacheTest.php index 39b95953c6347..aa87a1cd5f646 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/CacheTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/CacheTest.php @@ -39,7 +39,7 @@ protected function setUp() public function testGetOptions() { $options = $this->configOptionsList->getOptions(); - $this->assertCount(5, $options); + $this->assertCount(6, $options); $this->assertArrayHasKey(0, $options); $this->assertInstanceOf(SelectConfigOption::class, $options[0]); @@ -60,6 +60,10 @@ public function testGetOptions() $this->assertArrayHasKey(4, $options); $this->assertInstanceOf(TextConfigOption::class, $options[4]); $this->assertEquals('cache-backend-redis-password', $options[4]->getName()); + + $this->assertArrayHasKey(5, $options); + $this->assertInstanceOf(TextConfigOption::class, $options[5]); + $this->assertEquals('cache-id-prefix', $options[5]->getName()); } public function testCreateConfigCacheRedis() @@ -76,7 +80,8 @@ public function testCreateConfigCacheRedis() 'port' => '', 'database' => '', 'password' => '' - ] + ], + 'id_prefix' => $this->expectedIdPrefix(), ] ] ] @@ -99,7 +104,8 @@ public function testCreateConfigWithRedisConfig() 'port' => '1234', 'database' => '5', 'password' => '' - ] + ], + 'id_prefix' => $this->expectedIdPrefix(), ] ] ] @@ -115,6 +121,47 @@ public function testCreateConfigWithRedisConfig() $this->assertEquals($expectedConfigData, $configData->getData()); } + + /** + * testCreateConfigCacheRedis + */ + public function testCreateConfigWithFileCache() + { + $this->deploymentConfigMock->method('get')->willReturn(''); + $expectedConfigData = [ + 'cache' => [ + 'frontend' => [ + 'default' => [ + 'id_prefix' => $this->expectedIdPrefix(), + ] + ] + ] + ]; + $configData = $this->configOptionsList->createConfig([], $this->deploymentConfigMock); + $this->assertEquals($expectedConfigData, $configData->getData()); + } + /** + * testCreateConfigCacheRedis + */ + public function testCreateConfigWithIdPrefix() + { + $this->deploymentConfigMock->method('get')->willReturn(''); + $explicitPrefix = 'XXX_'; + $expectedConfigData = [ + 'cache' => [ + 'frontend' => [ + 'default' => [ + 'id_prefix' => $explicitPrefix, + ] + ] + ] + ]; + $configData = $this->configOptionsList->createConfig( + ['cache-id-prefix' => $explicitPrefix], + $this->deploymentConfigMock + ); + $this->assertEquals($expectedConfigData, $configData->getData()); + } public function testValidateWithValidInput() { @@ -142,4 +189,14 @@ public function testValidateWithInvalidInput() $this->assertCount(1, $errors); $this->assertEquals("Invalid cache handler 'clay-tablet'", $errors[0]); } + + /** + * The default ID prefix, based on installation directory + * + * @return string + */ + private function expectedIdPrefix(): string + { + return substr(\md5(dirname(__DIR__, 8)), 0, 3) . '_'; + } } From 0c29ce88b3581eb87c5350cc1fbdcb754472431d Mon Sep 17 00:00:00 2001 From: Ctucker9233 Date: Sat, 13 Apr 2019 16:22:53 -0700 Subject: [PATCH 09/10] Update PageCacheTest.php --- .../Model/ConfigOptionsList/PageCacheTest.php | 63 ++++++++++++++++++- 1 file changed, 60 insertions(+), 3 deletions(-) diff --git a/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/PageCacheTest.php b/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/PageCacheTest.php index ed0e567820ad1..9a7eff194b066 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/PageCacheTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/PageCacheTest.php @@ -39,7 +39,7 @@ protected function setUp() public function testGetOptions() { $options = $this->configList->getOptions(); - $this->assertCount(6, $options); + $this->assertCount(7, $options); $this->assertArrayHasKey(0, $options); $this->assertInstanceOf(SelectConfigOption::class, $options[0]); @@ -64,6 +64,10 @@ public function testGetOptions() $this->assertArrayHasKey(5, $options); $this->assertInstanceOf(TextConfigOption::class, $options[5]); $this->assertEquals('page-cache-redis-password', $options[5]->getName()); + + $this->assertArrayHasKey(6, $options); + $this->assertInstanceOf(TextConfigOption::class, $options[6]); + $this->assertEquals('page-cache-id-prefix', $options[6]->getName()); } public function testCreateConfigWithRedis() @@ -81,7 +85,8 @@ public function testCreateConfigWithRedis() 'database' => '', 'compress_data' => '', 'password' => '' - ] + ], + 'id_prefix' => $this->expectedIdPrefix(), ] ] ] @@ -105,7 +110,8 @@ public function testCreateConfigWithRedisConfiguration() 'database' => '6', 'compress_data' => '1', 'password' => '' - ] + ], + 'id_prefix' => $this->expectedIdPrefix(), ] ] ] @@ -123,6 +129,47 @@ public function testCreateConfigWithRedisConfiguration() $this->assertEquals($expectedConfigData, $configData->getData()); } + /** + * testCreateConfigWithRedis + */ + public function testCreateConfigWithFileCache() + { + $this->deploymentConfigMock->method('get')->willReturn(''); + $expectedConfigData = [ + 'cache' => [ + 'frontend' => [ + 'page_cache' => [ + 'id_prefix' => $this->expectedIdPrefix(), + ] + ] + ] + ]; + $configData = $this->configList->createConfig([], $this->deploymentConfigMock); + $this->assertEquals($expectedConfigData, $configData->getData()); + } + + /** + * testCreateConfigCacheRedis + */ + public function testCreateConfigWithIdPrefix() + { + $this->deploymentConfigMock->method('get')->willReturn(''); + $explicitPrefix = 'XXX_'; + $expectedConfigData = [ + 'cache' => [ + 'frontend' => [ + 'page_cache' => [ + 'id_prefix' => $explicitPrefix, + ] + ] + ] + ]; + $configData = $this->configList->createConfig( + ['page-cache-id-prefix' => $explicitPrefix], + $this->deploymentConfigMock + ); + $this->assertEquals($expectedConfigData, $configData->getData()); + } public function testValidationWithValidData() { @@ -151,4 +198,14 @@ public function testValidationWithInvalidData() $this->assertCount(1, $errors); $this->assertEquals('Invalid cache handler \'foobar\'', $errors[0]); } + + /** + * The default ID prefix, based on installation directory + * + * @return string + */ + private function expectedIdPrefix(): string + { + return substr(\md5(dirname(__DIR__, 8)), 0, 3) . '_'; + } } From b741929f471c7bbabd0e325e5a04b22a1080ae3d Mon Sep 17 00:00:00 2001 From: Ctucker9233 Date: Sat, 13 Apr 2019 16:41:42 -0700 Subject: [PATCH 10/10] Delete TaxTest.php --- .../Tax/Model/Sales/Total/Quote/TaxTest.php | 280 ------------------ 1 file changed, 280 deletions(-) delete mode 100644 dev/tests/integration/testsuite/Magento/Tax/Model/Sales/Total/Quote/TaxTest.php diff --git a/dev/tests/integration/testsuite/Magento/Tax/Model/Sales/Total/Quote/TaxTest.php b/dev/tests/integration/testsuite/Magento/Tax/Model/Sales/Total/Quote/TaxTest.php deleted file mode 100644 index 0513dd1c7d3c4..0000000000000 --- a/dev/tests/integration/testsuite/Magento/Tax/Model/Sales/Total/Quote/TaxTest.php +++ /dev/null @@ -1,280 +0,0 @@ -totalsCollector = $objectManager->create(TotalsCollector::class); - $this->setupUtil = new SetupUtil($objectManager); - - parent::setUp(); - } - - /** - * Test taxes collection for quote. - * - * Quote has customer and product. - * Product tax class and customer group tax class along with billing address have corresponding tax rule. - * - * @magentoDataFixture Magento/Customer/_files/customer.php - * @magentoDataFixture Magento/Customer/_files/customer_address.php - * @magentoDataFixture Magento/Catalog/_files/products.php - * @magentoDataFixture Magento/Tax/_files/tax_classes.php - * @magentoDataFixture Magento/Customer/_files/customer_group.php - * @magentoDbIsolation enabled - * @magentoAppIsolation enabled - */ - public function testCollect() - { - /** Preconditions */ - $objectManager = Bootstrap::getObjectManager(); - /** @var \Magento\Tax\Model\ClassModel $customerTaxClass */ - $customerTaxClass = $objectManager->create(\Magento\Tax\Model\ClassModel::class); - $fixtureCustomerTaxClass = 'CustomerTaxClass2'; - $customerTaxClass->load($fixtureCustomerTaxClass, 'class_name'); - $fixtureCustomerId = 1; - /** @var \Magento\Customer\Model\Customer $customer */ - $customer = $objectManager->create(\Magento\Customer\Model\Customer::class)->load($fixtureCustomerId); - /** @var \Magento\Customer\Model\Group $customerGroup */ - $customerGroup = $objectManager->create(\Magento\Customer\Model\Group::class) - ->load('custom_group', 'customer_group_code'); - $customerGroup->setTaxClassId($customerTaxClass->getId())->save(); - $customer->setGroupId($customerGroup->getId())->save(); - - /** @var \Magento\Tax\Model\ClassModel $productTaxClass */ - $productTaxClass = $objectManager->create(\Magento\Tax\Model\ClassModel::class); - $fixtureProductTaxClass = 'ProductTaxClass1'; - $productTaxClass->load($fixtureProductTaxClass, 'class_name'); - /** @var \Magento\Catalog\Model\Product $product */ - $product = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class)->get('simple'); - $product->setTaxClassId($productTaxClass->getId())->save(); - - $fixtureCustomerAddressId = 1; - $customerAddress = $objectManager->create(\Magento\Customer\Model\Address::class)->load($fixtureCustomerId); - /** Set data which corresponds tax class fixture */ - $customerAddress->setCountryId('US')->setRegionId(12)->save(); - /** @var \Magento\Quote\Model\Quote\Address $quoteShippingAddress */ - $quoteShippingAddress = $objectManager->create(\Magento\Quote\Model\Quote\Address::class); - /** @var \Magento\Customer\Api\AddressRepositoryInterface $addressRepository */ - $addressRepository = $objectManager->create(\Magento\Customer\Api\AddressRepositoryInterface::class); - $quoteShippingAddress->importCustomerAddressData($addressRepository->getById($fixtureCustomerAddressId)); - - /** @var \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository */ - $customerRepository = $objectManager->create(\Magento\Customer\Api\CustomerRepositoryInterface::class); - /** @var \Magento\Quote\Model\Quote $quote */ - $quote = $objectManager->create(\Magento\Quote\Model\Quote::class); - $quote->setStoreId(1) - ->setIsActive(true) - ->setIsMultiShipping(false) - ->assignCustomerWithAddressChange($customerRepository->getById($customer->getId())) - ->setShippingAddress($quoteShippingAddress) - ->setBillingAddress($quoteShippingAddress) - ->setCheckoutMethod($customer->getMode()) - ->setPasswordHash($customer->encryptPassword($customer->getPassword())) - ->addProduct($product->load($product->getId()), 2); - - /** - * Execute SUT. - * \Magento\Tax\Model\Sales\Total\Quote\Tax::collect cannot be called separately from - * \Magento\Tax\Model\Sales\Total\Quote\Subtotal::collect because tax to zero amount will be applied. - * That is why it make sense to call collectTotals() instead, which will call SUT in its turn. - */ - $quote->collectTotals(); - - /** Check results */ - $this->assertEquals( - $customerTaxClass->getId(), - $quote->getCustomerTaxClassId(), - 'Customer tax class ID in quote is invalid.' - ); - $this->assertEquals( - 21.5, - $quote->getGrandTotal(), - 'Customer tax was collected by \Magento\Tax\Model\Sales\Total\Quote\Tax::collect incorrectly.' - ); - } - - /** - * Verify fields in quote item - * - * @param \Magento\Quote\Model\Quote\Address\Item $item - * @param array $expectedItemData - * @return $this - */ - protected function verifyItem($item, $expectedItemData) - { - foreach ($expectedItemData as $key => $value) { - $this->assertEquals($value, $item->getData($key), 'item ' . $key . ' is incorrect'); - } - - return $this; - } - - /** - * Verify one tax rate in a tax row - * - * @param array $appliedTaxRate - * @param array $expectedAppliedTaxRate - * @return $this - */ - protected function verifyAppliedTaxRate($appliedTaxRate, $expectedAppliedTaxRate) - { - foreach ($expectedAppliedTaxRate as $key => $value) { - $this->assertEquals($value, $appliedTaxRate[$key], 'Applied tax rate ' . $key . ' is incorrect'); - } - return $this; - } - - /** - * Verify one row in the applied taxes - * - * @param array $appliedTax - * @param array $expectedAppliedTax - * @return $this - */ - protected function verifyAppliedTax($appliedTax, $expectedAppliedTax) - { - foreach ($expectedAppliedTax as $key => $value) { - if ($key == 'rates') { - foreach ($value as $index => $taxRate) { - $this->verifyAppliedTaxRate($appliedTax['rates'][$index], $taxRate); - } - } else { - $this->assertEquals($value, $appliedTax[$key], 'Applied tax ' . $key . ' is incorrect'); - } - } - return $this; - } - - /** - * Verify that applied taxes are correct - * - * @param array $appliedTaxes - * @param array $expectedAppliedTaxes - * @return $this - */ - protected function verifyAppliedTaxes($appliedTaxes, $expectedAppliedTaxes) - { - foreach ($expectedAppliedTaxes as $taxRateKey => $expectedTaxRate) { - $this->assertTrue(isset($appliedTaxes[$taxRateKey]), 'Missing tax rate ' . $taxRateKey); - $this->verifyAppliedTax($appliedTaxes[$taxRateKey], $expectedTaxRate); - } - return $this; - } - - /** - * Verify fields in quote address - * - * @param \Magento\Quote\Model\Quote\Address $quoteAddress - * @param array $expectedAddressData - * @return $this - */ - protected function verifyQuoteAddress($quoteAddress, $expectedAddressData) - { - foreach ($expectedAddressData as $key => $value) { - if ($key == 'applied_taxes') { - $this->verifyAppliedTaxes($quoteAddress->getAppliedTaxes(), $value); - } else { - $this->assertEquals($value, $quoteAddress->getData($key), 'Quote address ' . $key . ' is incorrect'); - } - } - - return $this; - } - - /** - * Verify fields in quote address and quote item are correct - * - * @param \Magento\Quote\Model\Quote\Address $quoteAddress - * @param array $expectedResults - * @return $this - */ - protected function verifyResult($quoteAddress, $expectedResults) - { - $addressData = $expectedResults['address_data']; - - $this->verifyQuoteAddress($quoteAddress, $addressData); - - $quoteItems = $quoteAddress->getAllItems(); - foreach ($quoteItems as $item) { - /** @var \Magento\Quote\Model\Quote\Address\Item $item */ - $sku = $item->getProduct()->getSku(); - $expectedItemData = $expectedResults['items_data'][$sku]; - $this->verifyItem($item, $expectedItemData); - } - - return $this; - } - - /** - * Test tax calculation with various configuration and combination of items - * This method will test various collectors through $quoteAddress->collectTotals() method - * - * @param array $configData - * @param array $quoteData - * @param array $expectedResults - * @magentoDbIsolation disabled - * @magentoAppIsolation enabled - * @dataProvider taxDataProvider - * @return void - */ - public function testTaxCalculation($configData, $quoteData, $expectedResults) - { - $db = \Magento\TestFramework\Helper\Bootstrap::getInstance()->getBootstrap() - ->getApplication() - ->getDbInstance(); - if (!$db->isDbDumpExists()) { - throw new \LogicException('DB dump does not exist.'); - } - $db->restoreFromDbDump(); - //Setup tax configurations - $this->setupUtil->setupTax($configData); - - $quote = $this->setupUtil->setupQuote($quoteData); - $quoteAddress = $quote->getShippingAddress(); - $this->totalsCollector->collectAddressTotals($quote, $quoteAddress); - $this->verifyResult($quoteAddress, $expectedResults); - } - - /** - * Read the array defined in ../../../../_files/tax_calculation_data_aggregated.php - * and feed it to testTaxCalculation - * - * @return array - */ - public function taxDataProvider() - { - global $taxCalculationData; - return $taxCalculationData; - } -}