Skip to content

Commit 81ab4fb

Browse files
committed
MC-40832: Create automated test for: "Verify that customer attribute label is displayed according saved values for each store view"
1 parent 2e2af0a commit 81ab4fb

File tree

3 files changed

+77
-1
lines changed

3 files changed

+77
-1
lines changed

dev/tests/integration/testsuite/Magento/Customer/Block/Address/EditTest.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@
1616
use Magento\Framework\View\Result\PageFactory;
1717
use Magento\TestFramework\Helper\Bootstrap;
1818
use Magento\TestFramework\Helper\Xpath;
19+
use Magento\TestFramework\Store\ExecuteInStoreContext;
1920
use PHPUnit\Framework\TestCase;
2021

2122
/**
2223
* Tests Address Edit Block
2324
*
2425
* @magentoAppArea frontend
2526
* @magentoAppIsolation enabled
27+
*
28+
* @magentoDataFixture Magento/Customer/_files/customer.php
2629
*/
2730
class EditTest extends TestCase
2831
{
@@ -41,9 +44,12 @@ class EditTest extends TestCase
4144
/** @var CustomerRegistry */
4245
private $customerRegistry;
4346

44-
/** @var RequestInterface */
47+
/** @var RequestInterface */
4548
private $request;
4649

50+
/** @var ExecuteInStoreContext */
51+
private $executeInStoreContext;
52+
4753
/**
4854
* @inheritdoc
4955
*/
@@ -62,6 +68,7 @@ protected function setUp(): void
6268
$this->block = $page->getLayout()->getBlock('customer_address_edit');
6369
$this->addressRegistry = $this->objectManager->get(AddressRegistry::class);
6470
$this->customerRegistry = $this->objectManager->get(CustomerRegistry::class);
71+
$this->executeInStoreContext = $this->objectManager->get(ExecuteInStoreContext::class);
6572
}
6673

6774
/**
@@ -174,4 +181,26 @@ public function testVatIdFieldNotVisible(): void
174181
$inputXpath = "//div[contains(@class, 'taxvat')]//div/input[contains(@id,'vat_id') and @type='text']";
175182
$this->assertEquals(0, Xpath::getElementsCountForXpath($inputXpath, $html));
176183
}
184+
185+
/**
186+
* @magentoDataFixture Magento/Customer/_files/customer.php
187+
* @magentoDataFixture Magento/Customer/_files/attribute_postcode_store_label_address.php
188+
*
189+
* @return void
190+
*/
191+
public function testCheckPostCodeLabels(): void
192+
{
193+
$newLabel = 'default store postcode label';
194+
$html = $this->executeInStoreContext->execute('default', [$this->block, 'toHtml']);
195+
$this->assertEquals(
196+
1,
197+
Xpath::getElementsCountForXpath(
198+
sprintf(
199+
"//form[contains(@class, 'form-address-edit')]//label[@for='zip']/span[contains(text(), '%s')]",
200+
$newLabel
201+
),
202+
$html
203+
)
204+
);
205+
}
177206
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\Customer\Api\AddressMetadataInterface;
9+
use Magento\Customer\Api\Data\AddressInterface;
10+
use Magento\Eav\Api\AttributeRepositoryInterface;
11+
use Magento\Store\Model\StoreManagerInterface;
12+
use Magento\TestFramework\Helper\Bootstrap;
13+
14+
$objectManager = Bootstrap::getObjectManager();
15+
/** @var AttributeRepositoryInterface $attributeRepository */
16+
$attributeRepository = $objectManager->get(AttributeRepositoryInterface::class);
17+
/** @var StoreManagerInterface $storeManager */
18+
$storeManager = $objectManager->get(StoreManagerInterface::class);
19+
$attribute = $attributeRepository->get(AddressMetadataInterface::ENTITY_TYPE_ADDRESS, AddressInterface::POSTCODE);
20+
$storeLabels = $attribute->getStoreLabels();
21+
$stores = $storeManager->getStores();
22+
foreach ($stores as $store) {
23+
$storeLabels[$store->getId()] = $store->getCode() . ' store postcode label';
24+
}
25+
$attribute->setStoreLabels($storeLabels);
26+
$attributeRepository->save($attribute);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\Customer\Api\AddressMetadataInterface;
9+
use Magento\Customer\Api\Data\AddressInterface;
10+
use Magento\Eav\Api\AttributeRepositoryInterface;
11+
use Magento\Store\Model\StoreManagerInterface;
12+
use Magento\TestFramework\Helper\Bootstrap;
13+
14+
$objectManager = Bootstrap::getObjectManager();
15+
/** @var AttributeRepositoryInterface $attributeRepository */
16+
$attributeRepository = $objectManager->get(AttributeRepositoryInterface::class);
17+
/** @var StoreManagerInterface $storeManager */
18+
$storeManager = $objectManager->get(StoreManagerInterface::class);
19+
$attribute = $attributeRepository->get(AddressMetadataInterface::ENTITY_TYPE_ADDRESS, AddressInterface::POSTCODE);
20+
$attribute->setStoreLabels([]);
21+
$attributeRepository->save($attribute);

0 commit comments

Comments
 (0)