diff --git a/app/code/Magento/Customer/view/adminhtml/ui_component/customer_listing.xml b/app/code/Magento/Customer/view/adminhtml/ui_component/customer_listing.xml index 272ff67d03c12..a56c2d4646dab 100644 --- a/app/code/Magento/Customer/view/adminhtml/ui_component/customer_listing.xml +++ b/app/code/Magento/Customer/view/adminhtml/ui_component/customer_listing.xml @@ -230,6 +230,7 @@ false MMM d, y + true dateRange date diff --git a/app/code/Magento/Ui/Component/Filters/Type/Date.php b/app/code/Magento/Ui/Component/Filters/Type/Date.php index 45d0896e2297f..3c103f3c18bde 100644 --- a/app/code/Magento/Ui/Component/Filters/Type/Date.php +++ b/app/code/Magento/Ui/Component/Filters/Type/Date.php @@ -3,6 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Ui\Component\Filters\Type; use Magento\Ui\Component\Form\Element\DataType\Date as DataTypeDate; @@ -79,7 +80,10 @@ protected function applyFilter() if (is_array($value)) { if (isset($value['from'])) { - $this->applyFilterByType('gteq', $this->wrappedComponent->convertDate($value['from'])); + $this->applyFilterByType( + 'gteq', + $this->wrappedComponent->convertDate($value['from'], 0, 0, 0, $this->getData('config/skipTime')) + ); } if (isset($value['to'])) { diff --git a/app/code/Magento/Ui/Component/Form/Element/DataType/Date.php b/app/code/Magento/Ui/Component/Form/Element/DataType/Date.php index f0a19e26ee299..8be55de5f429e 100644 --- a/app/code/Magento/Ui/Component/Form/Element/DataType/Date.php +++ b/app/code/Magento/Ui/Component/Form/Element/DataType/Date.php @@ -100,9 +100,10 @@ public function getComponentName() * @param int $hour * @param int $minute * @param int $second + * @param bool $skipTime * @return \DateTime|null */ - public function convertDate($date, $hour = 0, $minute = 0, $second = 0) + public function convertDate($date, $hour = 0, $minute = 0, $second = 0, $skipTime = false) { try { $dateObj = $this->localeDate->date( @@ -116,6 +117,9 @@ public function convertDate($date, $hour = 0, $minute = 0, $second = 0) $dateObj->setTime($hour, $minute, $second); //convert store date to default date in UTC timezone without DST $dateObj->setTimezone(new \DateTimeZone('UTC')); + if ($skipTime) { + $dateObj->setTime(0, 0, 0); + } return $dateObj; } catch (\Exception $e) { return null; diff --git a/app/code/Magento/Ui/view/base/ui_component/etc/definition.map.xml b/app/code/Magento/Ui/view/base/ui_component/etc/definition.map.xml index 1db8cf5d47d41..af951e74f8ebb 100644 --- a/app/code/Magento/Ui/view/base/ui_component/etc/definition.map.xml +++ b/app/code/Magento/Ui/view/base/ui_component/etc/definition.map.xml @@ -128,6 +128,7 @@ settings/dateFormat settings/timeFormat settings/timezone + settings/skipTime settings/editor/editorType settings/editor/validation @@ -239,6 +240,7 @@ settings/showsTime settings/dateFormat settings/timeFormat + settings/skipTime diff --git a/app/code/Magento/Ui/view/base/ui_component/etc/definition/column.xsd b/app/code/Magento/Ui/view/base/ui_component/etc/definition/column.xsd index be77cbe2a72a4..9e04c7e002c33 100644 --- a/app/code/Magento/Ui/view/base/ui_component/etc/definition/column.xsd +++ b/app/code/Magento/Ui/view/base/ui_component/etc/definition/column.xsd @@ -98,6 +98,13 @@ + + + + For the Date column: If time not important for filtering. + + + diff --git a/dev/tests/functional/tests/app/Magento/Customer/Test/Block/Adminhtml/CustomerGrid.php b/dev/tests/functional/tests/app/Magento/Customer/Test/Block/Adminhtml/CustomerGrid.php index 752b14e01f444..7d469f1886f63 100644 --- a/dev/tests/functional/tests/app/Magento/Customer/Test/Block/Adminhtml/CustomerGrid.php +++ b/dev/tests/functional/tests/app/Magento/Customer/Test/Block/Adminhtml/CustomerGrid.php @@ -44,5 +44,13 @@ class CustomerGrid extends DataGrid 'entity_id_to' => [ 'selector' => '[name="entity_id[to]"]', ], + 'dob_from' => [ + 'selector' => '[name="dob[from]"]', + 'input' => 'datepicker', + ], + 'dob_to' => [ + 'selector' => '[name="dob[to]"]', + 'input' => 'datepicker', + ], ]; } diff --git a/dev/tests/functional/tests/app/Magento/Customer/Test/Constraint/AssertCustomerForm.php b/dev/tests/functional/tests/app/Magento/Customer/Test/Constraint/AssertCustomerForm.php index 5061452a68a62..0edf85ea4bfc7 100644 --- a/dev/tests/functional/tests/app/Magento/Customer/Test/Constraint/AssertCustomerForm.php +++ b/dev/tests/functional/tests/app/Magento/Customer/Test/Constraint/AssertCustomerForm.php @@ -36,21 +36,42 @@ class AssertCustomerForm extends AbstractConstraint 'group_id' ]; + /** + * Locale map. + * + * @var array + */ + private $localeMap = [ + 'en_GB' => 'd/m/Y' + ]; + + /** + * Format date for current locale. + * + * @var string + */ + private $localeFormat = 'm/d/Y'; + /** * Assert that displayed customer data on edit page(backend) equals passed from fixture. * * @param Customer $customer * @param CustomerIndex $pageCustomerIndex * @param CustomerIndexEdit $pageCustomerIndexEdit - * @param Address $address[optional] + * @param Address $address [optional] + * @param string $locale * @return void */ public function processAssert( Customer $customer, CustomerIndex $pageCustomerIndex, CustomerIndexEdit $pageCustomerIndexEdit, - Address $address = null + Address $address = null, + $locale = '' ) { + $this->localeFormat = '' !== $locale && isset($this->localeMap[$locale]) + ? $this->localeMap[$locale] + : $this->localeFormat; $data = []; $filter = []; @@ -60,6 +81,9 @@ public function processAssert( } else { $data['addresses'] = []; } + if (isset($data['customer']['dob'])) { + $data['customer']['dob'] = date($this->localeFormat, strtotime($data['customer']['dob'])); + } $filter['email'] = $data['customer']['email']; $pageCustomerIndex->open(); diff --git a/dev/tests/functional/tests/app/Magento/Customer/Test/Constraint/AssertCustomerInGrid.php b/dev/tests/functional/tests/app/Magento/Customer/Test/Constraint/AssertCustomerInGrid.php index 8c6bbdc511a9b..c58b58a095000 100644 --- a/dev/tests/functional/tests/app/Magento/Customer/Test/Constraint/AssertCustomerInGrid.php +++ b/dev/tests/functional/tests/app/Magento/Customer/Test/Constraint/AssertCustomerInGrid.php @@ -26,34 +26,59 @@ class AssertCustomerInGrid extends AbstractConstraint * @param Customer $customer * @param CustomerIndex $pageCustomerIndex * @return void - * * @SuppressWarnings(PHPMD.NPathComplexity) */ public function processAssert( Customer $customer, CustomerIndex $pageCustomerIndex ) { - $customer = $customer->getData(); - $name = (isset($customer['prefix']) ? $customer['prefix'] . ' ' : '') - . $customer['firstname'] - . (isset($customer['middlename']) ? ' ' . $customer['middlename'] : '') - . ' ' . $customer['lastname'] - . (isset($customer['suffix']) ? ' ' . $customer['suffix'] : ''); + $customerData = $customer->getData(); + $name = (isset($customerData['prefix']) ? $customerData['prefix'] . ' ' : '') + . $customerData['firstname'] + . (isset($customerData['middlename']) ? ' ' . $customerData['middlename'] : '') + . ' ' . $customerData['lastname'] + . (isset($customerData['suffix']) ? ' ' . $customerData['suffix'] : ''); $filter = [ 'name' => $name, - 'email' => $customer['email'], + 'email' => $customerData['email'], ]; + $errorMessage = 'Customer with ' + . 'name \'' . $filter['name'] . '\', ' + . 'email \'' . $filter['email'] . '\''; + + if ($customer->hasData('dob')) { + $filter['dob_from'] = $customer->getData('dob'); + $filter['dob_to'] = $customer->getData('dob'); + } $pageCustomerIndex->open(); + $pageCustomerIndex->getCustomerGridBlock()->isRowVisible($filter); + if ($customer->hasData('dob')) { + unset($filter['dob_from']); + unset($filter['dob_to']); + $filter['dob'] = $this->prepareDob($customer->getData('dob')); + $errorMessage .= ', dob \'' . $filter['dob'] . '\' '; + } + + $errorMessage .= 'is absent in Customer grid.'; + \PHPUnit_Framework_Assert::assertTrue( - $pageCustomerIndex->getCustomerGridBlock()->isRowVisible($filter), - 'Customer with ' - . 'name \'' . $filter['name'] . '\', ' - . 'email \'' . $filter['email'] . '\' ' - . 'is absent in Customer grid.' + $pageCustomerIndex->getCustomerGridBlock()->isRowVisible($filter, false), + $errorMessage ); } + /** + * Prepare dob string to grid date format. + * + * @param string $date + * @return false|string + */ + private function prepareDob($date) + { + return date('M d, Y', strtotime($date)); + } + /** * Text success exist Customer in grid * diff --git a/dev/tests/functional/tests/app/Magento/Customer/Test/TestCase/CreateCustomerBackendEntityTest.php b/dev/tests/functional/tests/app/Magento/Customer/Test/TestCase/CreateCustomerBackendEntityTest.php index 050e4cdac558b..ccbc540195c8a 100644 --- a/dev/tests/functional/tests/app/Magento/Customer/Test/TestCase/CreateCustomerBackendEntityTest.php +++ b/dev/tests/functional/tests/app/Magento/Customer/Test/TestCase/CreateCustomerBackendEntityTest.php @@ -16,6 +16,9 @@ use Magento\Customer\Test\Fixture\Customer; use Magento\Customer\Test\Page\Adminhtml\CustomerIndex; use Magento\Customer\Test\Page\Adminhtml\CustomerIndexNew; +use Magento\User\Test\Fixture\User; +use Magento\User\Test\Page\Adminhtml\UserEdit; +use Magento\User\Test\Page\Adminhtml\UserIndex; /** * Steps: @@ -67,21 +70,45 @@ class CreateCustomerBackendEntityTest extends Injectable /** @var FixtureFactory */ private $fixtureFactory; + /** + * @var UserEdit + */ + private $userEdit; + + /** + * @var UserIndex + */ + private $userIndex; + + /** + * Array of steps. + * + * @var array + */ + private $steps; + /** * Inject customer pages. * * @param CustomerIndex $pageCustomerIndex * @param CustomerIndexNew $pageCustomerIndexNew + * @param FixtureFactory $fixtureFactory + * @param UserEdit $userEdit + * @param UserIndex $userIndex * @return void */ public function __inject( CustomerIndex $pageCustomerIndex, CustomerIndexNew $pageCustomerIndexNew, - \Magento\Mtf\Fixture\FixtureFactory $fixtureFactory + \Magento\Mtf\Fixture\FixtureFactory $fixtureFactory, + UserEdit $userEdit, + UserIndex $userIndex ) { $this->pageCustomerIndex = $pageCustomerIndex; $this->pageCustomerIndexNew = $pageCustomerIndexNew; $this->fixtureFactory = $fixtureFactory; + $this->userEdit = $userEdit; + $this->userIndex = $userIndex; } /** @@ -90,6 +117,8 @@ public function __inject( * @param Customer $customer * @param string $customerAction * @param Address $address + * @param array $steps + * @param array $beforeActionCallback * @return void */ public function test( @@ -99,6 +128,7 @@ public function test( array $steps = [], array $beforeActionCallback = [] ) { + $this->steps = $steps; ///Process initialize steps foreach ($steps as $methodName => $stepData) { if (method_exists($this, $methodName)) { @@ -229,4 +259,49 @@ protected function configureAllowedCountries(array $countryList = []) ]; } } + + /** + * Change Admin locale. + * + * @param array $userData + */ + private function changeAdminLocale(array $userData) + { + /** @var User $adminUser */ + $adminUser = $this->fixtureFactory->createByCode('user', ['data' => $userData]); + $this->userIndex->open(); + $this->userIndex->getUserGrid()->searchAndOpen(['username' => $adminUser->getUsername()]); + $this->userEdit->getUserForm()->fill($adminUser); + $this->userEdit->getPageActions()->save(); + } + + /** + * Revert Admin locale. + * + * @param array $userData + */ + private function changeAdminLocaleRollback(array $userData) + { + /** @var User $defaultAdminUser */ + $defaultAdminUser = $this->fixtureFactory->createByCode('user'); + $adminUserData = $defaultAdminUser->getData(); + unset($adminUserData['user_id']); + $defaultAdminUser = $this->fixtureFactory->createByCode('user', ['data' => $adminUserData]); + $this->userIndex->open(); + $this->userIndex->getUserGrid()->searchAndOpen(['username' => $defaultAdminUser->getUsername()]); + $this->userEdit->getUserForm()->fill($defaultAdminUser); + $this->userEdit->getPageActions()->save(); + } + + /** + * @inheritdoc + */ + protected function tearDown() + { + foreach ($this->steps as $key => $stepData) { + if (method_exists($this, $key . 'Rollback')) { + call_user_func_array([$this, $key . 'Rollback'], $stepData); + } + } + } } diff --git a/dev/tests/functional/tests/app/Magento/Customer/Test/TestCase/CreateCustomerBackendEntityTest.xml b/dev/tests/functional/tests/app/Magento/Customer/Test/TestCase/CreateCustomerBackendEntityTest.xml index 8c69da313debf..83dd382f0632d 100644 --- a/dev/tests/functional/tests/app/Magento/Customer/Test/TestCase/CreateCustomerBackendEntityTest.xml +++ b/dev/tests/functional/tests/app/Magento/Customer/Test/TestCase/CreateCustomerBackendEntityTest.xml @@ -159,5 +159,27 @@ + + save + Main Website + General + John%isolation% + Doe%isolation% + JohnDoe%isolation%@example.com + 03/29/2004 + + + + admin + English (United Kingdom) + 123123q + + + + en_GB + + + + diff --git a/dev/tests/functional/tests/app/Magento/User/Test/Block/Adminhtml/User/UserForm.xml b/dev/tests/functional/tests/app/Magento/User/Test/Block/Adminhtml/User/UserForm.xml index 8ebc6023c3d26..91d2afdd62db6 100644 --- a/dev/tests/functional/tests/app/Magento/User/Test/Block/Adminhtml/User/UserForm.xml +++ b/dev/tests/functional/tests/app/Magento/User/Test/Block/Adminhtml/User/UserForm.xml @@ -17,6 +17,9 @@ + + select + select diff --git a/dev/tests/functional/tests/app/Magento/User/Test/Repository/User.xml b/dev/tests/functional/tests/app/Magento/User/Test/Repository/User.xml index bfcfd3c13c307..bc2c120289a1f 100644 --- a/dev/tests/functional/tests/app/Magento/User/Test/Repository/User.xml +++ b/dev/tests/functional/tests/app/Magento/User/Test/Repository/User.xml @@ -16,6 +16,7 @@ 123123q 123123q %current_password% + English (United States)