|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the core-bundle package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) 2018 WEBEWEB |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace WBW\Bundle\CoreBundle\Tests\Exception; |
|
13
|
|
|
|
|
14
|
|
|
use WBW\Bundle\CoreBundle\Exception\BadUserRoleException; |
|
15
|
|
|
use WBW\Bundle\CoreBundle\Tests\AbstractTestCase; |
|
16
|
|
|
use WBW\Bundle\CoreBundle\Tests\Fixtures\Model\TestUser; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Bad user role exception test. |
|
20
|
|
|
* |
|
21
|
|
|
* @author webeweb <https://github.com/webeweb> |
|
22
|
|
|
* @package WBW\Bundle\CoreBundle\Tests\Exception |
|
23
|
|
|
*/ |
|
24
|
|
|
class BadUserRoleExceptionTest extends AbstractTestCase { |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Test __construct() |
|
28
|
|
|
* |
|
29
|
|
|
* @return void |
|
30
|
|
|
*/ |
|
31
|
|
|
public function test__construct(): void { |
|
32
|
|
|
|
|
33
|
|
|
$user = new TestUser("anonymous"); |
|
34
|
|
|
$roles = ["ROLE_ADMIN", "ROLE_USER"]; |
|
35
|
|
|
$originUrl = "https://github.com/webeweb"; |
|
36
|
|
|
$redirectUrl = "https://github.com"; |
|
37
|
|
|
|
|
38
|
|
|
$obj = new BadUserRoleException($user, $roles, $redirectUrl, $originUrl); |
|
39
|
|
|
|
|
40
|
|
|
$this->assertEquals('User "anonymous" is not allowed to access to "https://github.com/webeweb" with roles [ROLE_ADMIN,ROLE_USER]', $obj->getMessage()); |
|
41
|
|
|
|
|
42
|
|
|
$this->assertEquals($originUrl, $obj->getOriginUrl()); |
|
43
|
|
|
$this->assertEquals($redirectUrl, $obj->getRedirectUrl()); |
|
44
|
|
|
$this->assertEquals($roles, $obj->getRoles()); |
|
45
|
|
|
$this->assertSame($user, $obj->getUser()); |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|