|
| 1 | +<?php namespace Tests\unit; |
| 2 | + |
| 3 | +/** |
| 4 | + * Copyright 2025 OpenStack Foundation |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * Unless required by applicable law or agreed to in writing, software |
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | + * See the License for the specific language governing permissions and |
| 13 | + * limitations under the License. |
| 14 | + **/ |
| 15 | + |
| 16 | +use LaravelDoctrine\ORM\Facades\EntityManager; |
| 17 | +use Models\OAuth2\Client; |
| 18 | +use Models\OAuth2\OAuth2OTP; |
| 19 | +use OAuth2\OAuth2Protocol; |
| 20 | +use Tests\BrowserKitTestCase; |
| 21 | +use models\oauth2\UserConsent; |
| 22 | +use Auth\User; |
| 23 | +use Utils\Services\IdentifierGenerator; |
| 24 | + |
| 25 | +/** |
| 26 | + * Class OAuth2OTPMappingTest |
| 27 | + * @package Tests\unit |
| 28 | + */ |
| 29 | +class OAuth2OTPMappingTest extends BrowserKitTestCase |
| 30 | +{ |
| 31 | + public function testOAuth2OTPPersistence() |
| 32 | + { |
| 33 | + $email = 'test@nomail.com'; |
| 34 | + $connection = 'email'; |
| 35 | + |
| 36 | + $otp = new OAuth2OTP(6, 0); |
| 37 | + $otp->setConnection($connection); |
| 38 | + $otp->setSend('1'); |
| 39 | + $otp->setValue('test value'); |
| 40 | + $otp->setNonce('test nonce');; |
| 41 | + $otp->setRedirectUrl('https://www.openstack.org/'); |
| 42 | + $otp->setScope('openid email'); |
| 43 | + $otp->setEmail($email); |
| 44 | + $otp->setPhoneNumber('1234567890'); |
| 45 | + |
| 46 | + EntityManager::persist($otp); |
| 47 | + EntityManager::flush(); |
| 48 | + EntityManager::clear(); |
| 49 | + |
| 50 | + $repo = EntityManager::getRepository(OAuth2OTP::class); |
| 51 | + $found_otp = $repo->find($otp->getId()); |
| 52 | + |
| 53 | + $this->assertInstanceOf(OAuth2OTP::class, $found_otp); |
| 54 | + $this->assertEquals($connection, $found_otp->getConnection()); |
| 55 | + $this->assertEquals($email, $found_otp->getEmail()); |
| 56 | + } |
| 57 | +} |
0 commit comments