diff --git a/app/code/Magento/Customer/Test/Unit/Ui/Component/DataProvider/DocumentTest.php b/app/code/Magento/Customer/Test/Unit/Ui/Component/DataProvider/DocumentTest.php index e9c91d8305e90..1d7905cca7941 100644 --- a/app/code/Magento/Customer/Test/Unit/Ui/Component/DataProvider/DocumentTest.php +++ b/app/code/Magento/Customer/Test/Unit/Ui/Component/DataProvider/DocumentTest.php @@ -13,6 +13,8 @@ use Magento\Customer\Ui\Component\DataProvider\Document; use Magento\Framework\Api\AttributeValue; use Magento\Framework\Api\AttributeValueFactory; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\Phrase; use Magento\Store\Api\Data\WebsiteInterface; use Magento\Store\Model\StoreManagerInterface; use PHPUnit_Framework_MockObject_MockObject as MockObject; @@ -44,6 +46,11 @@ class DocumentTest extends \PHPUnit\Framework\TestCase */ private $storeManager; + /** + * @var ScopeConfigInterface|MockObject + */ + private $scopeConfig; + /** * @var Document */ @@ -59,11 +66,14 @@ protected function setUp() $this->storeManager = $this->getMockForAbstractClass(StoreManagerInterface::class); + $this->scopeConfig = $this->getMockForAbstractClass(ScopeConfigInterface::class); + $this->document = new Document( $this->attributeValueFactory, $this->groupRepository, $this->customerMetadata, - $this->storeManager + $this->storeManager, + $this->scopeConfig ); } @@ -156,6 +166,41 @@ public function testGetWebsiteAttribute() static::assertEquals('Main Website', $attribute->getValue()); } + /** + * @covers \Magento\Customer\Ui\Component\DataProvider\Document::getCustomAttribute + */ + public function testGetConfirmationAttribute() + { + $websiteId = 1; + $this->document->setData('original_website_id', $websiteId); + + $this->scopeConfig->expects(static::once()) + ->method('getValue') + ->with() + ->willReturn(true); + + $this->document->setData('confirmation', null); + $attribute = $this->document->getCustomAttribute('confirmation'); + + $value = $attribute->getValue(); + static::assertInstanceOf(Phrase::class, $value); + static::assertEquals('Confirmed', (string)$value); + } + + /** + * @covers \Magento\Customer\Ui\Component\DataProvider\Document::getCustomAttribute + */ + public function testGetAccountLockValue() + { + $this->document->setData('lock_expires', null); + + $attribute = $this->document->getCustomAttribute('lock_expires'); + + $value = $attribute->getValue(); + static::assertInstanceOf(Phrase::class, $value); + static::assertEquals('Unlocked', (string)$value); + } + /** * Create mock for attribute value factory * @return void diff --git a/app/code/Magento/Customer/Ui/Component/DataProvider/Document.php b/app/code/Magento/Customer/Ui/Component/DataProvider/Document.php index f5cd5cac62d86..a9a5c5b17744e 100644 --- a/app/code/Magento/Customer/Ui/Component/DataProvider/Document.php +++ b/app/code/Magento/Customer/Ui/Component/DataProvider/Document.php @@ -6,9 +6,13 @@ namespace Magento\Customer\Ui\Component\DataProvider; use Magento\Customer\Api\CustomerMetadataInterface; +use Magento\Customer\Model\AccountManagement; use Magento\Framework\Api\AttributeValueFactory; +use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\Exception\NoSuchEntityException; use Magento\Customer\Api\GroupRepositoryInterface; +use Magento\Framework\App\ObjectManager; +use Magento\Store\Model\ScopeInterface; use Magento\Store\Model\StoreManagerInterface; /** @@ -31,6 +35,21 @@ class Document extends \Magento\Framework\View\Element\UiComponent\DataProvider\ */ private static $websiteAttributeCode = 'website_id'; + /** + * @var string + */ + private static $websiteIdAttributeCode = 'original_website_id'; + + /** + * @var string + */ + private static $confirmationAttributeCode = 'confirmation'; + + /** + * @var string + */ + private static $accountLockAttributeCode = 'lock_expires'; + /** * @var CustomerMetadataInterface */ @@ -46,23 +65,31 @@ class Document extends \Magento\Framework\View\Element\UiComponent\DataProvider\ */ private $storeManager; + /** + * @var ScopeConfigInterface + */ + private $scopeConfig; + /** * Document constructor. * @param AttributeValueFactory $attributeValueFactory * @param GroupRepositoryInterface $groupRepository * @param CustomerMetadataInterface $customerMetadata * @param StoreManagerInterface $storeManager + * @param ScopeConfigInterface $scopeConfig */ public function __construct( AttributeValueFactory $attributeValueFactory, GroupRepositoryInterface $groupRepository, CustomerMetadataInterface $customerMetadata, - StoreManagerInterface $storeManager + StoreManagerInterface $storeManager, + ScopeConfigInterface $scopeConfig = null ) { parent::__construct($attributeValueFactory); $this->customerMetadata = $customerMetadata; $this->groupRepository = $groupRepository; $this->storeManager = $storeManager; + $this->scopeConfig = $scopeConfig ?: ObjectManager::getInstance()->create(ScopeConfigInterface::class); } /** @@ -80,6 +107,12 @@ public function getCustomAttribute($attributeCode) case self::$websiteAttributeCode: $this->setWebsiteValue(); break; + case self::$confirmationAttributeCode: + $this->setConfirmationValue(); + break; + case self::$accountLockAttributeCode: + $this->setAccountLockValue(); + break; } return parent::getCustomAttribute($attributeCode); } @@ -133,5 +166,49 @@ private function setWebsiteValue() $value = $this->getData(self::$websiteAttributeCode); $list = $this->storeManager->getWebsites(); $this->setCustomAttribute(self::$websiteAttributeCode, $list[$value]->getName()); + $this->setCustomAttribute(self::$websiteIdAttributeCode, $value); + } + + /** + * Update confirmation value + * Method set confirmation text value to match what is shown in grid + * @return void + */ + private function setConfirmationValue() + { + $value = $this->getData(self::$confirmationAttributeCode); + $websiteId = $this->getData(self::$websiteIdAttributeCode) ?: $this->getData(self::$websiteAttributeCode); + $isConfirmationRequired = (bool)$this->scopeConfig->getValue( + AccountManagement::XML_PATH_IS_CONFIRM, + ScopeInterface::SCOPE_WEBSITES, + $websiteId + ); + + $valueText = __('Confirmation Not Required'); + if ($isConfirmationRequired) { + $valueText = $value === null ? __('Confirmed') : __('Confirmation Required'); + } + + $this->setCustomAttribute(self::$confirmationAttributeCode, $valueText); + } + + /** + * Update lock expires value + * Method set account lock text value to match what is shown in grid + * @return void + */ + private function setAccountLockValue() + { + $value = $this->getDataByPath(self::$accountLockAttributeCode); + + $valueText = __('Unlocked'); + if ($value !== null) { + $lockExpires = new \DateTime($value); + if ($lockExpires > new \DateTime()) { + $valueText = __('Locked'); + } + } + + $this->setCustomAttribute(self::$accountLockAttributeCode, $valueText); } }