|
| 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\ApiScope; |
| 18 | +use Models\OAuth2\ApiScopeGroup; |
| 19 | +use Tests\BrowserKitTestCase; |
| 20 | + |
| 21 | +/** |
| 22 | + * Class ApiScopeGroupMappingTest |
| 23 | + * @package Tests\unit |
| 24 | + */ |
| 25 | +class ApiScopeGroupMappingTest extends BrowserKitTestCase |
| 26 | +{ |
| 27 | + public function testApiScopeGroupPersistence() |
| 28 | + { |
| 29 | + $name = 'test_group_name'; |
| 30 | + |
| 31 | + $group = new ApiScopeGroup(); |
| 32 | + $group->setName($name); |
| 33 | + $group->setActive(true); |
| 34 | + $group->setDescription('test description'); |
| 35 | + |
| 36 | + $scope = new ApiScope(); |
| 37 | + $scope->setName('test_scope_name'); |
| 38 | + $scope->setShortDescription('test short description'); |
| 39 | + $scope->setDescription('test description'); |
| 40 | + $scope->setActive(true); |
| 41 | + EntityManager::persist($scope); |
| 42 | + |
| 43 | + $group->addScope($scope); |
| 44 | + |
| 45 | + EntityManager::persist($group); |
| 46 | + EntityManager::flush(); |
| 47 | + EntityManager::clear(); |
| 48 | + |
| 49 | + $repo = EntityManager::getRepository(ApiScopeGroup::class); |
| 50 | + $found_group = $repo->find($group->getId()); |
| 51 | + |
| 52 | + $this->assertInstanceOf(ApiScopeGroup::class, $found_group); |
| 53 | + $this->assertEquals($name, $found_group->getName()); |
| 54 | + $this->assertCount(1, $found_group->getScopes()->toArray()); |
| 55 | + } |
| 56 | +} |
0 commit comments