Skip to content

Commit 8d1d31a

Browse files
author
Dmytro Aponasenko
committed
MTA-2494: Extend Create Customer from Backend
1 parent f735796 commit 8d1d31a

File tree

10 files changed

+323
-9
lines changed

10 files changed

+323
-9
lines changed

dev/tests/functional/tests/app/Magento/Backend/Test/Block/Cache/Grid.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
class Grid extends ParentGrid
1515
{
1616
/**
17-
* Search for item and select it
17+
* Search for item and select it.
1818
*
1919
* @param array $filter
20+
* @return void
2021
* @throws \Exception
2122
*/
2223
public function searchAndSelect(array $filter)

dev/tests/functional/tests/app/Magento/Backend/Test/Block/Widget/Tab.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
use Magento\Mtf\Client\Locator;
1212

1313
/**
14-
* Class Tab
15-
* Is used to represent any tab on the page
14+
* Is used to represent any tab on the page.
1615
*
1716
* @SuppressWarnings(PHPMD.NumberOfChildren)
1817
*/
@@ -23,24 +22,24 @@ class Tab extends AbstractForm
2322
*
2423
* @var string
2524
*/
26-
protected $mageErrorField = '//*[contains(@class,"field ")][.//*[@class="mage-error"]]';
25+
protected $mageErrorField = '//fieldset/*[contains(@class,"field ")][.//*[contains(@class,"error")]]';
2726

2827
/**
2928
* Fields label with mage error.
3029
*
3130
* @var string
3231
*/
33-
protected $mageErrorLabel = './label';
32+
protected $mageErrorLabel = './/*[contains(@class,"label")]';
3433

3534
/**
3635
* Mage error text.
3736
*
3837
* @var string
3938
*/
40-
protected $mageErrorText = './/*[@class="mage-error"]';
39+
protected $mageErrorText = './/label[contains(@class,"error")]';
4140

4241
/**
43-
* Fill data to fields on tab
42+
* Fill data to fields on tab.
4443
*
4544
* @param array $fields
4645
* @param SimpleElement|null $element
@@ -55,7 +54,7 @@ public function fillFormTab(array $fields, SimpleElement $element = null)
5554
}
5655

5756
/**
58-
* Get data of tab
57+
* Get data of tab.
5958
*
6059
* @param array|null $fields
6160
* @param SimpleElement|null $element
@@ -68,10 +67,11 @@ public function getDataFormTab($fields = null, SimpleElement $element = null)
6867
}
6968

7069
/**
71-
* Update data to fields on tab
70+
* Update data to fields on tab.
7271
*
7372
* @param array $fields
7473
* @param SimpleElement|null $element
74+
* @return void
7575
*/
7676
public function updateFormTab(array $fields, SimpleElement $element = null)
7777
{

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,21 @@ public function openTab($tabName)
141141

142142
return $this;
143143
}
144+
145+
/**
146+
* Get array of label => js error text.
147+
*
148+
* @return array
149+
*/
150+
public function getJsErrors()
151+
{
152+
$tabs = ['account_information', 'addresses'];
153+
$jsErrors = [];
154+
foreach ($tabs as $tabName) {
155+
$tab = $this->getTab($tabName);
156+
$this->openTab($tabName);
157+
$jsErrors = array_merge($jsErrors, $tab->getJsErrors());
158+
}
159+
return $jsErrors;
160+
}
144161
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Customer\Test\Constraint;
8+
9+
use Magento\Mtf\Constraint\AbstractConstraint;
10+
use Magento\Customer\Test\Page\Adminhtml\CustomerIndex;
11+
use Magento\Customer\Test\Page\Adminhtml\CustomerIndexEdit;
12+
13+
/**
14+
* Asserts that "Back" button works on customer edit page.
15+
*/
16+
class AssertCustomerBackendBackButton extends AbstractConstraint
17+
{
18+
/**
19+
* Asserts that "Back" button works on customer edit page (returns to customers grid).
20+
*
21+
* @param CustomerIndexEdit $customerEditPage
22+
* @param CustomerIndex $customerGridPage
23+
* @return void
24+
*/
25+
public function processAssert(CustomerIndexEdit $customerEditPage, CustomerIndex $customerGridPage)
26+
{
27+
$customerEditPage->getPageActionsBlock()->back();
28+
\PHPUnit_Framework_Assert::assertTrue(
29+
$customerGridPage->getCustomerGridBlock()->isVisible(),
30+
'Clicking on "Back" button does not redirect to customers grid.'
31+
);
32+
}
33+
34+
/**
35+
* Returns a string representation of the object.
36+
*
37+
* @return string
38+
*/
39+
public function toString()
40+
{
41+
return '"Back" button on customer edit page redirects to customers grid.';
42+
}
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 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\Adminhtml\CustomerIndex;
10+
use Magento\Mtf\Constraint\AbstractConstraint;
11+
12+
/**
13+
* Asserts duplicate error message on saving backend customer.
14+
*/
15+
class AssertCustomerBackendDuplicateErrorMessage extends AbstractConstraint
16+
{
17+
/**
18+
* Error save message text.
19+
*/
20+
const ERROR_SAVE_MESSAGE = 'A customer with the same email already exists in an associated website.';
21+
22+
/**
23+
* Asserts that error message is displayed while creating customer with the same email.
24+
*
25+
* @param CustomerIndex $customerIndexPage
26+
* @return void
27+
*/
28+
public function processAssert(CustomerIndex $customerIndexPage)
29+
{
30+
$actualMessage = $customerIndexPage->getMessagesBlock()->getErrorMessages();
31+
\PHPUnit_Framework_Assert::assertEquals(
32+
self::ERROR_SAVE_MESSAGE,
33+
$actualMessage,
34+
'Wrong error message is displayed.'
35+
. "\nExpected: " . self::ERROR_SAVE_MESSAGE
36+
. "\nActual: " . $actualMessage
37+
);
38+
}
39+
40+
/**
41+
* Returns a string representation of the object.
42+
*
43+
* @return string
44+
*/
45+
public function toString()
46+
{
47+
return 'Assert that error duplicated message is displayed.';
48+
}
49+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 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\Adminhtml\CustomerIndexNew;
10+
use Magento\Mtf\Constraint\AbstractConstraint;
11+
12+
/**
13+
* Assert required fields on customer form.
14+
*/
15+
class AssertCustomerBackendRequiredFields extends AbstractConstraint
16+
{
17+
/**
18+
* Expected message.
19+
*/
20+
const REQUIRE_MESSAGE = 'This is a required field.';
21+
22+
/**
23+
* Assert required fields on customer form.
24+
*
25+
* @param CustomerIndexNew $customerNewPage
26+
* @param array $expectedRequiredFields
27+
* @return void
28+
*/
29+
public function processAssert(CustomerIndexNew $customerNewPage, array $expectedRequiredFields)
30+
{
31+
$actualRequiredFields = $customerNewPage->getCustomerForm()->getJsErrors();
32+
foreach ($expectedRequiredFields as $field) {
33+
\PHPUnit_Framework_Assert::assertTrue(
34+
isset($actualRequiredFields[$field]),
35+
"Field '$field' is not highlighted with an JS error."
36+
);
37+
\PHPUnit_Framework_Assert::assertEquals(
38+
self::REQUIRE_MESSAGE,
39+
$actualRequiredFields[$field],
40+
"Field '$field' is not highlighted as required."
41+
);
42+
}
43+
}
44+
45+
/**
46+
* Return string representation of object.
47+
*
48+
* @return string
49+
*/
50+
public function toString()
51+
{
52+
return 'All required fields on customer form are highlighted.';
53+
}
54+
}

dev/tests/functional/tests/app/Magento/Customer/Test/TestCase/CreateCustomerBackendEntityTest.xml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,44 @@
9696
<constraint name="Magento\Customer\Test\Constraint\AssertCustomerSuccessSaveMessage" />
9797
<constraint name="Magento\Customer\Test\Constraint\AssertCustomerBackendFormTitle" />
9898
</variation>
99+
<variation name="CreateCustomerBackendEntityTestVariation7" summary="Create customer with custom customer group">
100+
<data name="customerAction" xsi:type="string">saveAndContinue</data>
101+
<data name="customer/data/website_id" xsi:type="string">Main Website</data>
102+
<data name="customer/data/group_id/dataset" xsi:type="string">customer_group_retail_customer</data>
103+
<data name="customer/data/firstname" xsi:type="string">John%isolation%</data>
104+
<data name="customer/data/lastname" xsi:type="string">Doe%isolation%</data>
105+
<data name="customer/data/email" xsi:type="string">JohnDoe%isolation%@example.com</data>
106+
<constraint name="Magento\Customer\Test\Constraint\AssertCustomerSuccessSaveMessage" />
107+
<constraint name="Magento\Customer\Test\Constraint\AssertCustomerBackendBackButton" />
108+
<constraint name="Magento\Customer\Test\Constraint\AssertCustomerForm" />
109+
</variation>
110+
<variation name="CreateCustomerBackendEntityTestVariation8" summary="Verify required fields on Account Information tab.">
111+
<data name="customerAction" xsi:type="string">save</data>
112+
<data name="customer/data/website_id" xsi:type="string">Main Website</data>
113+
<data name="customer/data/group_id/dataset" xsi:type="string">General</data>
114+
<data name="expectedRequiredFields" xsi:type="array">
115+
<item name="0" xsi:type="string">First Name</item>
116+
<item name="1" xsi:type="string">Last Name</item>
117+
<item name="2" xsi:type="string">Email</item>
118+
</data>
119+
<constraint name="Magento\Customer\Test\Constraint\AssertCustomerBackendRequiredFields" />
120+
</variation>
121+
<variation name="CreateCustomerBackendEntityTestVariation9" summary="Verify required fields on Addresses tab.">
122+
<data name="customerAction" xsi:type="string">save</data>
123+
<data name="customer/data/website_id" xsi:type="string">Main Website</data>
124+
<data name="customer/data/group_id/dataset" xsi:type="string">General</data>
125+
<data name="customer/data/firstname" xsi:type="string">John%isolation%</data>
126+
<data name="customer/data/lastname" xsi:type="string">Doe%isolation%</data>
127+
<data name="customer/data/email" xsi:type="string">JohnDoe%isolation%@example.com</data>
128+
<data name="address/data/company" xsi:type="string">Magento</data>
129+
<data name="expectedRequiredFields" xsi:type="array">
130+
<item name="2" xsi:type="string">Street Address</item>
131+
<item name="3" xsi:type="string">City</item>
132+
<item name="4" xsi:type="string">Country</item>
133+
<item name="5" xsi:type="string">Zip/Postal Code</item>
134+
<item name="6" xsi:type="string">Phone Number</item>
135+
</data>
136+
<constraint name="Magento\Customer\Test\Constraint\AssertCustomerBackendRequiredFields" />
137+
</variation>
99138
</testCase>
100139
</config>
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Customer\Test\TestCase;
8+
9+
use Magento\Mtf\TestCase\Injectable;
10+
use Magento\Customer\Test\Fixture\Customer;
11+
use Magento\Customer\Test\Page\Adminhtml\CustomerIndex;
12+
use Magento\Customer\Test\Page\Adminhtml\CustomerIndexNew;
13+
14+
/**
15+
* Precondition:
16+
* 1. Customer is created.
17+
*
18+
* Steps:
19+
* 1. Log in as default admin user.
20+
* 2. Go to Customers > All Customers.
21+
* 3. Press "Add New Customer" button.
22+
* 4. Fill form with data from previously created customer.
23+
* 5. Click "Save Customer" button.
24+
* 6. Perform all assertions.
25+
*
26+
* @ZephyrId MAGETWO-43685
27+
*/
28+
class CreateExistingCustomerBackendEntity extends Injectable
29+
{
30+
/* tags */
31+
const MVP = 'yes';
32+
const DOMAIN = 'CS';
33+
/* end tags */
34+
35+
/**
36+
* Customer index page.
37+
*
38+
* @var CustomerIndex
39+
*/
40+
protected $pageCustomerIndex;
41+
42+
/**
43+
* New customer page.
44+
*
45+
* @var CustomerIndexNew
46+
*/
47+
protected $pageCustomerIndexNew;
48+
49+
/**
50+
* Inject customer pages.
51+
*
52+
* @param CustomerIndex $pageCustomerIndex
53+
* @param CustomerIndexNew $pageCustomerIndexNew
54+
* @return void
55+
*/
56+
public function __inject(
57+
CustomerIndex $pageCustomerIndex,
58+
CustomerIndexNew $pageCustomerIndexNew
59+
) {
60+
$this->pageCustomerIndex = $pageCustomerIndex;
61+
$this->pageCustomerIndexNew = $pageCustomerIndexNew;
62+
}
63+
64+
/**
65+
* Create customer on backend.
66+
*
67+
* @param Customer $customer
68+
* @return void
69+
*/
70+
public function test(Customer $customer)
71+
{
72+
// Precondition
73+
$customer->persist();
74+
75+
// Steps
76+
$this->pageCustomerIndex->open();
77+
$this->pageCustomerIndex->getPageActionsBlock()->addNew();
78+
$this->pageCustomerIndexNew->getCustomerForm()->fillCustomer($customer);
79+
$this->pageCustomerIndexNew->getPageActionsBlock()->save();
80+
}
81+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
/**
4+
* Copyright © 2015 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd">
9+
<testCase name="Magento\Customer\Test\TestCase\CreateExistingCustomerBackendEntity" summary="Create Existing Customer from Backend" ticketId="MAGETWO-43685">
10+
<variation name="CreateExistingCustomerBackendEntity1" summary="Create existing customer on Backend.">
11+
<data name="customer/dataset" xsi:type="string">default</data>
12+
<constraint name="Magento\Customer\Test\Constraint\AssertCustomerBackendDuplicateErrorMessage" />
13+
</variation>
14+
</testCase>
15+
</config>

0 commit comments

Comments
 (0)