diff --git a/app/code/Magento/Braintree/Model/Ui/ConfigProvider.php b/app/code/Magento/Braintree/Model/Ui/ConfigProvider.php index ab23037b4e98e..1ba696839a95d 100644 --- a/app/code/Magento/Braintree/Model/Ui/ConfigProvider.php +++ b/app/code/Magento/Braintree/Model/Ui/ConfigProvider.php @@ -67,11 +67,12 @@ public function __construct( public function getConfig() { $storeId = $this->session->getStoreId(); + $isActive = $this->config->isActive($storeId); return [ 'payment' => [ self::CODE => [ - 'isActive' => $this->config->isActive($storeId), - 'clientToken' => $this->getClientToken(), + 'isActive' => $isActive, + 'clientToken' => $isActive ? $this->getClientToken() : null, 'ccTypesMapper' => $this->config->getCcTypesMapper(), 'sdkUrl' => $this->config->getSdkUrl(), 'hostedFieldsSdkUrl' => $this->config->getHostedFieldsSdkUrl(), diff --git a/app/code/Magento/Braintree/Test/Unit/Model/Ui/ConfigProviderTest.php b/app/code/Magento/Braintree/Test/Unit/Model/Ui/ConfigProviderTest.php index 55bc2cb195d6e..fb34113be15ae 100644 --- a/app/code/Magento/Braintree/Test/Unit/Model/Ui/ConfigProviderTest.php +++ b/app/code/Magento/Braintree/Test/Unit/Model/Ui/ConfigProviderTest.php @@ -76,7 +76,7 @@ protected function setUp() } /** - * Run test getConfig method + * Ensure that get config returns correct data if payment is active or not * * @param array $config * @param array $expected @@ -84,22 +84,37 @@ protected function setUp() */ public function testGetConfig($config, $expected) { - $this->braintreeAdapter->expects(static::once()) - ->method('generate') - ->willReturn(self::CLIENT_TOKEN); + if ($config['isActive']) { + $this->braintreeAdapter->expects($this->once()) + ->method('generate') + ->willReturn(self::CLIENT_TOKEN); + } else { + $config = array_replace_recursive( + $this->getConfigDataProvider()[0]['config'], + $config + ); + $expected = array_replace_recursive( + $this->getConfigDataProvider()[0]['expected'], + $expected + ); + $this->braintreeAdapter->expects($this->never()) + ->method('generate'); + } foreach ($config as $method => $value) { - $this->config->expects(static::once()) + $this->config->expects($this->once()) ->method($method) ->willReturn($value); } - static::assertEquals($expected, $this->configProvider->getConfig()); + $this->assertEquals($expected, $this->configProvider->getConfig()); } /** - * @covers \Magento\Braintree\Model\Ui\ConfigProvider::getClientToken + * @covers \Magento\Braintree\Model\Ui\ConfigProvider::getClientToken * @dataProvider getClientTokenDataProvider + * @param $merchantAccountId + * @param $params */ public function testGetClientToken($merchantAccountId, $params) { @@ -124,7 +139,7 @@ public function getConfigDataProvider() [ 'config' => [ 'isActive' => true, - 'getCcTypesMapper' => ['visa' => 'VI', 'american-express'=> 'AE'], + 'getCcTypesMapper' => ['visa' => 'VI', 'american-express' => 'AE'], 'getSdkUrl' => self::SDK_URL, 'getHostedFieldsSdkUrl' => 'https://sdk.com/test.js', 'getCountrySpecificCardTypeConfig' => [ @@ -148,7 +163,7 @@ public function getConfigDataProvider() 'ccTypesMapper' => ['visa' => 'VI', 'american-express' => 'AE'], 'sdkUrl' => self::SDK_URL, 'hostedFieldsSdkUrl' => 'https://sdk.com/test.js', - 'countrySpecificCardTypes' =>[ + 'countrySpecificCardTypes' => [ 'GB' => ['VI', 'AE'], 'US' => ['DI', 'JCB'] ], @@ -166,6 +181,19 @@ public function getConfigDataProvider() ] ] ] + ], + [ + 'config' => [ + 'isActive' => false, + ], + 'expected' => [ + 'payment' => [ + ConfigProvider::CODE => [ + 'isActive' => false, + 'clientToken' => null, + ] + ] + ] ] ]; } diff --git a/app/code/Magento/CatalogUrlRewrite/Observer/CategoryUrlPathAutogeneratorObserver.php b/app/code/Magento/CatalogUrlRewrite/Observer/CategoryUrlPathAutogeneratorObserver.php index 54ef7102fcc47..0d0b0fb995706 100644 --- a/app/code/Magento/CatalogUrlRewrite/Observer/CategoryUrlPathAutogeneratorObserver.php +++ b/app/code/Magento/CatalogUrlRewrite/Observer/CategoryUrlPathAutogeneratorObserver.php @@ -94,7 +94,7 @@ public function execute(\Magento\Framework\Event\Observer $observer) $resultUrlKey = $this->categoryUrlPathGenerator->getUrlKey($category); $this->updateUrlKey($category, $resultUrlKey); } elseif ($useDefaultAttribute) { - if (!$category->isObjectNew()) { + if (!$category->isObjectNew() && $category->getStoreId() === Store::DEFAULT_STORE_ID) { $resultUrlKey = $category->formatUrlKey($category->getOrigData('name')); $this->updateUrlKey($category, $resultUrlKey); } diff --git a/app/code/Magento/CatalogUrlRewrite/Test/Unit/Observer/CategoryUrlPathAutogeneratorObserverTest.php b/app/code/Magento/CatalogUrlRewrite/Test/Unit/Observer/CategoryUrlPathAutogeneratorObserverTest.php index 0a570adab309a..9e2090e36f08e 100644 --- a/app/code/Magento/CatalogUrlRewrite/Test/Unit/Observer/CategoryUrlPathAutogeneratorObserverTest.php +++ b/app/code/Magento/CatalogUrlRewrite/Test/Unit/Observer/CategoryUrlPathAutogeneratorObserverTest.php @@ -159,6 +159,9 @@ public function testShouldThrowExceptionIfUrlKeyIsEmpty($useDefaultUrlKey, $isOb $this->expectExceptionMessage('Invalid URL key'); $categoryData = ['use_default' => ['url_key' => $useDefaultUrlKey], 'url_key' => '', 'url_path' => '']; $this->category->setData($categoryData); + $this->category + ->method('getStoreId') + ->willReturn(\Magento\Store\Model\Store::DEFAULT_STORE_ID); $this->category->isObjectNew($isObjectNew); $this->assertEquals($isObjectNew, $this->category->isObjectNew()); $this->assertEquals($categoryData['url_key'], $this->category->getUrlKey()); diff --git a/app/code/Magento/Customer/Test/Mftf/ActionGroup/AdminAssertDefaultValueDisableAutoGroupInCustomerFormActionGroup.xml b/app/code/Magento/Customer/Test/Mftf/ActionGroup/AdminAssertDefaultValueDisableAutoGroupInCustomerFormActionGroup.xml new file mode 100644 index 0000000000000..8271cdec46df9 --- /dev/null +++ b/app/code/Magento/Customer/Test/Mftf/ActionGroup/AdminAssertDefaultValueDisableAutoGroupInCustomerFormActionGroup.xml @@ -0,0 +1,26 @@ + + + + + + + + Check Default Value for Disable Automatic Group Changes Based on VAT ID in Create Customer form. + + + + + + + + {{isChecked}} + grabDisableAutomaticGroupChange + + + diff --git a/app/code/Magento/Customer/Test/Mftf/ActionGroup/AdminNavigateNewCustomerActionGroup.xml b/app/code/Magento/Customer/Test/Mftf/ActionGroup/AdminNavigateNewCustomerActionGroup.xml new file mode 100644 index 0000000000000..81c788fc4445a --- /dev/null +++ b/app/code/Magento/Customer/Test/Mftf/ActionGroup/AdminNavigateNewCustomerActionGroup.xml @@ -0,0 +1,19 @@ + + + + + + + Goes to the New Customer page. + + + + + + diff --git a/app/code/Magento/Customer/Test/Mftf/Section/AdminCustomerAccountInformationSection.xml b/app/code/Magento/Customer/Test/Mftf/Section/AdminCustomerAccountInformationSection.xml index 4b36486f0bd17..2c9e66c15bbab 100644 --- a/app/code/Magento/Customer/Test/Mftf/Section/AdminCustomerAccountInformationSection.xml +++ b/app/code/Magento/Customer/Test/Mftf/Section/AdminCustomerAccountInformationSection.xml @@ -17,6 +17,7 @@ + diff --git a/app/code/Magento/Customer/Test/Mftf/Test/AdminCheckDefaultValueDisableAutoGroupChangeIsNoTest.xml b/app/code/Magento/Customer/Test/Mftf/Test/AdminCheckDefaultValueDisableAutoGroupChangeIsNoTest.xml new file mode 100644 index 0000000000000..be96765920bf5 --- /dev/null +++ b/app/code/Magento/Customer/Test/Mftf/Test/AdminCheckDefaultValueDisableAutoGroupChangeIsNoTest.xml @@ -0,0 +1,36 @@ + + + + + + + + + + <description value="Check settings Default Value for Disable Automatic Group Changes Based on VAT ID is No"/> + <severity value="MAJOR"/> + <group value="customer"/> + <group value="create"/> + </annotations> + <before> + <magentoCLI command="config:set customer/create_account/viv_disable_auto_group_assign_default 0" stepKey="setConfigDefaultIsNo"/> + <magentoCLI command="cache:flush" stepKey="flushCache"/> + <actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin1"/> + </before> + <after> + <actionGroup ref="logout" stepKey="adminLogout"/> + </after> + + <actionGroup ref="AdminNavigateNewCustomerActionGroup" stepKey="navigateToNewCustomer"/> + + <actionGroup ref="AdminAssertDefaultValueDisableAutoGroupInCustomerFormActionGroup" stepKey="seeDefaultValueInForm"> + <argument name="isChecked" value="0"/> + </actionGroup> + </test> +</tests> diff --git a/app/code/Magento/Customer/Test/Mftf/Test/AdminCheckDefaultValueDisableAutoGroupChangeIsYesTest.xml b/app/code/Magento/Customer/Test/Mftf/Test/AdminCheckDefaultValueDisableAutoGroupChangeIsYesTest.xml new file mode 100644 index 0000000000000..87cba0c10dbc1 --- /dev/null +++ b/app/code/Magento/Customer/Test/Mftf/Test/AdminCheckDefaultValueDisableAutoGroupChangeIsYesTest.xml @@ -0,0 +1,38 @@ +<?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="AdminCheckDefaultValueDisableAutoGroupChangeIsYesTest"> + <annotations> + <features value="Customer"/> + <stories value="Default Value for Disable Automatic Group Changes Based on VAT ID"/> + <title value="Check settings Default Value for Disable Automatic Group Changes Based on VAT ID is Yes"/> + <description value="Check settings Default Value for Disable Automatic Group Changes Based on VAT ID is Yes"/> + <severity value="MAJOR"/> + <group value="customer"/> + <group value="create"/> + </annotations> + <before> + <magentoCLI command="config:set customer/create_account/viv_disable_auto_group_assign_default 1" stepKey="setConfigDefaultIsYes"/> + <magentoCLI command="cache:flush" stepKey="flushCache"/> + <actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin1"/> + </before> + <after> + <magentoCLI command="config:set customer/create_account/viv_disable_auto_group_assign_default 0" stepKey="setConfigDefaultIsNo"/> + <magentoCLI command="cache:flush" stepKey="flushCache"/> + <actionGroup ref="logout" stepKey="adminLogout"/> + </after> + + <actionGroup ref="AdminNavigateNewCustomerActionGroup" stepKey="navigateToNewCustomer"/> + + <actionGroup ref="AdminAssertDefaultValueDisableAutoGroupInCustomerFormActionGroup" stepKey="seeDefaultValueInForm"> + <argument name="isChecked" value="1"/> + </actionGroup> + </test> +</tests> diff --git a/app/code/Magento/Customer/Test/Mftf/Test/StorefrontUpdateCustomerAddressBelgiumTest.xml b/app/code/Magento/Customer/Test/Mftf/Test/StorefrontUpdateCustomerAddressBelgiumTest.xml index 6c0615f701df6..d36d640c5ad17 100644 --- a/app/code/Magento/Customer/Test/Mftf/Test/StorefrontUpdateCustomerAddressBelgiumTest.xml +++ b/app/code/Magento/Customer/Test/Mftf/Test/StorefrontUpdateCustomerAddressBelgiumTest.xml @@ -47,5 +47,13 @@ <actionGroup ref="VerifyCustomerShippingAddressWithState" stepKey="verifyShippingAddress"> <argument name="address" value="updateCustomerBelgiumAddress"/> </actionGroup> + + <!-- Verify country Belgium can be saved without state as state not required --> + <actionGroup ref="StoreFrontClickEditDefaultShippingAddressActionGroup" stepKey="clickOnDefaultShippingAddress"/> + <selectOption selector="{{StorefrontCustomerAddressFormSection.country}}" userInput="Belgium" stepKey="selectCountry"/> + <selectOption selector="{{StorefrontCustomerAddressFormSection.state}}" userInput="Please select a region, state or province." stepKey="selectState"/> + <actionGroup ref="AdminSaveCustomerAddressActionGroup" stepKey="saveAddress"/> + <see selector="{{StorefrontCustomerAddressesSection.defaultShippingAddress}}" userInput="Belgium" stepKey="seeAssertCustomerDefaultShippingAddressCountry"/> + </test> </tests> diff --git a/app/code/Magento/Customer/Ui/Component/Form/Field/DisableAutoGroupChange.php b/app/code/Magento/Customer/Ui/Component/Form/Field/DisableAutoGroupChange.php new file mode 100644 index 0000000000000..3404a0e92230c --- /dev/null +++ b/app/code/Magento/Customer/Ui/Component/Form/Field/DisableAutoGroupChange.php @@ -0,0 +1,70 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +declare(strict_types=1); + +namespace Magento\Customer\Ui\Component\Form\Field; + +use Magento\Framework\View\Element\UiComponent\ContextInterface; +use Magento\Framework\View\Element\UiComponentFactory; +use Magento\Framework\View\Element\UiComponentInterface; +use Magento\Customer\Helper\Address as AddressHelper; + +/** + * Process setting to set Default Value for Disable Automatic Group Changes Based on VAT ID + * + * Class \Magento\Customer\Ui\Component\Form\Field\DisableAutoGroupChange + */ +class DisableAutoGroupChange extends \Magento\Ui\Component\Form\Field +{ + /** + * Yes value for Default Value for Disable Automatic Group Changes Based on VAT ID + */ + const DISABLE_AUTO_GROUP_CHANGE_YES = '1'; + + /** + * Address Helper + * + * @var AddressHelper + */ + private $addressHelper; + + /** + * Constructor + * + * @param ContextInterface $context + * @param UiComponentFactory $uiComponentFactory + * @param AddressHelper $addressHelper + * @param UiComponentInterface[] $components + * @param array $data + */ + public function __construct( + ContextInterface $context, + UiComponentFactory $uiComponentFactory, + AddressHelper $addressHelper, + array $components = [], + array $data = [] + ) { + $this->addressHelper = $addressHelper; + parent::__construct($context, $uiComponentFactory, $components, $data); + } + + /** + * Prepare component configuration + * + * @return void + * @throws \Magento\Framework\Exception\LocalizedException + */ + public function prepare() + { + parent::prepare(); + + if ($this->addressHelper->isDisableAutoGroupAssignDefaultValue()) { + $currentConfig = $this->getData('config'); + $currentConfig['default'] = self::DISABLE_AUTO_GROUP_CHANGE_YES; + $this->setData('config', $currentConfig); + } + } +} diff --git a/app/code/Magento/Customer/view/base/ui_component/customer_form.xml b/app/code/Magento/Customer/view/base/ui_component/customer_form.xml index 954b44ec19bbb..14e5abec58b08 100644 --- a/app/code/Magento/Customer/view/base/ui_component/customer_form.xml +++ b/app/code/Magento/Customer/view/base/ui_component/customer_form.xml @@ -169,7 +169,7 @@ <dataType>number</dataType> </settings> </field> - <field name="disable_auto_group_change" formElement="checkbox"> + <field name="disable_auto_group_change" formElement="checkbox" class="Magento\Customer\Ui\Component\Form\Field\DisableAutoGroupChange"> <argument name="data" xsi:type="array"> <item name="config" xsi:type="array"> <item name="fieldGroup" xsi:type="string">group_id</item> diff --git a/app/code/Magento/Directory/etc/di.xml b/app/code/Magento/Directory/etc/di.xml index 50cd65cc5045c..fb2c526ac730b 100644 --- a/app/code/Magento/Directory/etc/di.xml +++ b/app/code/Magento/Directory/etc/di.xml @@ -35,6 +35,7 @@ <item name="DE" xsi:type="string">DE</item> <item name="AT" xsi:type="string">AT</item> <item name="FI" xsi:type="string">FI</item> + <item name="BE" xsi:type="string">BE</item> </argument> </arguments> </type> diff --git a/app/code/Magento/Review/Block/Adminhtml/Rating/Edit/Tab/Form.php b/app/code/Magento/Review/Block/Adminhtml/Rating/Edit/Tab/Form.php index e4b4da23ac629..a8a39b3326edd 100644 --- a/app/code/Magento/Review/Block/Adminhtml/Rating/Edit/Tab/Form.php +++ b/app/code/Magento/Review/Block/Adminhtml/Rating/Edit/Tab/Form.php @@ -111,13 +111,16 @@ protected function addRatingFieldset() ] ); - foreach ($this->systemStore->getStoreCollection() as $store) { - $this->getFieldset('rating_form')->addField( - 'rating_code_' . $store->getId(), - 'text', - ['label' => $store->getName(), 'name' => 'rating_codes[' . $store->getId() . ']'] - ); + if (!$this->_storeManager->isSingleStoreMode()) { + foreach ($this->systemStore->getStoreCollection() as $store) { + $this->getFieldset('rating_form')->addField( + 'rating_code_' . $store->getId(), + 'text', + ['label' => $store->getName(), 'name' => 'rating_codes[' . $store->getId() . ']'] + ); + } } + $this->setRatingData(); } diff --git a/app/code/Magento/Review/Test/Mftf/ActionGroup/AdminAssertStoreViewRatingTitleWhenSingleStoreModeIsNoActionGroup.xml b/app/code/Magento/Review/Test/Mftf/ActionGroup/AdminAssertStoreViewRatingTitleWhenSingleStoreModeIsNoActionGroup.xml new file mode 100644 index 0000000000000..05fad32dabe51 --- /dev/null +++ b/app/code/Magento/Review/Test/Mftf/ActionGroup/AdminAssertStoreViewRatingTitleWhenSingleStoreModeIsNoActionGroup.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + /** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +--> +<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd"> + <actionGroup name="AdminAssertStoreViewRatingTitleWhenSingleStoreModeIsNoActionGroup"> + <annotations> + <description>If Single Store Mode is disabled, default store view title label should be displayed.</description> + </annotations> + <seeElement selector="{{AdminEditAndNewRatingSection.defaultStoreViewTitleLabel}}" stepKey="seeLabel"/> + <seeElement selector="{{AdminEditAndNewRatingSection.defaultStoreViewTitleInput}}" stepKey="seeInput"/> + </actionGroup> +</actionGroups> diff --git a/app/code/Magento/Review/Test/Mftf/ActionGroup/AdminAssertStoreViewRatingTitleWhenSingleStoreModeIsYesActionGroup.xml b/app/code/Magento/Review/Test/Mftf/ActionGroup/AdminAssertStoreViewRatingTitleWhenSingleStoreModeIsYesActionGroup.xml new file mode 100644 index 0000000000000..6e5586bfa1252 --- /dev/null +++ b/app/code/Magento/Review/Test/Mftf/ActionGroup/AdminAssertStoreViewRatingTitleWhenSingleStoreModeIsYesActionGroup.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + /** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +--> +<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd"> + <actionGroup name="AdminAssertStoreViewRatingTitleWhenSingleStoreModeIsYesActionGroup"> + <annotations> + <description>If Single Store Mode is enabled, default store view title label should not be displayed.</description> + </annotations> + <dontSeeElement selector="{{AdminEditAndNewRatingSection.defaultStoreViewTitleLabel}}" stepKey="dontSeeLabel"/> + <dontSeeElement selector="{{AdminEditAndNewRatingSection.defaultStoreViewTitleInput}}" stepKey="dontSeeInput"/> + </actionGroup> +</actionGroups> diff --git a/app/code/Magento/Review/Test/Mftf/ActionGroup/AdminNavigateToNewRatingFormActionGroup.xml b/app/code/Magento/Review/Test/Mftf/ActionGroup/AdminNavigateToNewRatingFormActionGroup.xml new file mode 100644 index 0000000000000..3659405c52b69 --- /dev/null +++ b/app/code/Magento/Review/Test/Mftf/ActionGroup/AdminNavigateToNewRatingFormActionGroup.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + /** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +--> +<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd"> + <actionGroup name="AdminNavigateToNewRatingFormActionGroup"> + <annotations> + <description>Open New Rating Form</description> + </annotations> + <amOnPage url="{{AdminNewRatingPage.url}}" stepKey="amOnUrlNewRatingPage"/> + <waitForPageLoad stepKey="waitForNewRatingPage"/> + </actionGroup> +</actionGroups> diff --git a/app/code/Magento/Review/Test/Mftf/Page/AdminNewRatingPage.xml b/app/code/Magento/Review/Test/Mftf/Page/AdminNewRatingPage.xml new file mode 100644 index 0000000000000..8dfc2182e228c --- /dev/null +++ b/app/code/Magento/Review/Test/Mftf/Page/AdminNewRatingPage.xml @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + /** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +--> + +<pages xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/PageObject.xsd"> + <page name="AdminNewRatingPage" url="review/rating/new/" area="admin" module="Review"> + <section name="AdminEditAndNewRatingSection"/> + </page> +</pages> diff --git a/app/code/Magento/Review/Test/Mftf/Section/AdminEditAndNewRatingSection.xml b/app/code/Magento/Review/Test/Mftf/Section/AdminEditAndNewRatingSection.xml new file mode 100644 index 0000000000000..59dd3d2004790 --- /dev/null +++ b/app/code/Magento/Review/Test/Mftf/Section/AdminEditAndNewRatingSection.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + /** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +--> + +<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd"> + <section name="AdminEditAndNewRatingSection"> + <element name="defaultStoreViewTitleLabel" type="text" selector=".field-rating_code_1 label"/> + <element name="defaultStoreViewTitleInput" type="input" selector=".field-rating_code_1 input"/> + </section> +</sections> diff --git a/app/code/Magento/Review/Test/Mftf/Test/AdminVerifyNewRatingFormSingleStoreModeNoTest.xml b/app/code/Magento/Review/Test/Mftf/Test/AdminVerifyNewRatingFormSingleStoreModeNoTest.xml new file mode 100644 index 0000000000000..77789dd172bdd --- /dev/null +++ b/app/code/Magento/Review/Test/Mftf/Test/AdminVerifyNewRatingFormSingleStoreModeNoTest.xml @@ -0,0 +1,31 @@ +<?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="AdminVerifyNewRatingFormSingleStoreModeNoTest"> + <annotations> + <features value="Review"/> + <stories value="Rating Form"/> + <title value="Verify New Rating Form if single store mode is No"/> + <description value="New Rating Form should have Default store view field if single store mode is No"/> + <severity value="MAJOR"/> + <testCaseId value="MC-21818"/> + <group value="review"/> + </annotations> + <before> + <magentoCLI command="config:set general/single_store_mode/enabled 0" stepKey="enabledSingleStoreMode"/> + <actionGroup ref="LoginAsAdmin" stepKey="LoginAsAdmin"/> + </before> + <after> + <actionGroup ref="logout" stepKey="logout"/> + </after> + <actionGroup ref="AdminNavigateToNewRatingFormActionGroup" stepKey="navigateToNewRatingPage" /> + <actionGroup ref="AdminAssertStoreViewRatingTitleWhenSingleStoreModeIsNoActionGroup" stepKey="verifyForm" /> + </test> +</tests> diff --git a/app/code/Magento/Review/Test/Mftf/Test/AdminVerifyNewRatingFormSingleStoreModeYesTest.xml b/app/code/Magento/Review/Test/Mftf/Test/AdminVerifyNewRatingFormSingleStoreModeYesTest.xml new file mode 100644 index 0000000000000..e5368e9192c98 --- /dev/null +++ b/app/code/Magento/Review/Test/Mftf/Test/AdminVerifyNewRatingFormSingleStoreModeYesTest.xml @@ -0,0 +1,32 @@ +<?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="AdminVerifyNewRatingFormSingleStoreModeYesTest"> + <annotations> + <features value="Review"/> + <stories value="Rating Form"/> + <title value="Verify New Rating Form if single store mode is Yes"/> + <description value="New Rating Form should not have Default store view field if single store mode is Yes"/> + <severity value="MAJOR"/> + <testCaseId value="MC-21818"/> + <group value="review"/> + </annotations> + <before> + <magentoCLI command="config:set general/single_store_mode/enabled 1" stepKey="enabledSingleStoreMode"/> + <actionGroup ref="LoginAsAdmin" stepKey="LoginAsAdmin"/> + </before> + <after> + <magentoCLI command="config:set general/single_store_mode/enabled 0" stepKey="enabledSingleStoreMode"/> + <actionGroup ref="logout" stepKey="logout"/> + </after> + <actionGroup ref="AdminNavigateToNewRatingFormActionGroup" stepKey="navigateToNewRatingPage" /> + <actionGroup ref="AdminAssertStoreViewRatingTitleWhenSingleStoreModeIsYesActionGroup" stepKey="verifyForm" /> + </test> +</tests> diff --git a/app/code/Magento/Swatches/Test/Unit/Block/Adminhtml/Attribute/Edit/Options/TextTest.php b/app/code/Magento/Swatches/Test/Unit/Block/Adminhtml/Attribute/Edit/Options/TextTest.php new file mode 100644 index 0000000000000..e72ebdd4507f4 --- /dev/null +++ b/app/code/Magento/Swatches/Test/Unit/Block/Adminhtml/Attribute/Edit/Options/TextTest.php @@ -0,0 +1,93 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +declare(strict_types=1); + +namespace Magento\Swatches\Test\Unit\Block\Adminhtml\Attribute\Edit\Options; + +use Magento\Swatches\Block\Adminhtml\Attribute\Edit\Options\Text; + +/** + * Class \Magento\Swatches\Test\Unit\Block\Adminhtml\Attribute\Edit\Options\TextTest + */ +class TextTest extends \PHPUnit\Framework\TestCase +{ + /** + * @var \PHPUnit_Framework_MockObject_MockObject|Text + */ + private $model; + + /** + * Setup environment for test + */ + protected function setUp() + { + $this->model = $this->getMockBuilder(Text::class) + ->disableOriginalConstructor() + ->setMethods(['getReadOnly', 'canManageOptionDefaultOnly', 'getOptionValues']) + ->getMock(); + } + + /** + * Test getJsonConfig with getReadOnly() is true and canManageOptionDefaultOnly() is false + */ + public function testGetJsonConfigDataSet1() + { + $testCase1 = [ + 'dataSet' => [ + 'read_only' => true, + 'can_manage_option_default_only' => false, + 'option_values' => [ + new \Magento\Framework\DataObject(['value' => 6, 'label' => 'red']), + new \Magento\Framework\DataObject(['value' => 6, 'label' => 'blue']), + ] + ], + 'expectedResult' => '{"attributesData":[{"value":6,"label":"red"},{"value":6,"label":"blue"}],' . + '"isSortable":0,"isReadOnly":1}' + + ]; + + $this->executeTest($testCase1); + } + + /** + * Test getJsonConfig with getReadOnly() is false and canManageOptionDefaultOnly() is false + */ + public function testGetJsonConfigDataSet2() + { + $testCase2 = [ + 'dataSet' => [ + 'read_only' => false, + 'can_manage_option_default_only' => false, + 'option_values' => [ + new \Magento\Framework\DataObject(['value' => 6, 'label' => 'red']), + new \Magento\Framework\DataObject(['value' => 6, 'label' => 'blue']), + ] + ], + 'expectedResult' => '{"attributesData":[{"value":6,"label":"red"},{"value":6,"label":"blue"}],' . + '"isSortable":1,"isReadOnly":0}' + + ]; + + $this->executeTest($testCase2); + } + + /** + * Execute test for getJsonConfig() function + */ + public function executeTest($testCase) + { + $this->model->expects($this->any())->method('getReadOnly') + ->willReturn($testCase['dataSet']['read_only']); + $this->model->expects($this->any())->method('canManageOptionDefaultOnly') + ->willReturn($testCase['dataSet']['can_manage_option_default_only']); + $this->model->expects($this->any())->method('getOptionValues')->willReturn( + $testCase['dataSet']['option_values'] + ); + + $this->assertEquals($testCase['expectedResult'], $this->model->getJsonConfig()); + } +} diff --git a/app/code/Magento/Swatches/Test/Unit/Block/Adminhtml/Attribute/Edit/Options/VisualTest.php b/app/code/Magento/Swatches/Test/Unit/Block/Adminhtml/Attribute/Edit/Options/VisualTest.php new file mode 100644 index 0000000000000..f78fedea6afb7 --- /dev/null +++ b/app/code/Magento/Swatches/Test/Unit/Block/Adminhtml/Attribute/Edit/Options/VisualTest.php @@ -0,0 +1,96 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +declare(strict_types=1); + +namespace Magento\Swatches\Test\Unit\Block\Adminhtml\Attribute\Edit\Options; + +use Magento\Swatches\Block\Adminhtml\Attribute\Edit\Options\Visual; + +/** + * Class \Magento\Swatches\Test\Unit\Block\Adminhtml\Attribute\Edit\Options\VisualTest + */ +class VisualTest extends \PHPUnit\Framework\TestCase +{ + /** + * @var \PHPUnit_Framework_MockObject_MockObject|Visual + */ + private $model; + + /** + * Setup environment for test + */ + protected function setUp() + { + $this->model = $this->getMockBuilder(Visual::class) + ->disableOriginalConstructor() + ->setMethods(['getReadOnly', 'canManageOptionDefaultOnly', 'getOptionValues', 'getUrl']) + ->getMock(); + } + + /** + * Test getJsonConfig with getReadOnly() is true and canManageOptionDefaultOnly() is false + */ + public function testGetJsonConfigDataSet1() + { + $testCase1 = [ + 'dataSet' => [ + 'read_only' => true, + 'can_manage_option_default_only' => false, + 'upload_action_url' => 'http://magento.com/admin/swatches/iframe/show', + 'option_values' => [ + new \Magento\Framework\DataObject(['value' => 6, 'label' => 'red']), + new \Magento\Framework\DataObject(['value' => 6, 'label' => 'blue']), + ] + ], + 'expectedResult' => '{"attributesData":[{"value":6,"label":"red"},{"value":6,"label":"blue"}],' . + '"uploadActionUrl":"http:\/\/magento.com\/admin\/swatches\/iframe\/show","isSortable":0,"isReadOnly":1}' + + ]; + + $this->executeTest($testCase1); + } + + /** + * Test getJsonConfig with getReadOnly() is false and canManageOptionDefaultOnly() is false + */ + public function testGetJsonConfigDataSet2() + { + $testCase1 = [ + 'dataSet' => [ + 'read_only' => false, + 'can_manage_option_default_only' => false, + 'upload_action_url' => 'http://magento.com/admin/swatches/iframe/show', + 'option_values' => [ + new \Magento\Framework\DataObject(['value' => 6, 'label' => 'red']), + new \Magento\Framework\DataObject(['value' => 6, 'label' => 'blue']), + ] + ], + 'expectedResult' => '{"attributesData":[{"value":6,"label":"red"},{"value":6,"label":"blue"}],' . + '"uploadActionUrl":"http:\/\/magento.com\/admin\/swatches\/iframe\/show","isSortable":1,"isReadOnly":0}' + ]; + + $this->executeTest($testCase1); + } + + /** + * Execute test for getJsonConfig() function + */ + public function executeTest($testCase) + { + $this->model->expects($this->any())->method('getReadOnly') + ->willReturn($testCase['dataSet']['read_only']); + $this->model->expects($this->any())->method('canManageOptionDefaultOnly') + ->willReturn($testCase['dataSet']['can_manage_option_default_only']); + $this->model->expects($this->any())->method('getOptionValues')->willReturn( + $testCase['dataSet']['option_values'] + ); + $this->model->expects($this->any())->method('getUrl') + ->willReturn($testCase['dataSet']['upload_action_url']); + + $this->assertEquals($testCase['expectedResult'], $this->model->getJsonConfig()); + } +} diff --git a/app/code/Magento/User/Model/Backend/Config/ObserverConfig.php b/app/code/Magento/User/Model/Backend/Config/ObserverConfig.php index 6d921dfdcdd65..93b5389bc3608 100644 --- a/app/code/Magento/User/Model/Backend/Config/ObserverConfig.php +++ b/app/code/Magento/User/Model/Backend/Config/ObserverConfig.php @@ -4,13 +4,37 @@ * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\User\Model\Backend\Config; /** * User backend observer helper class + * + * Class \Magento\User\Model\Backend\Config\ObserverConfig */ class ObserverConfig { + /** + * Config path for lockout threshold + */ + private const XML_ADMIN_SECURITY_LOCKOUT_THRESHOLD = 'admin/security/lockout_threshold'; + + /** + * Config path for password change is forced or not + */ + private const XML_ADMIN_SECURITY_PASSWORD_IS_FORCED = 'admin/security/password_is_forced'; + + /** + * Config path for password lifetime + */ + private const XML_ADMIN_SECURITY_PASSWORD_LIFETIME = 'admin/security/password_lifetime'; + + /** + * Config path for maximum lockout failures + */ + private const XML_ADMIN_SECURITY_LOCKOUT_FAILURES = 'admin/security/lockout_failures'; + /** * Backend configuration interface * @@ -19,6 +43,8 @@ class ObserverConfig protected $backendConfig; /** + * Constructor + * * @param \Magento\Backend\App\ConfigInterface $backendConfig */ public function __construct( @@ -44,11 +70,12 @@ public function _isLatestPasswordExpired($latestPassword) /** * Get admin lock threshold from configuration + * * @return int */ public function getAdminLockThreshold() { - return 60 * (int)$this->backendConfig->getValue('admin/security/lockout_threshold'); + return 60 * (int)$this->backendConfig->getValue(self::XML_ADMIN_SECURITY_LOCKOUT_THRESHOLD); } /** @@ -58,7 +85,7 @@ public function getAdminLockThreshold() */ public function isPasswordChangeForced() { - return (bool)(int)$this->backendConfig->getValue('admin/security/password_is_forced'); + return (bool)(int)$this->backendConfig->getValue(self::XML_ADMIN_SECURITY_PASSWORD_IS_FORCED); } /** @@ -68,7 +95,7 @@ public function isPasswordChangeForced() */ public function getAdminPasswordLifetime() { - return 86400 * (int)$this->backendConfig->getValue('admin/security/password_lifetime'); + return 86400 * (int)$this->backendConfig->getValue(self::XML_ADMIN_SECURITY_PASSWORD_LIFETIME); } /** @@ -78,6 +105,6 @@ public function getAdminPasswordLifetime() */ public function getMaxFailures() { - return (int)$this->backendConfig->getValue('admin/security/lockout_failures'); + return (int)$this->backendConfig->getValue(self::XML_ADMIN_SECURITY_LOCKOUT_FAILURES); } } diff --git a/app/code/Magento/User/Test/Unit/Model/Backend/Config/ObserverConfigTest.php b/app/code/Magento/User/Test/Unit/Model/Backend/Config/ObserverConfigTest.php new file mode 100644 index 0000000000000..395c45bc676a8 --- /dev/null +++ b/app/code/Magento/User/Test/Unit/Model/Backend/Config/ObserverConfigTest.php @@ -0,0 +1,142 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +declare(strict_types=1); + +namespace Magento\User\Test\Unit\Model\Backend\Config; + +use Magento\User\Model\Backend\Config\ObserverConfig; +use Magento\Backend\App\ConfigInterface; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; + +/** + * Unit Test for \Magento\User\Model\Backend\Config\ObserverConfig class + * + * Class \Magento\User\Test\Unit\Model\Backend\Config\ObserverConfigTest + */ +class ObserverConfigTest extends \PHPUnit\Framework\TestCase +{ + /** + * Config path for lockout threshold + */ + private const XML_ADMIN_SECURITY_LOCKOUT_THRESHOLD = 'admin/security/lockout_threshold'; + + /** + * Config path for password change is forced or not + */ + private const XML_ADMIN_SECURITY_PASSWORD_IS_FORCED = 'admin/security/password_is_forced'; + + /** + * Config path for password lifetime + */ + private const XML_ADMIN_SECURITY_PASSWORD_LIFETIME = 'admin/security/password_lifetime'; + + /** + * Config path for maximum lockout failures + */ + private const XML_ADMIN_SECURITY_LOCKOUT_FAILURES = 'admin/security/lockout_failures'; + + /** @var ObserverConfig */ + private $model; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject|ConfigInterface + */ + private $backendConfigMock; + + /** + * Set environment for test + */ + protected function setUp() + { + $this->backendConfigMock = $this->createMock(ConfigInterface::class); + + $objectManager = new ObjectManagerHelper($this); + $this->model = $objectManager->getObject( + ObserverConfig::class, + [ + 'backendConfig' => $this->backendConfigMock + ] + ); + } + + /** + * Test when admin password lifetime = 0 days + */ + public function testIsLatestPasswordExpiredWhenNoAdminLifeTime() + { + $this->backendConfigMock->expects(self::any())->method('getValue') + ->with(self::XML_ADMIN_SECURITY_PASSWORD_LIFETIME) + ->willReturn('0'); + $this->assertEquals(false, $this->model->_isLatestPasswordExpired([])); + } + + /** + * Test when admin password lifetime = 2 days + */ + public function testIsLatestPasswordExpiredWhenHasAdminLifeTime() + { + $this->backendConfigMock->expects(self::any())->method('getValue') + ->with(self::XML_ADMIN_SECURITY_PASSWORD_LIFETIME) + ->willReturn('2'); + $this->assertEquals(true, $this->model->_isLatestPasswordExpired(['last_updated' => 1571428052])); + } + + /** + * Test when security lockout threshold = 100 minutes + */ + public function testGetAdminLockThreshold() + { + $this->backendConfigMock->expects(self::any())->method('getValue') + ->with(self::XML_ADMIN_SECURITY_LOCKOUT_THRESHOLD) + ->willReturn('100'); + $this->assertEquals(6000, $this->model->getAdminLockThreshold()); + } + + /** + * Test when password change force is true + */ + public function testIsPasswordChangeForcedTrue() + { + $this->backendConfigMock->expects(self::any())->method('getValue') + ->with(self::XML_ADMIN_SECURITY_PASSWORD_IS_FORCED) + ->willReturn('1'); + $this->assertEquals(true, $this->model->isPasswordChangeForced()); + } + + /** + * Test when password change force is false + */ + public function testIsPasswordChangeForcedFalse() + { + $this->backendConfigMock->expects(self::any())->method('getValue') + ->with(self::XML_ADMIN_SECURITY_PASSWORD_IS_FORCED) + ->willReturn('0'); + $this->assertEquals(false, $this->model->isPasswordChangeForced()); + } + + /** + * Test when admin password lifetime = 2 days + */ + public function testGetAdminPasswordLifetime() + { + $this->backendConfigMock->expects(self::any())->method('getValue') + ->with(self::XML_ADMIN_SECURITY_PASSWORD_LIFETIME) + ->willReturn('2'); + $this->assertEquals(172800, $this->model->getAdminPasswordLifetime()); + } + + /** + * Test when max failures = 5 (times) + */ + public function testGetMaxFailures() + { + $this->backendConfigMock->expects(self::any())->method('getValue') + ->with(self::XML_ADMIN_SECURITY_LOCKOUT_FAILURES) + ->willReturn('5'); + $this->assertEquals(5, $this->model->getMaxFailures()); + } +} diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/CategoryTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/CategoryTest.php index c0eeb75592a5d..2f7a90caa11f9 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/CategoryTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/CategoryTest.php @@ -15,8 +15,8 @@ use Magento\Framework\Message\MessageInterface; use Magento\Framework\Serialize\Serializer\Json; use Magento\Store\Api\StoreRepositoryInterface; -use Magento\TestFramework\TestCase\AbstractBackendController; use Magento\TestFramework\Helper\Bootstrap; +use Magento\TestFramework\TestCase\AbstractBackendController; /** * Test for category backend actions @@ -63,6 +63,7 @@ protected function setUp() * @param array $defaultAttributes * @param array $attributesSaved * @return void + * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function testSaveAction(array $inputData, array $defaultAttributes, array $attributesSaved = []): void { @@ -107,6 +108,8 @@ public function testSaveAction(array $inputData, array $defaultAttributes, array * @magentoDbIsolation enabled * @magentoDataFixture Magento/CatalogUrlRewrite/_files/categories.php * @return void + * @throws \Magento\Framework\Exception\CouldNotSaveException + * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function testDefaultValueForCategoryUrlPath(): void { @@ -125,11 +128,12 @@ public function testDefaultValueForCategoryUrlPath(): void // set default url_path and check it $this->getRequest()->setMethod(HttpRequest::METHOD_POST); $postData = $category->getData(); - $postData['use_default'] = [ - 'available_sort_by' => 1, - 'default_sort_by' => 1, - 'url_key' => 1, - ]; + $postData['use_default'] = + [ + 'available_sort_by' => 1, + 'default_sort_by' => 1, + 'url_key' => 1, + ]; $this->getRequest()->setPostValue($postData); $this->dispatch('backend/catalog/category/save'); $this->assertSessionMessages( @@ -137,7 +141,7 @@ public function testDefaultValueForCategoryUrlPath(): void MessageInterface::TYPE_SUCCESS ); $category = $this->categoryRepository->get($categoryId); - $this->assertEquals($defaultUrlPath, $category->getData('url_path')); + $this->assertEquals($defaultUrlPath, $category->getData('url_key')); } /**