Skip to content

Commit 74a92ae

Browse files
Merge remote-tracking branch 'remotes/github/MAGETWO-91559' into EPAM-PR-36
2 parents 543e1ee + 28741de commit 74a92ae

File tree

4 files changed

+99
-7
lines changed

4 files changed

+99
-7
lines changed

app/code/Magento/Cms/Model/ResourceModel/Block.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,11 @@ protected function _beforeSave(AbstractModel $object)
9595
}
9696

9797
/**
98+
* Get block id.
99+
*
98100
* @param AbstractModel $object
99101
* @param mixed $value
100-
* @param null $field
102+
* @param string $field
101103
* @return bool|int|string
102104
* @throws LocalizedException
103105
* @throws \Exception
@@ -183,10 +185,12 @@ public function getIsUniqueBlockToStores(AbstractModel $object)
183185
$entityMetadata = $this->metadataPool->getMetadata(BlockInterface::class);
184186
$linkField = $entityMetadata->getLinkField();
185187

186-
if ($this->_storeManager->isSingleStoreMode()) {
187-
$stores = [Store::DEFAULT_STORE_ID];
188-
} else {
189-
$stores = (array)$object->getData('store_id');
188+
$stores = (array)$object->getData('store_id');
189+
$isDefaultStore = $this->_storeManager->isSingleStoreMode()
190+
|| array_search(Store::DEFAULT_STORE_ID, $stores) !== false;
191+
192+
if (!$isDefaultStore) {
193+
$stores[] = Store::DEFAULT_STORE_ID;
190194
}
191195

192196
$select = $this->getConnection()->select()
@@ -196,8 +200,11 @@ public function getIsUniqueBlockToStores(AbstractModel $object)
196200
'cb.' . $linkField . ' = cbs.' . $linkField,
197201
[]
198202
)
199-
->where('cb.identifier = ?', $object->getData('identifier'))
200-
->where('cbs.store_id IN (?)', $stores);
203+
->where('cb.identifier = ? ', $object->getData('identifier'));
204+
205+
if (!$isDefaultStore) {
206+
$select->where('cbs.store_id IN (?)', $stores);
207+
}
201208

202209
if ($object->getId()) {
203210
$select->where('cb.' . $entityMetadata->getIdentifierField() . ' <> ?', $object->getId());
@@ -236,6 +243,8 @@ public function lookupStoreIds($id)
236243
}
237244

238245
/**
246+
* Save an object.
247+
*
239248
* @param AbstractModel $object
240249
* @return $this
241250
* @throws \Exception

app/code/Magento/Cms/Test/Mftf/ActionGroup/CMSActionGroup.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@
4444
<waitForPageLoad stepKey="waitForPageLoad3"/>
4545
<waitForLoadingMaskToDisappear stepKey="waitForLoadingMaskOfStagingSection" />
4646
</actionGroup>
47+
<actionGroup name="DeleteCMSBlockActionGroup">
48+
<amOnPage url="{{CmsBlocksPage.url}}" stepKey="navigateToCMSPagesGrid"/>
49+
<waitForPageLoad stepKey="waitForPageLoad"/>
50+
<click selector="{{CmsPagesPageActionsSection.select(_defaultBlock.title)}}" stepKey="ClickOnSelect"/>
51+
<click selector="{{CmsPagesPageActionsSection.delete(_defaultBlock.title)}}" stepKey="ClickOnEdit"/>
52+
<waitForPageLoad stepKey="waitForPageLoad3"/>
53+
<click selector="{{CmsPagesPageActionsSection.deleteConfirm}}" stepKey="ClickToConfirm"/>
54+
<waitForPageLoad stepKey="waitForPageLoad4"/>
55+
<see userInput="You deleted the block." stepKey="VerifyBlockIsDeleted"/>
56+
</actionGroup>
4757

4858
<actionGroup name="AddStoreViewToCmsPage" extends="navigateToCreatedCMSPage">
4959
<arguments>

app/code/Magento/Cms/Test/Mftf/Section/CmsNewBlockBlockActionsSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<element name="saveAndDuplicate" type="button" selector="#save_and_duplicate" timeout="10"/>
1818
<element name="saveAndClose" type="button" selector="#save_and_close" timeout="10"/>
1919
<element name="expandSplitButton" type="button" selector="//button[@data-ui-id='save-button-dropdown']" timeout="10"/>
20+
<element name="back" type="button" selector="#back"/>
2021
</section>
2122
<section name="BlockWYSIWYGSection">
2223
<element name="ShowHideBtn" type="button" selector="#togglecms_block_form_content"/>
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="CheckStaticBlocksTest">
12+
<annotations>
13+
<features value="Cms"/>
14+
<stories value="MAGETWO-91559 - Static blocks with same ID appear in place of correct block"/>
15+
<title value="Check static blocks: ID should be unique per Store View"/>
16+
<description value="Check static blocks: ID should be unique per Store View"/>
17+
<severity value="CRITICAL"/>
18+
<testCaseId value="MAGETWO-94229"/>
19+
<group value="Cms"/>
20+
</annotations>
21+
<before>
22+
<actionGroup ref="LoginAsAdmin" stepKey="LoginAsAdmin"/>
23+
<actionGroup ref="AdminCreateWebsiteActionGroup" stepKey="AdminCreateWebsite">
24+
<argument name="newWebsiteName" value="secondWebsite"/>
25+
<argument name="websiteCode" value="second_website"/>
26+
</actionGroup>
27+
<actionGroup ref="AdminCreateNewStoreGroupActionGroup" stepKey="AdminCreateStore">
28+
<argument name="website" value="secondWebsite"/>
29+
<argument name="storeGroupName" value="{{customStoreGroup.name}}"/>
30+
<argument name="storeGroupCode" value="{{customStoreGroup.code}}"/>
31+
</actionGroup>
32+
<actionGroup ref="AdminCreateStoreViewActionGroup" stepKey="AdminCreateStoreView">
33+
<argument name="StoreGroup" value="customStoreGroup"/>
34+
<argument name="customStore" value="customStore"/>
35+
</actionGroup>
36+
</before>
37+
38+
<!--Go to Cms blocks page-->
39+
<amOnPage url="{{CmsBlocksPage.url}}" stepKey="navigateToCMSPagesGrid"/>
40+
<waitForPageLoad stepKey="waitForPageLoad1"/>
41+
<seeInCurrentUrl url="cms/block/" stepKey="VerifyPageIsOpened"/>
42+
<!--Click to create new block-->
43+
<click selector="{{BlockPageActionsSection.addNewBlock}}" stepKey="ClickToAddNewBlock"/>
44+
<waitForPageLoad stepKey="waitForPageLoad2"/>
45+
<seeInCurrentUrl url="cms/block/new" stepKey="VerifyNewBlockPageIsOpened"/>
46+
<actionGroup ref="FillOutBlockContent" stepKey="FillOutBlockContent"/>
47+
<click selector="{{BlockNewPagePageActionsSection.saveBlock}}" stepKey="ClickToSaveBlock"/>
48+
<waitForPageLoad stepKey="waitForPageLoad3"/>
49+
<see userInput="You saved the block." stepKey="VerifyBlockIsSaved"/>
50+
<!--Click to go back and add new block-->
51+
<click selector="{{BlockNewPagePageActionsSection.back}}" stepKey="ClickToGoBack"/>
52+
<waitForPageLoad stepKey="waitForPageLoad4"/>
53+
<click selector="{{BlockPageActionsSection.addNewBlock}}" stepKey="ClickToAddNewBlock1"/>
54+
<waitForPageLoad stepKey="waitForPageLoad5"/>
55+
<seeInCurrentUrl url="cms/block/new" stepKey="VerifyNewBlockPageIsOpened1"/>
56+
<!--Add new BLock with the same data-->
57+
<actionGroup ref="FillOutBlockContent" stepKey="FillOutBlockContent1"/>
58+
<selectOption selector="{{BlockNewPageBasicFieldsSection.storeView}}" userInput="Default Store View" stepKey="selectDefaultStoreView" />
59+
<selectOption selector="{{BlockNewPageBasicFieldsSection.storeView}}" userInput="{{customStore.name}}" stepKey="selectSecondStoreView1" />
60+
<click selector="{{BlockNewPagePageActionsSection.saveBlock}}" stepKey="ClickToSaveBlock1"/>
61+
<waitForPageLoad stepKey="waitForPageLoad6"/>
62+
<!--Verify that corresponding message is displayed-->
63+
<see userInput="A block identifier with the same properties already exists in the selected store." stepKey="VerifyBlockIsSaved1"/>
64+
65+
<after>
66+
<actionGroup ref="AdminDeleteWebsiteActionGroup" stepKey="DeleteWebsite">
67+
<argument name="websiteName" value="secondWebsite"/>
68+
</actionGroup>
69+
<actionGroup ref="DeleteCMSBlockActionGroup" stepKey="DeleteCMSBlockActionGroup"/>
70+
</after>
71+
</test>
72+
</tests>

0 commit comments

Comments
 (0)