forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPermissionServiceTest.php
More file actions
62 lines (52 loc) · 1.74 KB
/
PermissionServiceTest.php
File metadata and controls
62 lines (52 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Tests\Unit\Services;
use Mockery as m;
use Tests\TestCase;
use Pterodactyl\Models\APIPermission;
use Pterodactyl\Services\Api\PermissionService;
use Pterodactyl\Contracts\Repository\ApiPermissionRepositoryInterface;
class PermissionServiceTest extends TestCase
{
/**
* @var \Pterodactyl\Contracts\Repository\ApiPermissionRepositoryInterface
*/
protected $repository;
/**
* @var \Pterodactyl\Services\Api\PermissionService
*/
protected $service;
/**
* Setup tests.
*/
public function setUp()
{
parent::setUp();
$this->repository = m::mock(ApiPermissionRepositoryInterface::class);
$this->service = new PermissionService($this->repository);
}
/**
* Test that a new API permission can be assigned to a key.
*/
public function test_create_function()
{
$this->repository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf()
->shouldReceive('create')->with(['key_id' => 1, 'permission' => 'test-permission'])
->once()->andReturn(true);
$this->assertTrue($this->service->create(1, 'test-permission'));
}
/**
* Test that function returns an array of all the permissions available as defined on the model.
*/
public function test_get_permissions_function()
{
$this->repository->shouldReceive('getModel')->withNoArgs()->once()->andReturn(new APIPermission());
$this->assertEquals(APIPermission::CONST_PERMISSIONS, $this->service->getPermissions());
}
}