|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +namespace Magento\User\Model; |
| 8 | + |
| 9 | +use Magento\Backend\Model\Auth as AuthModel; |
| 10 | +use Magento\Framework\Exception\AuthenticationException; |
| 11 | +use Magento\Framework\Exception\LocalizedException; |
| 12 | +use Magento\Framework\ObjectManagerInterface; |
| 13 | +use Magento\TestFramework\Fixture\DataFixture; |
| 14 | +use Magento\TestFramework\Fixture\DataFixtureStorage; |
| 15 | +use Magento\TestFramework\Fixture\DataFixtureStorageManager; |
| 16 | +use Magento\TestFramework\Helper\Bootstrap; |
| 17 | +use Magento\User\Model\User as UserModel; |
| 18 | +use Magento\User\Test\Fixture\User as UserDataFixture; |
| 19 | +use PHPUnit\Framework\TestCase; |
| 20 | + |
| 21 | +/** |
| 22 | + * @magentoAppArea adminhtml |
| 23 | + */ |
| 24 | +class ValidateUserDateFieldsTest extends TestCase |
| 25 | +{ |
| 26 | + |
| 27 | + /** |
| 28 | + * @var DataFixtureStorage |
| 29 | + */ |
| 30 | + private DataFixtureStorage $fixtures; |
| 31 | + |
| 32 | + /** |
| 33 | + * @var AuthModel |
| 34 | + */ |
| 35 | + protected $authModel; |
| 36 | + |
| 37 | + /** |
| 38 | + * @var UserModel |
| 39 | + */ |
| 40 | + protected $userModel; |
| 41 | + |
| 42 | + /** |
| 43 | + * @throws LocalizedException |
| 44 | + */ |
| 45 | + protected function setUp(): void |
| 46 | + { |
| 47 | + Bootstrap::getInstance()->loadArea(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE); |
| 48 | + $objectManager = Bootstrap::getObjectManager(); |
| 49 | + $this->fixtures = DataFixtureStorageManager::getStorage(); |
| 50 | + $this->authModel = $objectManager->create(AuthModel::class); |
| 51 | + $this->userModel = $objectManager->create(UserModel::class); |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * @throws AuthenticationException |
| 56 | + */ |
| 57 | + #[ |
| 58 | + DataFixture(UserDataFixture::class, ['role_id' => 1], 'user') |
| 59 | + ] |
| 60 | + public function testLogDate() |
| 61 | + { |
| 62 | + $user = $this->fixtures->get('user'); |
| 63 | + $userName = $user->getDataByKey('username'); |
| 64 | + $this->authModel->login( |
| 65 | + $userName, |
| 66 | + \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD |
| 67 | + ); |
| 68 | + $this->userModel->loadByUsername($userName); |
| 69 | + $this->assertNotNull($this->userModel->getLogdate()); |
| 70 | + } |
| 71 | +} |
0 commit comments