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 PermissionCheckCommandTest 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
|
|
|
public function provideSimpleCase() |
33
|
|
|
{ |
34
|
|
|
return array( |
35
|
|
|
array('foobar', 'alice', 'PROJECT_READ', true ), |
36
|
|
|
array('barbaz', 'bob', 'PROJECT_READ', false ), |
37
|
|
|
array(null, 'admin', 'ROLE_ADMIN', true ), |
38
|
|
|
array(null, 'alice', 'ROLE_ADMIN', false ), |
39
|
|
|
); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @dataProvider provideSimpleCase |
44
|
|
|
*/ |
45
|
|
|
public function testSimpleCase($projectSlug, $username, $permission, $expected) |
46
|
|
|
{ |
47
|
|
|
$projectSuffix = $projectSlug === null ? '' : '--project='.$projectSlug; |
48
|
|
|
|
49
|
|
|
$command = sprintf('fabrica:permission-check %s %s %s', $projectSuffix, $username, $permission); |
50
|
|
|
list($statusCode, $output) = $this->runCommand($this->client, $command); |
51
|
|
|
|
52
|
|
|
$this->assertEquals($statusCode, $expected ? 0 : 1); |
53
|
|
|
$this->assertEquals('', $output); // Output must be empty, otherwise displayed to user pushing |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|