Skip to content

Commit

Permalink
Merge pull request #6787 from magento-tsg/2.4-develop-pr142
Browse files Browse the repository at this point in the history
[Arrows] Fixes for 2.4 (pr142) (2.4-develop)
  • Loading branch information
zakdma authored Apr 15, 2021
2 parents cdd4d4b + b749025 commit d2155b3
Show file tree
Hide file tree
Showing 12 changed files with 225 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,13 @@ define([
}
},

/**
* Helper to find select element of currently confirmed item
*/
getCurrentConfirmedSelectElement: function () {
return $(this.confirmedCurrentId).getElementsByTagName('select');
},

/**
* Helper to find qty of active form
*/
Expand Down
3 changes: 2 additions & 1 deletion app/code/Magento/CatalogRule/Model/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ protected function _invalidateCache()
*/
public function afterSave()
{
if (!$this->getIsActive()) {
if (!$this->getIsActive() && !$this->getOrigData(self::IS_ACTIVE)) {
return parent::afterSave();
}

Expand All @@ -601,6 +601,7 @@ public function afterSave()
} else {
$this->_ruleProductProcessor->getIndexer()->invalidate();
}

return parent::afterSave();
}

Expand Down
104 changes: 67 additions & 37 deletions app/code/Magento/CatalogRule/Test/Unit/Model/RuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
use Magento\CatalogRule\Api\Data\RuleInterface;
use Magento\CatalogRule\Model\Indexer\Rule\RuleProductProcessor;
use Magento\CatalogRule\Model\Rule;
use Magento\CatalogRule\Model\Rule\Condition\CombineFactory;
Expand All @@ -31,46 +32,60 @@
*/
class RuleTest extends TestCase
{
/** @var Rule */
protected $rule;
/**
* @var Rule
*/
private $rule;

/** @var ObjectManager */
/**
* @var ObjectManager
*/
private $objectManager;

/** @var StoreManagerInterface|MockObject */
protected $storeManager;
/**
* @var StoreManagerInterface|MockObject
*/
private $storeManager;

/** @var MockObject */
protected $combineFactory;
/**
* @var CombineFactory|MockObject
*/
private $combineFactory;

/** @var Store|MockObject */
protected $storeModel;
/**
* @var Store|MockObject
*/
private $storeModel;

/** @var Website|MockObject */
protected $websiteModel;
/**
* @var Website|MockObject
*/
private $websiteModel;

/** @var Combine|MockObject */
protected $condition;
/**
* @var Combine|MockObject
*/
private $condition;

/**
* @var RuleProductProcessor|MockObject
*/
protected $_ruleProductProcessor;
private $_ruleProductProcessor;

/**
* @var CollectionFactory|MockObject
*/
protected $_productCollectionFactory;
private $_productCollectionFactory;

/**
* @var Iterator|MockObject
*/
protected $_resourceIterator;
private $_resourceIterator;

/**
* @var Product|MockObject
*/
protected $productModel;
private $productModel;

/**
* Set up before test
Expand All @@ -85,15 +100,15 @@ protected function setUp(): void
$this->combineFactory = $this->createPartialMock(
CombineFactory::class,
[
'create'
'create',
]
);
$this->productModel = $this->createPartialMock(
Product::class,
[
'__wakeup',
'getId',
'setData'
'setData',
]
);
$this->condition = $this->getMockBuilder(Combine::class)
Expand All @@ -106,7 +121,7 @@ protected function setUp(): void
[
'__wakeup',
'getId',
'getDefaultStore'
'getDefaultStore',
]
);
$this->_ruleProductProcessor = $this->createMock(
Expand Down Expand Up @@ -192,7 +207,7 @@ public function testCallbackValidateProduct($validate)
'has_options' => '0',
'required_options' => '0',
'created_at' => '2014-06-25 13:14:30',
'updated_at' => '2014-06-25 14:37:15'
'updated_at' => '2014-06-25 14:37:15',
];
$this->storeManager->expects($this->any())->method('getWebsites')->with(false)
->willReturn([$this->websiteModel, $this->websiteModel]);
Expand Down Expand Up @@ -263,14 +278,14 @@ public function validateDataDataProvider()
'simple_action' => 'by_fixed',
'discount_amount' => '123',
],
true
true,
],
[
[
'simple_action' => 'by_percent',
'discount_amount' => '9,99',
],
true
true,
],
[
[
Expand All @@ -279,7 +294,7 @@ public function validateDataDataProvider()
],
[
'Percentage discount should be between 0 and 100.',
]
],
],
[
[
Expand All @@ -288,7 +303,7 @@ public function validateDataDataProvider()
],
[
'Percentage discount should be between 0 and 100.',
]
],
],
[
[
Expand All @@ -297,7 +312,7 @@ public function validateDataDataProvider()
],
[
'Discount value should be 0 or greater.',
]
],
],
[
[
Expand All @@ -306,7 +321,7 @@ public function validateDataDataProvider()
],
[
'Unknown action.',
]
],
],
];
}
Expand All @@ -325,33 +340,48 @@ public function testAfterDelete()
}

/**
* Test after update action for inactive rule
* Test after update action for active and deactivated rule.
*
* @dataProvider afterUpdateDataProvider
* @param int $active
* @return void
*/
public function testAfterUpdateInactive()
public function testAfterUpdate(int $active)
{
$this->rule->isObjectNew(false);
$this->rule->setIsActive(0);
$this->_ruleProductProcessor->expects($this->never())->method('getIndexer');
$this->rule->setIsActive($active);
$this->rule->setOrigData(RuleInterface::IS_ACTIVE, 1);
$indexer = $this->getMockForAbstractClass(IndexerInterface::class);
$indexer->expects($this->once())->method('invalidate');
$this->_ruleProductProcessor->expects($this->once())->method('getIndexer')->willReturn($indexer);
$this->rule->afterSave();
}

/**
* Test after update action for active rule
* Test after update action for inactive rule.
*
* @return void
*/
public function testAfterUpdateActive()
public function testAfterUpdateInactiveRule()
{
$this->rule->isObjectNew(false);
$this->rule->setIsActive(1);
$indexer = $this->getMockForAbstractClass(IndexerInterface::class);
$indexer->expects($this->once())->method('invalidate');
$this->_ruleProductProcessor->expects($this->once())->method('getIndexer')->willReturn($indexer);
$this->rule->setIsActive(0);
$this->rule->setOrigData(RuleInterface::IS_ACTIVE, 0);
$this->_ruleProductProcessor->expects($this->never())->method('getIndexer');
$this->rule->afterSave();
}

/**
* @return array
*/
public function afterUpdateDataProvider(): array
{
return [
['active' => 0],
['active' => 1],
];
}

/**
* Test isRuleBehaviorChanged action
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@

<!-- Check order summary in checkout -->
<waitForElement selector="{{CheckoutPaymentSection.paymentSectionTitle}}" stepKey="waitForPaymentSectionLoaded"/>
<waitForElementVisible selector="{{CheckoutPaymentSection.placeOrder}}" stepKey="waitForPlaceOrderButton"/>
<click selector="{{CheckoutPaymentSection.placeOrder}}" stepKey="clickPlaceOrderButton"/>
<seeElement selector="{{CheckoutSuccessMainSection.success}}" stepKey="orderIsSuccessfullyPlaced"/>
<grabTextFrom selector="{{CheckoutSuccessMainSection.orderNumber22}}" stepKey="grabOrderNumber"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@

<!-- Check order summary in checkout -->
<waitForElement selector="{{CheckoutPaymentSection.paymentSectionTitle}}" stepKey="waitForPaymentSectionLoaded"/>
<waitForElementVisible selector="{{CheckoutPaymentSection.placeOrder}}" stepKey="waitForPlaceOrderButton"/>
<click selector="{{CheckoutPaymentSection.placeOrder}}" stepKey="clickPlaceOrderButton"/>
<seeElement selector="{{CheckoutSuccessMainSection.success}}" stepKey="orderIsSuccessfullyPlaced"/>
<grabTextFrom selector="{{CheckoutSuccessMainSection.orderNumber22}}" stepKey="grabOrderNumber"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@

<!-- Check order summary in checkout -->
<waitForElement selector="{{CheckoutPaymentSection.paymentSectionTitle}}" stepKey="waitForPaymentSectionLoaded"/>
<waitForElementVisible selector="{{CheckoutPaymentSection.placeOrder}}" stepKey="waitForPlaceOrderButton"/>
<click selector="{{CheckoutPaymentSection.placeOrder}}" stepKey="clickPlaceOrderButton"/>
<seeElement selector="{{CheckoutSuccessMainSection.success}}" stepKey="orderIsSuccessfullyPlaced"/>
<grabTextFrom selector="{{CheckoutSuccessMainSection.orderNumber22}}" stepKey="grabOrderNumber"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="StorefrontGuestCheckoutWithDifferentShippingAndBillingAddressWithRestrictedCountriesForPaymentTest">
<annotations>
<features value="Checkout"/>
<stories value="Check payment methods on checkout"/>
<title value="Check payment methods update on checkout payment step"/>
<description value="Check that payment methods will update on checkout payment step after updating customer billing address"/>
<severity value="AVERAGE"/>
<testCaseId value="MC-41743"/>
<useCaseId value="MC-37820"/>
<group value="checkout"/>
</annotations>

<before>
<magentoCLI command="config:set {{BankTransferEnableConfigData.path}} {{BankTransferEnableConfigData.value}}" stepKey="enableBankTransfer"/>
<magentoCLI command="config:set payment/checkmo/allowspecific 1" stepKey="allowSpecificValue"/>
<magentoCLI command="config:set payment/checkmo/specificcountry GB" stepKey="allowBankTransferOnlyForGB"/>
<createData entity="SimpleProduct2" stepKey="createProduct"/>
</before>

<after>
<magentoCLI command="config:set {{BankTransferDisabledConfigData.path}} {{BankTransferDisabledConfigData.value}}" stepKey="disableBankTransfer"/>
<magentoCLI command="config:set payment/checkmo/allowspecific 0" stepKey="disallowSpecificValue" />
<magentoCLI command="config:set payment/checkmo/specificcountry ''" stepKey="defaultCountryValue"/>
<deleteData createDataKey="createProduct" stepKey="deleteProduct"/>
</after>

<actionGroup ref="StorefrontOpenProductPageActionGroup" stepKey="openProductPage">
<argument name="productUrl" value="$createProduct.custom_attributes[url_key]$"/>
</actionGroup>
<actionGroup ref="AddToCartFromStorefrontProductPageActionGroup" stepKey="addToCartFromStorefrontProductPage">
<argument name="productName" value="$createProduct.name$"/>
</actionGroup>
<actionGroup ref="GoToCheckoutFromMinicartActionGroup" stepKey="goToCheckoutFromMinicart"/>
<actionGroup ref="GuestCheckoutFillingShippingSectionActionGroup" stepKey="fillShippingSectionAsGuest">
<argument name="customerVar" value="CustomerEntityOne"/>
<argument name="customerAddressVar" value="CustomerAddressSimple"/>
</actionGroup>
<dontSee selector="{{CheckoutPaymentSection.paymentMethodTitle}}" userInput="Check / Money order" stepKey="assertNoCheckMoneyOrderPaymentMethod"/>
<waitForElementVisible selector="{{CheckoutPaymentSection.billingAddressNotSameBankTransferCheckbox}}" stepKey="waitForBillingAddressNotSameAsShippingCheckbox"/>
<uncheckOption selector="{{CheckoutPaymentSection.billingAddressNotSameBankTransferCheckbox}}" stepKey="uncheckSameBillingAndShippingAddress"/>
<conditionalClick selector="{{CheckoutPaymentSection.editAddress}}" dependentSelector="{{CheckoutShippingSection.editAddressButton}}" visible="true" stepKey="clickEditBillingAddressButton"/>
<waitForLoadingMaskToDisappear stepKey="waitForBillingAddressFormLoads"/>

<!-- Fill Billing Address -->
<actionGroup ref="StorefrontFillBillingAddressActionGroup" stepKey="fillBillingAddress"/>
<click selector="{{CheckoutPaymentSection.update}}" stepKey="clickOnUpdateButton"/>
<waitForLoadingMaskToDisappear stepKey="waitForLoadingMaskDisappear" />
<see selector="{{CheckoutPaymentSection.paymentMethodTitle}}" userInput="Check / Money order" stepKey="sdadasdasdsdaasd"/>
</test>
</tests>
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ function (
checkoutData.setNewCustomerBillingAddress(addressData);
}
}
setBillingAddressAction(globalMessageList);
this.updateAddresses();
},

Expand Down
5 changes: 4 additions & 1 deletion app/code/Magento/Customer/Model/Metadata/Form/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,10 @@ public function compactValue($value)
}

// Remove outdated file (in the case of file uploader UI component)
if (!empty($this->_value) && !empty($value['delete'])) {
if (!empty($this->_value)
&& (!empty($value['delete'])
|| ($this->_entityTypeCode == 'customer' && empty($value)))
) {
$this->fileProcessor->removeUploadedFile($this->_value);
return $value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ public function testCompactValueNoDelete()
->with('value')
->willReturnSelf();

$this->assertSame('value', $model->compactValue([]));
$this->assertSame([], $model->compactValue([]));
}

public function testCompactValueDelete()
Expand Down Expand Up @@ -625,7 +625,7 @@ public function testCompactValueRemoveUiComponentValue()
->with($value)
->willReturnSelf();

$this->assertEquals($value, $model->compactValue([]));
$this->assertEquals([], $model->compactValue([]));
}

public function testCompactValueNoAction()
Expand Down
Loading

0 comments on commit d2155b3

Please sign in to comment.