Skip to content

Commit 990d414

Browse files
committed
MTA-3255: Customer: Extend update backend customer test
1 parent 8bc4691 commit 990d414

File tree

16 files changed

+418
-54
lines changed

16 files changed

+418
-54
lines changed

dev/tests/functional/tests/app/Magento/Customer/Test/Block/Account/AddressesDefault.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@
1515
class AddressesDefault extends Block
1616
{
1717
/**
18-
* Selector for change billing address
18+
* Content of default address block.
19+
*
20+
* @var string
21+
*/
22+
protected $defaultAddressContent = '.block-content';
23+
24+
/**
25+
* Selector for change billing address.
1926
*
2027
* @var string
2128
*/
@@ -29,4 +36,14 @@ public function goToAddressBook()
2936
$this->waitForElementVisible($this->changeBillingAddressSelector, Locator::SELECTOR_CSS);
3037
$this->_rootElement->find($this->changeBillingAddressSelector, Locator::SELECTOR_CSS)->click();
3138
}
39+
40+
/**
41+
* Get block text.
42+
*
43+
* @return string
44+
*/
45+
public function getBlockText()
46+
{
47+
return $this->_rootElement->find($this->defaultAddressContent)->getText();
48+
}
3249
}

dev/tests/functional/tests/app/Magento/Customer/Test/Block/Address/Renderer.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ protected function getPattern()
5353
. "{{city}}, {{{$region}}}, {{postcode}}\n{{country_id}}\n{{depend}}T: {{telephone}}{{/depend}}"
5454
. "{{depend}}\nF: {{fax}}{{/depend}}{{depend}}\nVAT: {{vat_id}}{{/depend}}";
5555
break;
56+
case "htmlInBackend":
57+
$outputPattern = "{{depend}}{{prefix}} {{/depend}}{{firstname}} {{depend}}{{middlename}} {{/depend}}"
58+
. "{{lastname}}{{depend}} {{suffix}}{{/depend}}\n{{depend}}{{company}}\n{{/depend}}"
59+
. "{{city}}, {{{$region}}}, {{postcode}}\n{{country_id}}\n{{depend}}T: {{telephone}}{{/depend}}"
60+
. "{{depend}}\nF: {{fax}}{{/depend}}{{depend}}\nVAT: {{vat_id}}{{/depend}}";
61+
break;
5662
case "oneline":
5763
default:
5864
$outputPattern = "{{depend}}{{prefix}} {{/depend}}{{firstname}} {{depend}}{{middlename}} {{/depend}}"

dev/tests/functional/tests/app/Magento/Customer/Test/Block/Adminhtml/Edit/CustomerForm.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
namespace Magento\Customer\Test\Block\Adminhtml\Edit;
88

99
use Magento\Backend\Test\Block\Widget\FormTabs;
10-
use Magento\Mtf\Client\Locator;
1110
use Magento\Mtf\Fixture\FixtureInterface;
1211
use Magento\Mtf\Fixture\InjectableFixture;
12+
use Magento\Customer\Test\Fixture\Address;
1313

1414
/**
1515
* Form for creation of the customer.
@@ -79,17 +79,22 @@ public function fillCustomer(FixtureInterface $customer, $address = null)
7979
*
8080
* @param FixtureInterface $customer
8181
* @param FixtureInterface|FixtureInterface[]|null $address
82+
* @param Address $addressToDelete = null
8283
* @return $this
8384
*/
84-
public function updateCustomer(FixtureInterface $customer, $address = null)
85+
public function updateCustomer(FixtureInterface $customer, $address = null, Address $addressToDelete = null)
8586
{
8687
$this->waitForm();
8788

8889
$isHasData = ($customer instanceof InjectableFixture) ? $customer->hasData() : true;
8990
if ($isHasData) {
9091
parent::fill($customer);
9192
}
92-
if (null !== $address) {
93+
if ($addressToDelete !== null) {
94+
$this->openTab('addresses');
95+
$this->getTab('addresses')->deleteCustomerAddress($addressToDelete);
96+
}
97+
if ($address !== null) {
9398
$this->openTab('addresses');
9499
$this->getTab('addresses')->updateAddresses($address);
95100
}

dev/tests/functional/tests/app/Magento/Customer/Test/Block/Adminhtml/Edit/Tab/Addresses.php

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@
77
namespace Magento\Customer\Test\Block\Adminhtml\Edit\Tab;
88

99
use Magento\Backend\Test\Block\Widget\Tab;
10+
use Magento\Mtf\Block\BlockFactory;
1011
use Magento\Mtf\Client\Element\SimpleElement;
1112
use Magento\Mtf\Client\Element;
1213
use Magento\Mtf\Client\Locator;
1314
use Magento\Mtf\Fixture\FixtureInterface;
15+
use Magento\Mtf\ObjectManager;
16+
use Magento\Mtf\Util\ModuleResolver\SequenceSorterInterface;
17+
use Magento\Mtf\Client\BrowserInterface;
18+
use Magento\Mtf\Block\Mapper;
19+
use Magento\Customer\Test\Fixture\Address;
1420

1521
/**
1622
* Customer addresses edit block.
@@ -24,6 +30,27 @@ class Addresses extends Tab
2430
*/
2531
protected $addNewAddress = '.address-list-actions .add';
2632

33+
/**
34+
* Selector for address block.
35+
*
36+
* @var string
37+
*/
38+
protected $addressSelector = "//li[address[contains(.,'%s')]]";
39+
40+
/**
41+
* Delete Address button.
42+
*
43+
* @var string
44+
*/
45+
protected $deleteAddress = '.action-delete';
46+
47+
/**
48+
* Accept button selector.
49+
*
50+
* @var string
51+
*/
52+
private $confirmModal = '.confirm._show[data-role=modal]';
53+
2754
/**
2855
* Open customer address.
2956
*
@@ -38,6 +65,36 @@ class Addresses extends Tab
3865
*/
3966
protected $loader = '//ancestor::body/div[@data-role="loader"]';
4067

68+
/**
69+
* Object Manager.
70+
*
71+
* @var ObjectManager
72+
*/
73+
private $objectManager;
74+
75+
/**
76+
* @constructor
77+
* @param SimpleElement $element
78+
* @param BlockFactory $blockFactory
79+
* @param Mapper $mapper
80+
* @param BrowserInterface $browser
81+
* @param SequenceSorterInterface $sequenceSorter
82+
* @param ObjectManager $objectManager
83+
* @param array $config [optional]
84+
*/
85+
public function __construct(
86+
SimpleElement $element,
87+
BlockFactory $blockFactory,
88+
Mapper $mapper,
89+
BrowserInterface $browser,
90+
SequenceSorterInterface $sequenceSorter,
91+
ObjectManager $objectManager,
92+
array $config = []
93+
) {
94+
$this->objectManager = $objectManager;
95+
parent::__construct($element, $blockFactory, $mapper, $browser, $sequenceSorter, $config);
96+
}
97+
4198
/**
4299
* Fill customer addresses.
43100
*
@@ -95,7 +152,7 @@ public function updateAddresses($address)
95152
}
96153

97154
/**
98-
* Get data of Customer addresses.
155+
* Get data from Customer addresses.
99156
*
100157
* @param FixtureInterface|FixtureInterface[]|null $address
101158
* @return array
@@ -182,4 +239,33 @@ protected function isVisibleCustomerAddress($addressNumber)
182239

183240
return $addressTab->isVisible();
184241
}
242+
243+
/**
244+
* Click delete customer address button.
245+
*
246+
* @param Address $addressToDelete
247+
* @return $this
248+
*/
249+
public function deleteCustomerAddress(Address $addressToDelete)
250+
{
251+
$addressRenderer = $this->objectManager->create(
252+
\Magento\Customer\Test\Block\Address\Renderer::class,
253+
['address' => $addressToDelete, 'type' => 'htmlInBackend']
254+
);
255+
$addressToDelete = $addressRenderer->render();
256+
257+
$dataList = explode("\n", $addressToDelete);
258+
$dataList = implode("') and contains(.,'", $dataList);
259+
260+
$this->_rootElement
261+
->find(sprintf($this->addressSelector, $dataList), Locator::SELECTOR_XPATH)
262+
->find($this->deleteAddress)->click();
263+
264+
$element = $this->browser->find($this->confirmModal);
265+
/** @var \Magento\Ui\Test\Block\Adminhtml\Modal $modal */
266+
$modal = $this->blockFactory->create(\Magento\Ui\Test\Block\Adminhtml\Modal::class, ['element' => $element]);
267+
$modal->acceptAlert();
268+
269+
return $this;
270+
}
185271
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Customer\Test\Constraint;
8+
9+
use Magento\Customer\Test\Page\CustomerAccountIndex;
10+
use Magento\Mtf\Constraint\AbstractConstraint;
11+
12+
/**
13+
* Assert that deleted customers address is absent in Address Book in Customer Account
14+
*/
15+
class AssertAdditionalAddressDeletedFrontend extends AbstractConstraint
16+
{
17+
/**
18+
* Expected message
19+
*/
20+
const EXPECTED_MESSAGE = 'You have no other address entries in your address book.';
21+
22+
/**
23+
* Asserts that Asserts that 'Additional Address Entries' contains expected message
24+
*
25+
* @param CustomerAccountIndex $customerAccountIndex
26+
* @return void
27+
*/
28+
public function processAssert(CustomerAccountIndex $customerAccountIndex)
29+
{
30+
$customerAccountIndex->open();
31+
$customerAccountIndex->getAccountMenuBlock()->openMenuItem('Address Book');
32+
$actualText = $customerAccountIndex->getAdditionalAddressBlock()->getBlockText();
33+
\PHPUnit_Framework_Assert::assertTrue(
34+
self::EXPECTED_MESSAGE == $actualText,
35+
'Expected text is absent in Additional Address block.'
36+
);
37+
}
38+
39+
/**
40+
* Returns a string representation of the object
41+
*
42+
* @return string
43+
*/
44+
public function toString()
45+
{
46+
return 'Deleted address is absent in "Additional Address Entries" block.';
47+
}
48+
}

dev/tests/functional/tests/app/Magento/Customer/Test/Constraint/AssertAddressDeletedFrontend.php

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,43 +7,67 @@
77
namespace Magento\Customer\Test\Constraint;
88

99
use Magento\Customer\Test\Page\CustomerAccountIndex;
10+
use Magento\Customer\Test\Page\CustomerAddressEdit;
1011
use Magento\Mtf\Constraint\AbstractConstraint;
12+
use Magento\Customer\Test\Fixture\Customer;
13+
use Magento\Customer\Test\Fixture\Address;
1114

1215
/**
13-
* Class AssertAddressDeletedFrontend
14-
* Assert that deleted customers address is absent in Address Book in Customer Account
16+
* Assert that deleted customers address is absent in Address Book in Customer Account.
1517
*/
1618
class AssertAddressDeletedFrontend extends AbstractConstraint
1719
{
1820
/**
19-
* Expected message
20-
*/
21-
const EXPECTED_MESSAGE = 'You have no other address entries in your address book.';
22-
23-
/**
24-
* Asserts that Asserts that 'Additional Address Entries' contains expected message
21+
* Asserts that deleted address is not present on Frontend.
2522
*
2623
* @param CustomerAccountIndex $customerAccountIndex
24+
* @param CustomerAddressEdit $customerAddressEdit
25+
* @param Customer $customer
26+
* @param Address $addressToDelete
2727
* @return void
2828
*/
29-
public function processAssert(CustomerAccountIndex $customerAccountIndex)
30-
{
31-
$customerAccountIndex->open();
29+
public function processAssert(
30+
CustomerAccountIndex $customerAccountIndex,
31+
CustomerAddressEdit $customerAddressEdit,
32+
Customer $customer,
33+
Address $addressToDelete
34+
) {
35+
36+
$this->objectManager->create(
37+
'Magento\Customer\Test\TestStep\LoginCustomerOnFrontendStep',
38+
['customer' => $customer]
39+
)->run();
40+
3241
$customerAccountIndex->getAccountMenuBlock()->openMenuItem('Address Book');
33-
$actualText = $customerAccountIndex->getAdditionalAddressBlock()->getBlockText();
42+
$addressRenderer = $this->objectManager->create(
43+
\Magento\Customer\Test\Block\Address\Renderer::class,
44+
['address' => $addressToDelete, 'type' => 'html']
45+
);
46+
$deletedAddress = $addressRenderer->render();
47+
48+
$isAddressDeleted = false;
49+
if ($customerAddressEdit->getEditForm()->isVisible()
50+
|| ($customerAccountIndex->getAdditionalAddressBlock()->getBlockText() !== null
51+
&& $deletedAddress != $customerAccountIndex->getAdditionalAddressBlock()->getBlockText())
52+
|| ($customerAccountIndex->getDefaultAddressBlock()->getBlockText() !== null
53+
&& $deletedAddress != $customerAccountIndex->getAdditionalAddressBlock()->getBlockText())
54+
) {
55+
$isAddressDeleted = true;
56+
}
57+
3458
\PHPUnit_Framework_Assert::assertTrue(
35-
self::EXPECTED_MESSAGE == $actualText,
36-
'Expected text is absent in Additional Address block.'
59+
$isAddressDeleted,
60+
'Customer address was not deleted.'
3761
);
3862
}
3963

4064
/**
41-
* Returns a string representation of the object
65+
* Returns a string representation of the object.
4266
*
4367
* @return string
4468
*/
4569
public function toString()
4670
{
47-
return 'Deleted address is absent in "Additional Address Entries" block.';
71+
return 'Deleted address is absent in Frontend.';
4872
}
4973
}

dev/tests/functional/tests/app/Magento/Customer/Test/Constraint/AssertCustomerForm.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,18 @@ class AssertCustomerForm extends AbstractConstraint
4141
* @param CustomerIndex $pageCustomerIndex
4242
* @param CustomerIndexEdit $pageCustomerIndexEdit
4343
* @param Address $address[optional]
44-
* @param Customer $initialCustomer [optional]
4544
* @return void
4645
*/
4746
public function processAssert(
4847
Customer $customer,
4948
CustomerIndex $pageCustomerIndex,
5049
CustomerIndexEdit $pageCustomerIndexEdit,
51-
Address $address = null,
52-
Customer $initialCustomer = null
50+
Address $address = null
5351
) {
5452
$data = [];
5553
$filter = [];
5654

57-
if ($initialCustomer) {
58-
$data['customer'] = $customer->hasData()
59-
? array_merge($initialCustomer->getData(), $customer->getData())
60-
: $initialCustomer->getData();
61-
} else {
62-
$data['customer'] = $customer->getData();
63-
}
55+
$data['customer'] = $customer->getData();
6456
if ($address) {
6557
$data['addresses'][1] = $address->hasData() ? $address->getData() : [];
6658
} else {

dev/tests/functional/tests/app/Magento/Customer/Test/Constraint/AssertCustomerInGrid.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,15 @@ class AssertCustomerInGrid extends AbstractConstraint
2525
*
2626
* @param Customer $customer
2727
* @param CustomerIndex $pageCustomerIndex
28-
* @param Customer $initialCustomer [optional]
2928
* @return void
3029
*
3130
* @SuppressWarnings(PHPMD.NPathComplexity)
3231
*/
3332
public function processAssert(
3433
Customer $customer,
35-
CustomerIndex $pageCustomerIndex,
36-
Customer $initialCustomer = null
34+
CustomerIndex $pageCustomerIndex
3735
) {
38-
if ($initialCustomer) {
39-
$customer = $customer->hasData()
40-
? array_merge($initialCustomer->getData(), $customer->getData())
41-
: $initialCustomer->getData();
42-
} else {
43-
$customer = $customer->getData();
44-
}
36+
$customer = $customer->getData();
4537
$name = (isset($customer['prefix']) ? $customer['prefix'] . ' ' : '')
4638
. $customer['firstname']
4739
. (isset($customer['middlename']) ? ' ' . $customer['middlename'] : '')

0 commit comments

Comments
 (0)