|
| 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\OpenId\OpenIdTrustedSite; |
| 19 | +use Models\UserAction; |
| 20 | +use Tests\BrowserKitTestCase; |
| 21 | +use models\oauth2\UserConsent; |
| 22 | +use Auth\User; |
| 23 | +use Utils\Services\IAuthService; |
| 24 | + |
| 25 | +/** |
| 26 | + * Class UserMappingTest |
| 27 | + * @package Tests\unit |
| 28 | + */ |
| 29 | +class UserMappingTest extends BrowserKitTestCase |
| 30 | +{ |
| 31 | + public function testUserPersistence() |
| 32 | + { |
| 33 | + $email = 'test@nomail.com'; |
| 34 | + $realm = 'https://www.test.com/'; |
| 35 | + |
| 36 | + $user = new User(); |
| 37 | + $user->setEmail($email); |
| 38 | + $user->setPassword('P@sswordS3cret'); |
| 39 | + |
| 40 | + $user_action = new UserAction(); |
| 41 | + $user_action->setFromIp("127.0.0.1"); |
| 42 | + $user_action->setUserAction("test action");; |
| 43 | + $user_action->setOwner($user); |
| 44 | + |
| 45 | + $user->addUserAction($user_action); |
| 46 | + |
| 47 | + $site = new OpenIdTrustedSite(); |
| 48 | + $site->setRealm($realm); |
| 49 | + $site->setPolicy(IAuthService::AuthorizationResponse_AllowForever); |
| 50 | + $site->setOwner($user); |
| 51 | + $site->setData(json_encode([])); |
| 52 | + $user->addTrustedSite($site); |
| 53 | + |
| 54 | + EntityManager::persist($user); |
| 55 | + EntityManager::flush(); |
| 56 | + EntityManager::clear(); |
| 57 | + |
| 58 | + $repo = EntityManager::getRepository(User::class); |
| 59 | + $found_user = $repo->find($user->getId()); |
| 60 | + $found_trusted_site = $found_user->getTrustedSites()->first(); |
| 61 | + |
| 62 | + $this->assertInstanceOf(User::class, $found_user); |
| 63 | + $this->assertEquals($email, $found_user->getEmail()); |
| 64 | + $this->assertCount(1, $user->getActions()->toArray()); |
| 65 | + $this->assertEquals($realm, $found_trusted_site->getRealm());; |
| 66 | + } |
| 67 | +} |
0 commit comments