|
| 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\Client; |
| 19 | +use Models\OAuth2\ResourceServer; |
| 20 | +use Tests\BrowserKitTestCase; |
| 21 | + |
| 22 | +/** |
| 23 | + * Class ResourceServerMappingTest |
| 24 | + * @package Tests\unit |
| 25 | + */ |
| 26 | +class ResourceServerMappingTest extends BrowserKitTestCase |
| 27 | +{ |
| 28 | + public function testClientPersistence() |
| 29 | + { |
| 30 | + $host = 'https://www.openstack.org'; |
| 31 | + |
| 32 | + $client = EntityManager::getRepository(Client::class)->findAll()[0]; |
| 33 | + $api = EntityManager::getRepository(Api::class)->findAll()[0]; |
| 34 | + |
| 35 | + $rs = new ResourceServer(); |
| 36 | + $rs->setFriendlyName('OpenStackId server 2'); |
| 37 | + $rs->setHost($host); |
| 38 | + $rs->setIps('127.0.0.1'); |
| 39 | + $rs->setActive(true); |
| 40 | + |
| 41 | + $rs->setClient($client); |
| 42 | + $rs->addApi($api); |
| 43 | + |
| 44 | + EntityManager::persist($rs); |
| 45 | + EntityManager::flush(); |
| 46 | + EntityManager::clear(); |
| 47 | + |
| 48 | + $rs_repo = EntityManager::getRepository(ResourceServer::class); |
| 49 | + $found_rs = $rs_repo->find($rs->getId()); |
| 50 | + |
| 51 | + $this->assertCount(1, $found_rs->getApis()->toArray()); |
| 52 | + $this->assertEquals($host, $found_rs->getHost()); |
| 53 | + $this->assertEquals($client->getApplicationName(), $found_rs->getClient()->getApplicationName());; |
| 54 | + } |
| 55 | +} |
0 commit comments