Skip to content

Commit 169fa6e

Browse files
committed
Merge branch 'MAGETWO-57835' of github.com:magento-troll/magento2ce into PR_Troll
2 parents 92d97a5 + a2bec20 commit 169fa6e

File tree

13 files changed

+204
-25
lines changed

13 files changed

+204
-25
lines changed

app/code/Magento/Customer/view/adminhtml/ui_component/customer_listing.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@
230230
<settings>
231231
<timezone>false</timezone>
232232
<dateFormat>MMM d, y</dateFormat>
233+
<skipTime>true</skipTime>
233234
<filter>dateRange</filter>
234235
<dataType>date</dataType>
235236
<label translate="true">Date of Birth</label>

app/code/Magento/Ui/Component/Filters/Type/Date.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Ui\Component\Filters\Type;
78

89
use Magento\Ui\Component\Form\Element\DataType\Date as DataTypeDate;
@@ -78,12 +79,26 @@ protected function applyFilter()
7879
}
7980

8081
if (is_array($value)) {
82+
$dateFrom = null;
83+
$dateTo = null;
84+
8185
if (isset($value['from'])) {
82-
$this->applyFilterByType('gteq', $this->wrappedComponent->convertDate($value['from']));
86+
$dateFrom = $this->wrappedComponent->convertDate($value['from']);
87+
if ($this->getData('config/skipTime')) {
88+
$dateFrom->setTime(0, 0, 0);
89+
}
90+
$this->applyFilterByType('gteq', $dateFrom);
8391
}
8492

8593
if (isset($value['to'])) {
86-
$this->applyFilterByType('lteq', $this->wrappedComponent->convertDate($value['to'], 23, 59, 59));
94+
$dateTo = $this->wrappedComponent->convertDate($value['to']);
95+
if ($this->getData('config/skipTime')) {
96+
$dateTo->setTime(0, 0, 0);
97+
}
98+
if ($dateFrom == $dateTo) {
99+
$dateTo->setTime(23, 59, 59);
100+
}
101+
$this->applyFilterByType('lteq', $dateTo);
87102
}
88103
} else {
89104
$this->applyFilterByType('eq', $this->wrappedComponent->convertDate($value));

app/code/Magento/Ui/Component/Form/Element/DataType/Date.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,9 @@ public function getComponentName()
9797
* Convert given date to default (UTC) timezone
9898
*
9999
* @param int $date
100-
* @param int $hour
101-
* @param int $minute
102-
* @param int $second
103100
* @return \DateTime|null
104101
*/
105-
public function convertDate($date, $hour = 0, $minute = 0, $second = 0)
102+
public function convertDate($date)
106103
{
107104
try {
108105
$dateObj = $this->localeDate->date(
@@ -113,7 +110,6 @@ public function convertDate($date, $hour = 0, $minute = 0, $second = 0)
113110
$this->getLocale(),
114111
true
115112
);
116-
$dateObj->setTime($hour, $minute, $second);
117113
//convert store date to default date in UTC timezone without DST
118114
$dateObj->setTimezone(new \DateTimeZone('UTC'));
119115
return $dateObj;

app/code/Magento/Ui/view/base/ui_component/etc/definition.map.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@
128128
<item name="dateFormat" type="string" xsi:type="xpath">settings/dateFormat</item>
129129
<item name="timeFormat" type="string" xsi:type="xpath">settings/timeFormat</item>
130130
<item name="timezone" type="string" xsi:type="xpath">settings/timezone</item>
131+
<item name="skipTime" type="boolean" xsi:type="xpath">settings/skipTime</item>
131132
<item name="editor" xsi:type="array">
132133
<item name="editorType" type="string" xsi:type="xpath">settings/editor/editorType</item>
133134
<item name="validation" type="item" xsi:type="converter">settings/editor/validation</item>
@@ -239,6 +240,7 @@
239240
<item name="showsTime" type="boolean" xsi:type="xpath">settings/showsTime</item>
240241
<item name="dateFormat" type="string" xsi:type="xpath">settings/dateFormat</item>
241242
<item name="timeFormat" type="string" xsi:type="xpath">settings/timeFormat</item>
243+
<item name="skipTime" type="string" xsi:type="xpath">settings/skipTime</item>
242244
</item>
243245
</argument>
244246
</schema>

app/code/Magento/Ui/view/base/ui_component/etc/definition/column.xsd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@
9898
</xs:annotation>
9999
</xs:element>
100100
<xs:element name="timeFormat" type="xs:string"/>
101+
<xs:element name="skipTime" type="xs:boolean">
102+
<xs:annotation>
103+
<xs:documentation>
104+
For the Date column: If time not important for filtering.
105+
</xs:documentation>
106+
</xs:annotation>
107+
</xs:element>
101108
<xs:element name="timezone" type="xs:boolean">
102109
<xs:annotation>
103110
<xs:documentation>

app/code/Magento/Ui/view/base/web/js/form/element/date.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ define([
178178

179179
this.pickerDateTimeFormat = utils.convertToMomentFormat(this.pickerDateTimeFormat);
180180

181-
if (this.dateFormat) {
182-
this.inputDateFormat = this.dateFormat;
181+
if (this.options.dateFormat) {
182+
this.outputDateFormat = this.options.dateFormat;
183183
}
184184

185185
this.inputDateFormat = utils.convertToMomentFormat(this.inputDateFormat);

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,13 @@ class CustomerGrid extends DataGrid
4444
'entity_id_to' => [
4545
'selector' => '[name="entity_id[to]"]',
4646
],
47+
'dob_from' => [
48+
'selector' => '[name="dob[from]"]',
49+
'input' => 'datepicker',
50+
],
51+
'dob_to' => [
52+
'selector' => '[name="dob[to]"]',
53+
'input' => 'datepicker',
54+
],
4755
];
4856
}

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

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,42 @@ class AssertCustomerForm extends AbstractConstraint
3636
'group_id'
3737
];
3838

39+
/**
40+
* Locale map.
41+
*
42+
* @var array
43+
*/
44+
private $localeMap = [
45+
'en_GB' => 'd/m/Y'
46+
];
47+
48+
/**
49+
* Format date for current locale.
50+
*
51+
* @var string
52+
*/
53+
private $localeFormat = 'm/d/Y';
54+
3955
/**
4056
* Assert that displayed customer data on edit page(backend) equals passed from fixture.
4157
*
4258
* @param Customer $customer
4359
* @param CustomerIndex $pageCustomerIndex
4460
* @param CustomerIndexEdit $pageCustomerIndexEdit
45-
* @param Address $address[optional]
61+
* @param Address $address [optional]
62+
* @param string $locale
4663
* @return void
4764
*/
4865
public function processAssert(
4966
Customer $customer,
5067
CustomerIndex $pageCustomerIndex,
5168
CustomerIndexEdit $pageCustomerIndexEdit,
52-
Address $address = null
69+
Address $address = null,
70+
$locale = ''
5371
) {
72+
$this->localeFormat = '' !== $locale && isset($this->localeMap[$locale])
73+
? $this->localeMap[$locale]
74+
: $this->localeFormat;
5475
$data = [];
5576
$filter = [];
5677

@@ -60,6 +81,9 @@ public function processAssert(
6081
} else {
6182
$data['addresses'] = [];
6283
}
84+
if (isset($data['customer']['dob'])) {
85+
$data['customer']['dob'] = date($this->localeFormat, strtotime($data['customer']['dob']));
86+
}
6387
$filter['email'] = $data['customer']['email'];
6488

6589
$pageCustomerIndex->open();

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

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,34 +26,59 @@ class AssertCustomerInGrid extends AbstractConstraint
2626
* @param Customer $customer
2727
* @param CustomerIndex $pageCustomerIndex
2828
* @return void
29-
*
3029
* @SuppressWarnings(PHPMD.NPathComplexity)
3130
*/
3231
public function processAssert(
3332
Customer $customer,
3433
CustomerIndex $pageCustomerIndex
3534
) {
36-
$customer = $customer->getData();
37-
$name = (isset($customer['prefix']) ? $customer['prefix'] . ' ' : '')
38-
. $customer['firstname']
39-
. (isset($customer['middlename']) ? ' ' . $customer['middlename'] : '')
40-
. ' ' . $customer['lastname']
41-
. (isset($customer['suffix']) ? ' ' . $customer['suffix'] : '');
35+
$customerData = $customer->getData();
36+
$name = (isset($customerData['prefix']) ? $customerData['prefix'] . ' ' : '')
37+
. $customerData['firstname']
38+
. (isset($customerData['middlename']) ? ' ' . $customerData['middlename'] : '')
39+
. ' ' . $customerData['lastname']
40+
. (isset($customerData['suffix']) ? ' ' . $customerData['suffix'] : '');
4241
$filter = [
4342
'name' => $name,
44-
'email' => $customer['email'],
43+
'email' => $customerData['email'],
4544
];
45+
$errorMessage = 'Customer with '
46+
. 'name \'' . $filter['name'] . '\', '
47+
. 'email \'' . $filter['email'] . '\'';
48+
49+
if ($customer->hasData('dob')) {
50+
$filter['dob_from'] = $customer->getData('dob');
51+
$filter['dob_to'] = $customer->getData('dob');
52+
}
4653

4754
$pageCustomerIndex->open();
55+
$pageCustomerIndex->getCustomerGridBlock()->isRowVisible($filter);
56+
if ($customer->hasData('dob')) {
57+
unset($filter['dob_from']);
58+
unset($filter['dob_to']);
59+
$filter['dob'] = $this->prepareDob($customer->getData('dob'));
60+
$errorMessage .= ', dob \'' . $filter['dob'] . '\' ';
61+
}
62+
63+
$errorMessage .= 'is absent in Customer grid.';
64+
4865
\PHPUnit_Framework_Assert::assertTrue(
49-
$pageCustomerIndex->getCustomerGridBlock()->isRowVisible($filter),
50-
'Customer with '
51-
. 'name \'' . $filter['name'] . '\', '
52-
. 'email \'' . $filter['email'] . '\' '
53-
. 'is absent in Customer grid.'
66+
$pageCustomerIndex->getCustomerGridBlock()->isRowVisible($filter, false),
67+
$errorMessage
5468
);
5569
}
5670

71+
/**
72+
* Prepare dob string to grid date format.
73+
*
74+
* @param string $date
75+
* @return false|string
76+
*/
77+
private function prepareDob($date)
78+
{
79+
return date('M d, Y', strtotime($date));
80+
}
81+
5782
/**
5883
* Text success exist Customer in grid
5984
*

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

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
use Magento\Customer\Test\Fixture\Customer;
1717
use Magento\Customer\Test\Page\Adminhtml\CustomerIndex;
1818
use Magento\Customer\Test\Page\Adminhtml\CustomerIndexNew;
19+
use Magento\User\Test\Fixture\User;
20+
use Magento\User\Test\Page\Adminhtml\UserEdit;
21+
use Magento\User\Test\Page\Adminhtml\UserIndex;
1922

2023
/**
2124
* Steps:
@@ -67,21 +70,45 @@ class CreateCustomerBackendEntityTest extends Injectable
6770
/** @var FixtureFactory */
6871
private $fixtureFactory;
6972

73+
/**
74+
* @var UserEdit
75+
*/
76+
private $userEdit;
77+
78+
/**
79+
* @var UserIndex
80+
*/
81+
private $userIndex;
82+
83+
/**
84+
* Array of steps.
85+
*
86+
* @var array
87+
*/
88+
private $steps;
89+
7090
/**
7191
* Inject customer pages.
7292
*
7393
* @param CustomerIndex $pageCustomerIndex
7494
* @param CustomerIndexNew $pageCustomerIndexNew
95+
* @param FixtureFactory $fixtureFactory
96+
* @param UserEdit $userEdit
97+
* @param UserIndex $userIndex
7598
* @return void
7699
*/
77100
public function __inject(
78101
CustomerIndex $pageCustomerIndex,
79102
CustomerIndexNew $pageCustomerIndexNew,
80-
\Magento\Mtf\Fixture\FixtureFactory $fixtureFactory
103+
\Magento\Mtf\Fixture\FixtureFactory $fixtureFactory,
104+
UserEdit $userEdit,
105+
UserIndex $userIndex
81106
) {
82107
$this->pageCustomerIndex = $pageCustomerIndex;
83108
$this->pageCustomerIndexNew = $pageCustomerIndexNew;
84109
$this->fixtureFactory = $fixtureFactory;
110+
$this->userEdit = $userEdit;
111+
$this->userIndex = $userIndex;
85112
}
86113

87114
/**
@@ -90,6 +117,8 @@ public function __inject(
90117
* @param Customer $customer
91118
* @param string $customerAction
92119
* @param Address $address
120+
* @param array $steps
121+
* @param array $beforeActionCallback
93122
* @return void
94123
*/
95124
public function test(
@@ -99,6 +128,7 @@ public function test(
99128
array $steps = [],
100129
array $beforeActionCallback = []
101130
) {
131+
$this->steps = $steps;
102132
///Process initialize steps
103133
foreach ($steps as $methodName => $stepData) {
104134
if (method_exists($this, $methodName)) {
@@ -229,4 +259,49 @@ protected function configureAllowedCountries(array $countryList = [])
229259
];
230260
}
231261
}
262+
263+
/**
264+
* Change Admin locale.
265+
*
266+
* @param array $userData
267+
*/
268+
private function changeAdminLocale(array $userData)
269+
{
270+
/** @var User $adminUser */
271+
$adminUser = $this->fixtureFactory->createByCode('user', ['data' => $userData]);
272+
$this->userIndex->open();
273+
$this->userIndex->getUserGrid()->searchAndOpen(['username' => $adminUser->getUsername()]);
274+
$this->userEdit->getUserForm()->fill($adminUser);
275+
$this->userEdit->getPageActions()->save();
276+
}
277+
278+
/**
279+
* Revert Admin locale.
280+
*
281+
* @param array $userData
282+
*/
283+
private function changeAdminLocaleRollback(array $userData)
284+
{
285+
/** @var User $defaultAdminUser */
286+
$defaultAdminUser = $this->fixtureFactory->createByCode('user');
287+
$adminUserData = $defaultAdminUser->getData();
288+
unset($adminUserData['user_id']);
289+
$defaultAdminUser = $this->fixtureFactory->createByCode('user', ['data' => $adminUserData]);
290+
$this->userIndex->open();
291+
$this->userIndex->getUserGrid()->searchAndOpen(['username' => $defaultAdminUser->getUsername()]);
292+
$this->userEdit->getUserForm()->fill($defaultAdminUser);
293+
$this->userEdit->getPageActions()->save();
294+
}
295+
296+
/**
297+
* @inheritdoc
298+
*/
299+
protected function tearDown()
300+
{
301+
foreach ($this->steps as $key => $stepData) {
302+
if (method_exists($this, $key . 'Rollback')) {
303+
call_user_func_array([$this, $key . 'Rollback'], $stepData);
304+
}
305+
}
306+
}
232307
}

0 commit comments

Comments
 (0)