openstackid/tests/TrustedSitesServiceTest.php
Sebastian Marcet 6b0d6c36af IDP Upgrade from Laravel 4.X to 5.X
In order to migrate IDP from LV 4.x to
latest LV version, following task were performed:

* Updated namespace to be complain with PSR-4
* General Refactoring: moved all DB access code
  from services to repositories.
* Migration to LV 5.X: these migration guides
  were applied
  - https://laravel.com/docs/5.3/upgrade#upgrade-5.0
  - https://laravel.com/docs/5.3/upgrade#upgrade-5.1.0
  - https://laravel.com/docs/5.3/upgrade#upgrade-5.2.0
* Improved caching: added repositories decorators
  in order to add REDIS cache to queries, entities

Change-Id: I8edf9f5fce6585129701c88bb88332f242307534
2016-11-17 18:37:40 -03:00

84 lines
2.1 KiB
PHP

<?php
use OpenId\Services\OpenIdServiceCatalog;
use Utils\Services\IAuthService;
use OpenId\Repositories\IOpenIdTrustedSiteRepository;
use OpenId\Models\IOpenIdUser;
use Auth\User;
use Repositories\EloquentOpenIdTrustedSiteRepository;
use Way\Tests\Factory;
/**
* Class TrustedSitesServiceTest
*/
class TrustedSitesServiceTest extends TestCase {
public function __construct()
{
}
protected function prepareForTests()
{
parent::prepareForTests();
}
public function tearDown()
{
Mockery::close();
}
public function testBehaviorAdd(){
$repo_mock = Mockery::mock(EloquentOpenIdTrustedSiteRepository::class);
$repo_mock->shouldReceive('add')->andReturn(true)->once();
$this->app->instance(IOpenIdTrustedSiteRepository::class, $repo_mock);
$mock_user = Mockery::mock(IOpenIdUser::class);
$mock_user->shouldReceive('getId')->andReturn(1);
$service = $this->app[OpenIdServiceCatalog::TrustedSitesService];
$res = $service->addTrustedSite($mock_user,
$realm = 'https://www.test.com',
IAuthService::AuthorizationResponse_AllowForever,
$data = array());
$this->assertTrue(!is_null($res));
}
public function testAdd(){
$service = $this->app[OpenIdServiceCatalog::TrustedSitesService];
$user = Factory::create(User::class);
$res = $service->addTrustedSite($user,
$realm = 'https://www.test.com',
IAuthService::AuthorizationResponse_AllowForever,
$data = array());
$this->assertTrue(!is_null($res));
}
public function testGetTrustedSitesByRealm(){
$realm = 'https://*.test.com';
$service = $this->app[OpenIdServiceCatalog::TrustedSitesService];
$user = Factory::create(User::class);
$res = $service->addTrustedSite($user, $realm, IAuthService::AuthorizationResponse_AllowForever, $data = array('email','profile','address'));
$this->assertTrue(!is_null($res));
$sites = $service->getTrustedSites($user,'https://www.dev.test.com', $data = array('email','address'));
$this->assertTrue(is_array($sites));
$this->assertTrue(count($sites)>0);
}
}