diff --git a/app/code/Magento/Customer/Test/Unit/Ui/Component/Listing/Column/AccountLockTest.php b/app/code/Magento/Customer/Test/Unit/Ui/Component/Listing/Column/AccountLockTest.php index c72cf9fddd0b7043759b0c1706e3018f51bce174..c6f113d56c38f587ffa10c0d21f3d6fe8a5c2ac2 100644 --- a/app/code/Magento/Customer/Test/Unit/Ui/Component/Listing/Column/AccountLockTest.php +++ b/app/code/Magento/Customer/Test/Unit/Ui/Component/Listing/Column/AccountLockTest.php @@ -46,27 +46,9 @@ class AccountLockTest extends \PHPUnit_Framework_TestCase */ public function testPrepareDataSource($lockExpirationDate, $expectedResult) { - $dataSource = [ - 'data' => [ - 'items' => [ - [ - 'lock_expires' => $lockExpirationDate - ], - ] - ] - ]; - $expectedDataSource = [ - 'data' => [ - 'items' => [ - [ - 'lock_expires' => $expectedResult, - ], - ] - ] - ]; - $dataSource = $this->component->prepareDataSource($dataSource); + $dataSource = $this->component->prepareDataSource($lockExpirationDate); - $this->assertEquals($expectedDataSource, $dataSource); + $this->assertEquals($expectedResult, $dataSource); } /** @@ -76,13 +58,77 @@ class AccountLockTest extends \PHPUnit_Framework_TestCase { return [ [ - 'lockExpirationDate' => date("F j, Y", strtotime('-1 days')), - 'expectedResult' => new \Magento\Framework\Phrase('Unlocked') + 'lockExpirationDate' => [ + 'data' => [ + 'items' => [['lock_expires' => null]], + ] + ], + 'expectedResult' => [ + 'data' => [ + 'items' => [ + [ + 'lock_expires' => new \Magento\Framework\Phrase('Unlocked') + ], + ] + ] + ] ], [ - 'lockExpirationDate' => date("F j, Y", strtotime('+1 days')), - 'expectedResult' => new \Magento\Framework\Phrase('Locked') - ] + 'lockExpirationDate' => [ + 'data' => [ + 'items' => [[]]//Non exist lock_expires data + ] + ], + 'expectedResult' => [ + 'data' => [ + 'items' => [ + [ + 'lock_expires' => new \Magento\Framework\Phrase('Unlocked') + ], + ] + ] + ] + ], + [ + 'lockExpirationDate' => [ + 'data' => [ + 'items' => [ + [ + 'lock_expires' => date("F j, Y", strtotime('-1 days')) + ], + ] + ] + ], + 'expectedResult' => [ + 'data' => [ + 'items' => [ + [ + 'lock_expires' => new \Magento\Framework\Phrase('Unlocked') + ], + ] + ] + ] + ], + [ + 'lockExpirationDate' => [ + 'data' => [ + 'items' => [ + [ + 'lock_expires' => date("F j, Y", strtotime('+1 days')) + ], + ] + ] + ], + 'expectedResult' => [ + 'data' => [ + 'items' => [ + [ + 'lock_expires' => new \Magento\Framework\Phrase('Locked') + ], + ] + ] + ] + ], ]; } } diff --git a/app/code/Magento/Customer/Ui/Component/Listing/Column/AccountLock.php b/app/code/Magento/Customer/Ui/Component/Listing/Column/AccountLock.php index 5e2e92e1c933e070c04b26713c067c51d14397e5..3622829f53f0cfd74c82820d32f56f6a11bb91ee 100644 --- a/app/code/Magento/Customer/Ui/Component/Listing/Column/AccountLock.php +++ b/app/code/Magento/Customer/Ui/Component/Listing/Column/AccountLock.php @@ -41,9 +41,13 @@ class AccountLock extends Column { if (isset($dataSource['data']['items'])) { foreach ($dataSource['data']['items'] as & $item) { - $lockExpires = new \DateTime($item['lock_expires']); - if ($lockExpires > new \DateTime()) { - $item['lock_expires'] = __('Locked'); + if (array_key_exists('lock_expires', $item)) { + $lockExpires = new \DateTime($item['lock_expires']); + if ($lockExpires > new \DateTime()) { + $item['lock_expires'] = __('Locked'); + } else { + $item['lock_expires'] = __('Unlocked'); + } } else { $item['lock_expires'] = __('Unlocked'); }