1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of Fabrica. |
5
|
|
|
* |
6
|
|
|
* (c) Alexandre Salomé <[email protected]> |
7
|
|
|
* (c) Julien DIDIER <[email protected]> |
8
|
|
|
* |
9
|
|
|
* This source file is subject to the GPL license that is bundled |
10
|
|
|
* with this source code in the file LICENSE. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Fabrica\Bundle\CoreBundle\Tests\Command; |
14
|
|
|
|
15
|
|
|
use Fabrica\Bundle\CoreBundle\Test\CommandTestCase; |
16
|
|
|
|
17
|
|
|
class UserRoleCreateCommandTest extends CommandTestCase |
18
|
|
|
{ |
19
|
|
|
protected $client; |
20
|
|
|
|
21
|
|
|
protected function setUp(): void |
22
|
|
|
{ |
23
|
|
|
$this->client = self::createClient(); |
24
|
|
|
$this->client->startIsolation(); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function tearDown(): void |
28
|
|
|
{ |
29
|
|
|
$this->client->stopIsolation(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
View Code Duplication |
public function testProjectRole() |
|
|
|
|
33
|
|
|
{ |
34
|
|
|
list($statusCode ,$output) = $this->runCommand($this->client, 'fabrica:user-role-create bob Developer barbaz'); |
|
|
|
|
35
|
|
|
|
36
|
|
|
$this->assertEquals("Added successfully Bob as Developer to Barbaz\n", $output); |
37
|
|
|
|
38
|
|
|
$em = $this->client->getKernel()->getContainer()->get('doctrine')->getManager(); |
39
|
|
|
|
40
|
|
|
$user = $em->getRepository('FabricaCoreBundle:User')->findOneByUsername('bob'); |
41
|
|
|
$role = $em->getRepository('FabricaCoreBundle:Role')->findOneByName('Developer'); |
42
|
|
|
$project = $em->getRepository('FabricaCoreBundle:Project')->findOneBySlug('barbaz'); |
|
|
|
|
43
|
|
|
$userRole = $em->getRepository('FabricaCoreBundle:UserRoleProject')->findOneBy( |
44
|
|
|
array( |
45
|
|
|
'user' => $user, |
46
|
|
|
'role' => $role, |
47
|
|
|
) |
48
|
|
|
); |
49
|
|
|
|
50
|
|
|
$this->assertInstanceOf('Fabrica\Models\Code\UserRoleProject', $userRole); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testGlobalRole() |
54
|
|
|
{ |
55
|
|
|
list($statusCode ,$output) = $this->runCommand($this->client, 'fabrica:user-role-create bob Administrator'); |
|
|
|
|
56
|
|
|
|
57
|
|
|
$this->assertEquals("Added successfully Bob as Administrator\n", $output); |
58
|
|
|
|
59
|
|
|
$em = $this->client->getKernel()->getContainer()->get('doctrine')->getManager(); |
60
|
|
|
|
61
|
|
|
$user = $em->getRepository('FabricaCoreBundle:User')->findOneByUsername('bob'); |
62
|
|
|
$role = $em->getRepository('FabricaCoreBundle:Role')->findOneByName('Administrator'); |
63
|
|
|
|
64
|
|
|
$this->assertTrue($user->getGlobalRoles()->contains($role)); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function testProjectRoleIncorrect() |
68
|
|
|
{ |
69
|
|
|
list($statusCode ,$output) = $this->runCommand($this->client, 'fabrica:user-role-create bob Administrator barbaz'); |
|
|
|
|
70
|
|
|
|
71
|
|
|
$this->assertContains("Cannot add a global role to a project", $output); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function testGlobalRoleIncorrect() |
75
|
|
|
{ |
76
|
|
|
list($statusCode ,$output) = $this->runCommand($this->client, 'fabrica:user-role-create bob Developer'); |
|
|
|
|
77
|
|
|
|
78
|
|
|
$this->assertContains("Cannot add a project role without project slug", $output); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.