|
| 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\Api; |
| 18 | +use Models\OAuth2\ApiEndpoint; |
| 19 | +use Models\OAuth2\ApiScope; |
| 20 | +use Tests\BrowserKitTestCase; |
| 21 | + |
| 22 | +/** |
| 23 | + * Class ApiEndpointMappingTest |
| 24 | + * @package Tests\unit |
| 25 | + */ |
| 26 | +class ApiEndpointMappingTest extends BrowserKitTestCase |
| 27 | +{ |
| 28 | + public function testApiEndpointPersistence() |
| 29 | + { |
| 30 | + $name = 'test_endpoint_name'; |
| 31 | + $route = '/api/test_endpoint'; |
| 32 | + $scope_name = 'openid'; |
| 33 | + |
| 34 | + $api = EntityManager::getRepository(Api::class)->findAll()[0]; |
| 35 | + |
| 36 | + $scope = new ApiScope(); |
| 37 | + $scope->setName($scope_name); |
| 38 | + $scope->setShortDescription('test short description'); |
| 39 | + $scope->setDescription('test description'); |
| 40 | + $scope->setActive(true); |
| 41 | + EntityManager::persist($scope); |
| 42 | + |
| 43 | + $endpoint = new ApiEndpoint(); |
| 44 | + $endpoint->setName($name); |
| 45 | + $endpoint->setRoute($route); |
| 46 | + $endpoint->setHttpMethod('GET'); |
| 47 | + $endpoint->setStatus(true); |
| 48 | + $endpoint->setAllowCors(true); |
| 49 | + $endpoint->setAllowCredentials(true); |
| 50 | + $endpoint->setApi($api); |
| 51 | + $endpoint->addScope($scope); |
| 52 | + |
| 53 | + EntityManager::persist($endpoint); |
| 54 | + EntityManager::flush(); |
| 55 | + EntityManager::clear(); |
| 56 | + |
| 57 | + $repo = EntityManager::getRepository(ApiEndpoint::class); |
| 58 | + $found_endpoint = $repo->find($endpoint->getId()); |
| 59 | + $found_scope = $found_endpoint->getScopes()[0]; |
| 60 | + |
| 61 | + $this->assertInstanceOf(ApiEndpoint::class, $found_endpoint); |
| 62 | + $this->assertInstanceOf(ApiScope::class, $found_scope); |
| 63 | + $this->assertEquals($name, $found_endpoint->getName()); |
| 64 | + $this->assertEquals($route, $found_endpoint->getRoute()); |
| 65 | + $this->assertEquals($scope_name, $found_scope->getName()); |
| 66 | + } |
| 67 | +} |
0 commit comments