init
This commit is contained in:
+81
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\SalesRule\Model\ResourceModel\Coupon;
|
||||
|
||||
use Magento\Framework\DataObject;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\SalesRule\Model\Coupon;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* Tests accounting of coupon usages.
|
||||
*
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
class UsageTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var Coupon
|
||||
*/
|
||||
private $coupon;
|
||||
|
||||
/**
|
||||
* @var Usage
|
||||
*/
|
||||
private $usage;
|
||||
|
||||
/**
|
||||
* @var DataObject
|
||||
*/
|
||||
private $couponUsage;
|
||||
|
||||
/**
|
||||
* Tests incrementing and decrementing of coupon usages.
|
||||
*
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/SalesRule/_files/coupons_limited.php
|
||||
*/
|
||||
public function testUpdateCustomerCouponTimesUsed()
|
||||
{
|
||||
$customerId = 1;
|
||||
$couponCode = 'one_usage';
|
||||
|
||||
$this->coupon->loadByCode($couponCode);
|
||||
|
||||
$testCases = [
|
||||
['increment' => true, 'expected' => 1],
|
||||
['increment' => false, 'expected' => 0],
|
||||
['increment' => false, 'expected' => 0],
|
||||
['increment' => true, 'expected' => 1],
|
||||
['increment' => true, 'expected' => 2],
|
||||
];
|
||||
|
||||
foreach ($testCases as $testCase) {
|
||||
$this->usage->updateCustomerCouponTimesUsed($customerId, $this->coupon->getId(), $testCase['increment']);
|
||||
$this->usage->loadByCustomerCoupon($this->couponUsage, $customerId, $this->coupon->getId());
|
||||
|
||||
self::assertEquals(
|
||||
$testCase['expected'],
|
||||
$this->couponUsage->getTimesUsed()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->coupon = $this->objectManager->get(Coupon::class);
|
||||
$this->usage = $this->objectManager->get(Usage::class);
|
||||
$this->couponUsage = $this->objectManager->get(DataObject::class);
|
||||
}
|
||||
}
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\SalesRule\Model\ResourceModel\Report\Rule;
|
||||
|
||||
/**
|
||||
* Createdat test for check report totals calculate
|
||||
*
|
||||
* @magentoDataFixture Magento/SalesRule/_files/order_with_coupon.php
|
||||
*/
|
||||
class CreatedatTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider orderParamsDataProvider()
|
||||
* @param $orderParams
|
||||
*/
|
||||
public function testTotals($orderParams)
|
||||
{
|
||||
/** @var \Magento\Sales\Model\Order $order */
|
||||
$order = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Sales\Model\Order::class);
|
||||
$order->loadByIncrementId('100000001')
|
||||
->setBaseGrandTotal($orderParams['base_subtotal'])
|
||||
->setSubtotal($orderParams['base_subtotal'])
|
||||
->setBaseSubtotal($orderParams['base_subtotal'])
|
||||
->setBaseDiscountAmount($orderParams['base_discount_amount'])
|
||||
->setBaseTaxAmount($orderParams['base_tax_amount'])
|
||||
->setBaseSubtotalInvoiced($orderParams['base_subtotal_invoiced'])
|
||||
->setBaseDiscountInvoiced($orderParams['base_discount_invoiced'])
|
||||
->setBaseTaxInvoiced($orderParams['base_tax_invoiced'])
|
||||
->setBaseShippingAmount(0)
|
||||
->setBaseToGlobalRate(1)
|
||||
->setCouponCode('1234567890')
|
||||
->setCreatedAt('2014-10-25 10:10:10')
|
||||
->save();
|
||||
// refresh report statistics
|
||||
/** @var \Magento\SalesRule\Model\ResourceModel\Report\Rule $reportResource */
|
||||
$reportResource = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\SalesRule\Model\ResourceModel\Report\Rule::class
|
||||
);
|
||||
$reportResource->aggregate();
|
||||
/** @var \Magento\SalesRule\Model\ResourceModel\Report\Collection $reportCollection */
|
||||
$reportCollection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\SalesRule\Model\ResourceModel\Report\Collection::class
|
||||
);
|
||||
$salesRuleReportItem = $reportCollection->getFirstItem();
|
||||
$this->assertEquals($this->getTotalAmount($order), $salesRuleReportItem['total_amount']);
|
||||
$this->assertEquals($this->getTotalAmountActual($order), $salesRuleReportItem['total_amount_actual']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Repeat sql formula from \Magento\SalesRule\Model\ResourceModel\Report\Rule\Createdat::_aggregateByOrder
|
||||
*
|
||||
* @param \Magento\Sales\Model\Order $order
|
||||
* @return float
|
||||
*/
|
||||
private function getTotalAmount(\Magento\Sales\Model\Order $order)
|
||||
{
|
||||
return (
|
||||
($order->getBaseSubtotal() - $order->getBaseSubtotalCanceled()
|
||||
+ ($order->getBaseShippingAmount() - $order->getBaseShippingCanceled()))
|
||||
- (abs((float) $order->getBaseDiscountAmount()) - abs((float) $order->getBaseDiscountCanceled()))
|
||||
+ ($order->getBaseTaxAmount() - $order->getBaseTaxCanceled())
|
||||
) * $order->getBaseToGlobalRate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Repeat sql formula from \Magento\SalesRule\Model\ResourceModel\Report\Rule\Createdat::_aggregateByOrder
|
||||
*
|
||||
* @param \Magento\Sales\Model\Order $order
|
||||
* @return float
|
||||
*/
|
||||
private function getTotalAmountActual(\Magento\Sales\Model\Order $order)
|
||||
{
|
||||
return (
|
||||
($order->getBaseSubtotalInvoiced() - $order->getSubtotalRefunded()
|
||||
+ ($order->getBaseShippingInvoiced() - $order->getBaseShippingRefunded()))
|
||||
- abs((float) $order->getBaseDiscountInvoiced()) - abs((float) $order->getBaseDiscountRefunded())
|
||||
+ $order->getBaseTaxInvoiced() - $order->getBaseTaxRefunded()
|
||||
) * $order->getBaseToGlobalRate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function orderParamsDataProvider()
|
||||
{
|
||||
return [
|
||||
[
|
||||
[
|
||||
'base_discount_amount' => 98.80,
|
||||
'base_subtotal' => 494,
|
||||
'base_tax_amount' => 8.8,
|
||||
'base_subtotal_invoiced' => 494,
|
||||
'base_discount_invoiced' => 98.80,
|
||||
'base_tax_invoiced' => 8.8
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\SalesRule\Model\ResourceModel\Report;
|
||||
|
||||
use Magento\Sales\Model\Order;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test for salesrule report model
|
||||
*/
|
||||
class RuleTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @magentoDataFixture Magento/SalesRule/_files/order_with_coupon.php
|
||||
*/
|
||||
public function testGetUniqRulesNamesList()
|
||||
{
|
||||
$ruleName = uniqid('cart_price_rule_');
|
||||
$orderIncrementId = '100000001';
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var Order $order */
|
||||
$order = $objectManager->create(Order::class);
|
||||
$order->loadByIncrementId($orderIncrementId)
|
||||
->setCouponRuleName($ruleName)
|
||||
->save();
|
||||
/** @var Rule $reportResource */
|
||||
$reportResource = $objectManager->create(Rule::class);
|
||||
$reportResource->aggregate();
|
||||
$this->assertContains($ruleName, $reportResource->getUniqRulesNamesList());
|
||||
}
|
||||
}
|
||||
+313
@@ -0,0 +1,313 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\SalesRule\Model\ResourceModel\Rule;
|
||||
|
||||
use Magento\Config\Model\Config\Backend\Admin\Custom as AdminBackendConfig;
|
||||
use Magento\Framework\App\Config\ScopeConfigInterface;
|
||||
use Magento\Store\Api\WebsiteRepositoryInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
class CollectionTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var Collection
|
||||
*/
|
||||
private $collection;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $defaultTimezone;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$scopeConfig = Bootstrap::getObjectManager()->get(ScopeConfigInterface::class);
|
||||
$this->defaultTimezone = $scopeConfig->getValue(AdminBackendConfig::XML_PATH_GENERAL_LOCALE_TIMEZONE);
|
||||
|
||||
$this->collection = Bootstrap::getObjectManager()->create(Collection::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/SalesRule/_files/rules.php
|
||||
* @magentoDataFixture Magento/SalesRule/_files/coupons.php
|
||||
* @dataProvider setValidationFilterDataProvider()
|
||||
* @param string $couponCode
|
||||
* @param array $expectedItems
|
||||
* @magentoDbIsolation disabled
|
||||
*/
|
||||
public function testSetValidationFilter($couponCode, $expectedItems)
|
||||
{
|
||||
/** @var \Magento\SalesRule\Model\Rule[] $items */
|
||||
$items = array_values($this->collection->setValidationFilter(1, 0, $couponCode)->getItems());
|
||||
|
||||
$this->assertEquals(
|
||||
count($expectedItems),
|
||||
count($items),
|
||||
'Invalid number of items in the result collection'
|
||||
);
|
||||
|
||||
$ids = [];
|
||||
foreach ($items as $key => $item) {
|
||||
$this->assertEquals($expectedItems[$key], $item->getName());
|
||||
$this->assertFalse(
|
||||
in_array($item->getId(), $ids),
|
||||
'Item should be unique in result collection'
|
||||
);
|
||||
$ids[] = $item->getId();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* data provider for testSetValidationFilter
|
||||
* @return array
|
||||
*/
|
||||
public function setValidationFilterDataProvider()
|
||||
{
|
||||
return [
|
||||
'Check type COUPON' => ['coupon_code', ['#1', '#2', '#5']],
|
||||
'Check type NO_COUPON' => ['', ['#2', '#5']],
|
||||
'Check type COUPON_AUTO' => ['coupon_code_auto', ['#2', '#4', '#5']],
|
||||
'Check result with auto generated coupon' => ['autogenerated_3_1', ['#2', '#3', '#5']],
|
||||
'Check result with non actual previously generated coupon' => [
|
||||
'autogenerated_2_1',
|
||||
['#2', '#5'],
|
||||
],
|
||||
'Check result with wrong code' => ['wrong_code', ['#2', '#5']]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation disabled
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDataFixture Magento/Checkout/_files/quote_with_shipping_method_and_items_categories.php
|
||||
* @magentoDataFixture Magento/SalesRule/_files/rules_group_any_categories.php
|
||||
*/
|
||||
public function testSetValidationFilterWithGroup()
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
/** @var \Magento\SalesRule\Model\Rule $rule */
|
||||
$rule = $objectManager->get(\Magento\Framework\Registry::class)
|
||||
->registry('_fixture/Magento_SalesRule_Group_Multiple_Categories');
|
||||
|
||||
/** @var \Magento\Quote\Model\Quote $quote */
|
||||
$quote = $objectManager->create(\Magento\Quote\Model\Quote::class);
|
||||
$quote->load('test_order_item_with_items', 'reserved_order_id');
|
||||
|
||||
//gather only the existing rules that obey the validation filter
|
||||
$appliedRulesArray = array_keys(
|
||||
$this->collection->setValidationFilter(
|
||||
$quote->getStore()->getWebsiteId(),
|
||||
0,
|
||||
'',
|
||||
null,
|
||||
$quote->getShippingAddress()
|
||||
)->getItems()
|
||||
);
|
||||
|
||||
$this->assertEquals([$rule->getRuleId()], $appliedRulesArray);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation disabled
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDataFixture Magento/Checkout/_files/quote_with_shipping_method_and_items_categories.php
|
||||
* @magentoDataFixture Magento/SalesRule/_files/rules_group_any_categories.php
|
||||
*/
|
||||
public function testSetValidationFilterAnyCategory()
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
/** @var \Magento\SalesRule\Model\Rule $rule */
|
||||
$rule = $objectManager->get(\Magento\Framework\Registry::class)
|
||||
->registry('_fixture/Magento_SalesRule_Group_Multiple_Categories');
|
||||
|
||||
/** @var \Magento\Quote\Model\Quote $quote */
|
||||
$quote = $objectManager->create(\Magento\Quote\Model\Quote::class);
|
||||
$quote->load('test_order_item_with_items', 'reserved_order_id');
|
||||
|
||||
//gather only the existing rules that obey the validation filter
|
||||
$appliedRulesArray = array_keys(
|
||||
$this->collection->setValidationFilter(
|
||||
$quote->getStore()->getWebsiteId(),
|
||||
0,
|
||||
'',
|
||||
null,
|
||||
$quote->getShippingAddress()
|
||||
)->getItems()
|
||||
);
|
||||
$this->assertEquals([$rule->getRuleId()], $appliedRulesArray);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation disabled
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDataFixture Magento/Checkout/_files/quote_with_shipping_method_and_items_categories.php
|
||||
* @magentoDataFixture Magento/SalesRule/_files/rules_group_not_categories_sku_attr.php
|
||||
* @magentoDataFixture Magento/SalesRule/_files/rules_group_any_categories.php
|
||||
* @magentoDataFixture Magento/SalesRule/_files/rules_group_any_categories_price_attr_set_any.php
|
||||
*/
|
||||
public function testSetValidationFilterOther()
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
/** @var \Magento\Quote\Model\Quote $quote */
|
||||
$quote = $objectManager->create(\Magento\Quote\Model\Quote::class);
|
||||
$quote->load('test_order_item_with_items', 'reserved_order_id');
|
||||
|
||||
//gather only the existing rules that obey the validation filter
|
||||
$appliedRulesArray = array_keys(
|
||||
$this->collection->setValidationFilter(
|
||||
$quote->getStore()->getWebsiteId(),
|
||||
0,
|
||||
'',
|
||||
null,
|
||||
$quote->getShippingAddress()
|
||||
)->getItems()
|
||||
);
|
||||
$this->assertCount(3, $appliedRulesArray);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDataFixture Magento/SalesRule/_files/rules.php
|
||||
* @magentoDataFixture Magento/SalesRule/_files/coupons.php
|
||||
* @magentoDataFixture Magento/SalesRule/_files/rule_specific_date.php
|
||||
* @magentoConfigFixture general/locale/timezone Europe/Kiev
|
||||
*/
|
||||
public function testMultiRulesWithTimezone()
|
||||
{
|
||||
$this->setSpecificTimezone('Europe/Kiev');
|
||||
$this->collection->addWebsiteGroupDateFilter(1, 0);
|
||||
$items = array_values($this->collection->getItems());
|
||||
$this->assertNotEmpty($items);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDataFixture Magento/SalesRule/_files/rules.php
|
||||
* @magentoDataFixture Magento/SalesRule/_files/coupons.php
|
||||
* @magentoDataFixture Magento/SalesRule/_files/rule_specific_date.php
|
||||
* @magentoConfigFixture general/locale/timezone Australia/Sydney
|
||||
*/
|
||||
public function testMultiRulesWithDifferentTimezone()
|
||||
{
|
||||
$this->setSpecificTimezone('Australia/Sydney');
|
||||
$this->collection->addWebsiteGroupDateFilter(1, 0);
|
||||
$items = array_values($this->collection->getItems());
|
||||
$this->assertNotEmpty($items);
|
||||
}
|
||||
|
||||
protected function setSpecificTimezone($timezone)
|
||||
{
|
||||
$localeData = [
|
||||
'section' => 'general',
|
||||
'website' => null,
|
||||
'store' => null,
|
||||
'groups' => [
|
||||
'locale' => [
|
||||
'fields' => [
|
||||
'timezone' => [
|
||||
'value' => $timezone
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
Bootstrap::getObjectManager()->get(\Magento\Config\Model\Config\Factory::class)
|
||||
->create()
|
||||
->addData($localeData)
|
||||
->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that it's possible to find previously created rule by attribute.
|
||||
*
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDataFixture Magento/SalesRule/_files/rule_custom_product_attribute.php
|
||||
*/
|
||||
public function testAddAttributeInConditionFilterPositive()
|
||||
{
|
||||
$this->collection->addAttributeInConditionFilter('attribute_for_sales_rule_1');
|
||||
/** @var \Magento\SalesRule\Model\Rule $item */
|
||||
$item = $this->collection->getFirstItem();
|
||||
$this->assertEquals('50% Off on some attribute', $item->getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that it's not possible to find previously created rule by wrong attribute.
|
||||
*
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDataFixture Magento/SalesRule/_files/rule_custom_product_attribute.php
|
||||
*/
|
||||
public function testAddAttributeInConditionFilterNegative()
|
||||
{
|
||||
$this->collection->addAttributeInConditionFilter('attribute_for_sales_rule_2');
|
||||
$this->assertEquals(0, $this->collection->count());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation disabled
|
||||
* @magentoDataFixture Magento/SalesRule/_files/multi_websites_rules.php
|
||||
* @dataProvider addWebsiteFilterDataProvider
|
||||
* @param string[] $websiteCodes
|
||||
* @param int $count
|
||||
*/
|
||||
public function testAddWebsiteFilter(array $websiteCodes, int $count)
|
||||
{
|
||||
$websiteRepository = Bootstrap::getObjectManager()->get(WebsiteRepositoryInterface::class);
|
||||
$websiteIds = [];
|
||||
foreach ($websiteCodes as $websiteCode) {
|
||||
$websiteIds[] = (int) $websiteRepository->get($websiteCode)->getId();
|
||||
}
|
||||
|
||||
$this->collection->addWebsiteFilter($websiteIds);
|
||||
$this->assertEquals($count, $this->collection->getSize());
|
||||
$this->assertCount($count, $this->collection->getItems());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function addWebsiteFilterDataProvider(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
['base'],
|
||||
4,
|
||||
],
|
||||
[
|
||||
['test'],
|
||||
2,
|
||||
],
|
||||
[
|
||||
['base', 'test'],
|
||||
5,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
// restore default timezone
|
||||
$this->setSpecificTimezone($this->defaultTimezone);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\SalesRule\Model\ResourceModel;
|
||||
|
||||
use Magento\SalesRule\Test\Fixture\ProductCondition as ProductConditionFixture;
|
||||
use Magento\SalesRule\Test\Fixture\ProductFoundInCartConditions as ProductFoundInCartConditionsFixture;
|
||||
use Magento\SalesRule\Test\Fixture\Rule as RuleFixture;
|
||||
use Magento\TestFramework\Fixture\DataFixture;
|
||||
use Magento\TestFramework\Fixture\DataFixtureStorage;
|
||||
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
class RuleTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var DataFixtureStorage
|
||||
*/
|
||||
private $fixtures;
|
||||
|
||||
/**
|
||||
* @var Rule
|
||||
*/
|
||||
private $resource;
|
||||
|
||||
/**
|
||||
* @inheirtDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->fixtures = Bootstrap::getObjectManager()->get(
|
||||
DataFixtureStorageManager::class
|
||||
)->getStorage();
|
||||
$this->resource = Bootstrap::getObjectManager()->create(
|
||||
Rule::class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/SalesRule/_files/rule_custom_product_attribute.php
|
||||
*/
|
||||
public function testAfterSave()
|
||||
{
|
||||
$items = $this->resource->getActiveAttributes();
|
||||
|
||||
$this->assertEquals([['attribute_code' => 'attribute_for_sales_rule_1']], $items);
|
||||
}
|
||||
|
||||
#[
|
||||
DataFixture(
|
||||
ProductConditionFixture::class,
|
||||
['attribute' => 'category_ids', 'value' => '2'],
|
||||
'cond11'
|
||||
),
|
||||
DataFixture(
|
||||
ProductFoundInCartConditionsFixture::class,
|
||||
['conditions' => ['$cond11$']],
|
||||
'cond1'
|
||||
),
|
||||
DataFixture(
|
||||
RuleFixture::class,
|
||||
['discount_amount' => 50, 'conditions' => ['$cond1$'], 'is_active' => 0],
|
||||
'rule1'
|
||||
)
|
||||
]
|
||||
public function testGetActiveAttributes()
|
||||
{
|
||||
$rule = $this->fixtures->get('rule1');
|
||||
$items = $this->resource->getActiveAttributes();
|
||||
$this->assertEquals([], $items);
|
||||
$rule->setIsActive(1);
|
||||
$rule->save();
|
||||
$items = $this->resource->getActiveAttributes();
|
||||
$this->assertEquals([['attribute_code' => 'category_ids']], $items);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user