/** * @magentoDataFixture Magento/User/_files/user_with_role.php */ public function testCreateAdminAccessToken() { $adminUserNameFromFixture = 'adminUser'; $accessToken = $this->tokenService->createAdminAccessToken($adminUserNameFromFixture, \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD); $adminUserId = $this->userModel->loadByUsername($adminUserNameFromFixture)->getId(); /** @var $token TokenModel */ $token = $this->tokenModel->loadByAdminId($adminUserId)->getToken(); $this->assertEquals($accessToken, $token); }
/** * @magentoApiDataFixture Magento/User/_files/user_with_role.php */ public function testCreateAdminAccessToken() { $adminUserNameFromFixture = 'adminUser'; $serviceInfo = ['rest' => ['resourcePath' => self::RESOURCE_PATH_ADMIN_TOKEN, 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST]]; $requestData = ['username' => $adminUserNameFromFixture, 'password' => \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD]; $accessToken = $this->_webApiCall($serviceInfo, $requestData); $adminUserId = $this->userModel->loadByUsername($adminUserNameFromFixture)->getId(); /** @var $token TokenModel */ $token = $this->tokenModel->loadByAdminId($adminUserId)->getToken(); $this->assertEquals($accessToken, $token); }
/** * Make sure provided token is valid and belongs to the specified user. * * @param string $username * @param string $accessToken */ private function assertToken($username, $accessToken) { $adminUserId = $this->userModel->loadByUsername($username)->getId(); /** @var $token TokenModel */ $token = $this->tokenModel->loadByAdminId($adminUserId)->getToken(); $this->assertEquals($accessToken, $token); }
public function testLoadByAdminId() { $adminId = 1; $tokenData = 'testToken'; $data = ['token' => $tokenData]; $this->resourceMock->expects($this->once())->method('selectTokenByAdminId')->willReturn($data); $actualToken = $this->tokenModel->loadByAdminId($adminId); $this->assertEquals($this->tokenModel, $actualToken); $this->assertEquals($tokenData, $actualToken->getToken()); }