Skip to content

Commit

Permalink
Merge branch '3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
crynobone committed Apr 19, 2015
2 parents 1eeaf74 + f61d410 commit d9fc948
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 16 deletions.
7 changes: 7 additions & 0 deletions .php_cs
Expand Up @@ -24,12 +24,16 @@ return Symfony\CS\Config\Config::create()
'multiline_array_trailing_comma',
'new_with_braces',
'no_blank_lines_after_class_opening',
'no_blank_lines_before_namespace',
'no_empty_lines_after_phpdocs',
'object_operator',
'operators_spaces',
'phpdoc_indent',
'phpdoc_no_access',
'-phpdoc_no_empty_return',
'phpdoc_no_package',
'-phpdoc_params',
'phpdoc_scalar',
'phpdoc_separation',
'phpdoc_short_description',
'phpdoc_to_comment',
Expand All @@ -40,8 +44,11 @@ return Symfony\CS\Config\Config::create()
'remove_leading_slash_use',
'remove_lines_between_uses',
'short_array_syntax',
'single_quote',
'spaces_cast',
'standardize_not_equal',
'ternary_spaces',
'trim_array_spaces',
'unused_use',
'whitespacy_lines',
'visibility',
Expand Down
2 changes: 1 addition & 1 deletion src/Auth/CommandServiceProvider.php
Expand Up @@ -8,7 +8,7 @@ class CommandServiceProvider extends ServiceProvider
/**
* Indicates if loading of the provider is deferred.
*
* @var boolean
* @var bool
*/
protected $defer = true;

Expand Down
6 changes: 3 additions & 3 deletions src/Authorization/Authorization.php
Expand Up @@ -161,9 +161,9 @@ public function sync()
$name = $this->name;

$this->memory->put("acl_{$name}", [
"acl" => $this->acl,
"actions" => $this->actions->get(),
"roles" => $this->roles->get(),
'acl' => $this->acl,
'actions' => $this->actions->get(),
'roles' => $this->roles->get(),
]);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Authorization/AuthorizationServiceProvider.php
Expand Up @@ -7,7 +7,7 @@ class AuthorizationServiceProvider extends ServiceProvider
/**
* Indicates if loading of the provider is deferred.
*
* @var boolean
* @var bool
*/
protected $defer = true;

Expand Down
2 changes: 1 addition & 1 deletion src/Authorization/Fluent.php
Expand Up @@ -131,7 +131,7 @@ public function filter($request)
*
* @param mixed $name
*
* @return integer|null
* @return int|null
*/
public function findKey($name)
{
Expand Down
64 changes: 58 additions & 6 deletions tests/Authorization/AuthorizationTest.php
Expand Up @@ -28,9 +28,9 @@ class AuthorizationTest extends \PHPUnit_Framework_TestCase
public function setUp()
{
$this->app = new IlluminateContainer();
$this->app['auth'] = $auth = m::mock('\Orchestra\Auth\Guard');
$this->app['config'] = $config = m::mock('Config');
$this->app['events'] = $event = m::mock('Event');
$this->app['auth'] = $auth = m::mock('\Orchestra\Contracts\Auth\Guard');
$this->app['config'] = $config = m::mock('\Illuminate\Contracts\Config\Repository');
$this->app['events'] = $event = m::mock('\Illuminate\Contracts\Events\Dispatcher');

$auth->shouldReceive('guest')->andReturn(true)
->shouldReceive('user')->andReturn(null);
Expand Down Expand Up @@ -96,7 +96,7 @@ public function testInstanceOfStub()
$acl->setAccessible(true);

$this->assertInstanceOf('\Orchestra\Authorization\Authorization', $this->stub);
$this->assertInstanceOf('\Orchestra\Memory\Provider', $memory->getValue($this->stub));
$this->assertInstanceOf('\Orchestra\Contracts\Memory\Provider', $memory->getValue($this->stub));
$this->assertInstanceOf('\Orchestra\Authorization\Fluent', $roles->getValue($this->stub));
$this->assertInstanceOf('\Orchestra\Authorization\Fluent', $actions->getValue($this->stub));
$this->assertTrue(is_array($acl->getValue($this->stub)));
Expand Down Expand Up @@ -248,7 +248,7 @@ public function testDenyMethod()
*/
public function testCanMethodAsAdminUser()
{
$auth = m::mock('\Orchestra\Auth\Guard');
$auth = m::mock('\Orchestra\Contracts\Auth\Guard');

$auth->shouldReceive('guest')->times(4)->andReturn(false)
->shouldReceive('roles')->times(4)->andReturn(['Admin']);
Expand All @@ -267,6 +267,58 @@ public function testCanMethodAsAdminUser()
$this->assertFalse($stub->can('manage-photo'));
}

/**
* Test Orchestra\Authorization\Authorization::can() method as "normal" user.
*
* @test
*/
public function testCanMethodAsUser()
{
$auth = m::mock('\Orchestra\Contracts\Auth\Guard');

$auth->shouldReceive('guest')->times(2)->andReturn(false)
->shouldReceive('roles')->times(2)->andReturn(['Admin', 'Staff']);

$runtime = $this->getRuntimeMemoryProvider();
$runtime->put('acl_foo', $this->memoryProvider());

$stub = new Authorization($auth, 'foo', $runtime);

$stub->addRoles(['Staff']);
$stub->addActions(['Manage Application', 'Manage Photo']);
$stub->allow('Admin', ['Manage Application', 'Manage Photo']);
$stub->allow('Staff', ['Manage Photo']);

$this->assertTrue($stub->can('manage application'));
$this->assertTrue($stub->can('manage photo'));
}

/**
* Test Orchestra\Authorization\Authorization::can() method as "normal" user.
*
* @test
*/
public function testCanMethodAsUserShouldNotBeAffectedByRoleOrder()
{
$auth = m::mock('\Orchestra\Contracts\Auth\Guard');

$auth->shouldReceive('guest')->times(2)->andReturn(false)
->shouldReceive('roles')->times(2)->andReturn(['Staff', 'Admin']);

$runtime = $this->getRuntimeMemoryProvider();
$runtime->put('acl_foo', $this->memoryProvider());

$stub = new Authorization($auth, 'foo', $runtime);

$stub->addRoles(['Staff']);
$stub->addActions(['Manage Application', 'Manage Photo']);
$stub->allow('Admin', ['Manage Application', 'Manage Photo']);
$stub->allow('Staff', ['Manage Photo']);

$this->assertTrue($stub->can('manage application'));
$this->assertTrue($stub->can('manage photo'));
}

/**
* Test Orchestra\Authorization\Authorization::can() method as "guest" user.
*
Expand Down Expand Up @@ -368,7 +420,7 @@ public function testMemoryIsProperlySync()
$roles->setAccessible(true);
$actions->setAccessible(true);

$this->assertInstanceOf('\Orchestra\Memory\Provider', $memory->getValue($stub));
$this->assertInstanceOf('\Orchestra\Contracts\Memory\Provider', $memory->getValue($stub));
$this->assertInstanceOf('\Orchestra\Authorization\Fluent', $roles->getValue($stub));

$this->assertTrue($stub->roles()->has('guest'));
Expand Down
8 changes: 4 additions & 4 deletions tests/Authorization/FactoryTest.php
Expand Up @@ -20,7 +20,7 @@ public function tearDown()
*/
public function testMakeMethod()
{
$auth = m::mock('\Orchestra\Auth\Guard');
$auth = m::mock('\Orchestra\Contracts\Auth\Guard');
$stub = new Factory($auth);

$this->assertInstanceOf('\Orchestra\Authorization\Authorization', $stub->make('mock-one'));
Expand All @@ -39,7 +39,7 @@ public function testMakeMethod()
*/
public function testRegisterMethod()
{
$auth = m::mock('\Orchestra\Auth\Guard');
$auth = m::mock('\Orchestra\Contracts\Auth\Guard');
$stub = new Factory($auth);

$auth->shouldReceive('guest')->times(3)->andReturn(true);
Expand All @@ -64,7 +64,7 @@ public function testRegisterMethod()
*/
public function testMagicMethods()
{
$auth = m::mock('\Orchestra\Auth\Guard');
$auth = m::mock('\Orchestra\Contracts\Auth\Guard');
$stub = new Factory($auth);

$acl1 = $stub->make('mock-one');
Expand Down Expand Up @@ -100,7 +100,7 @@ public function testMagicMethods()
*/
public function testAllMethod()
{
$auth = m::mock('\Orchestra\Auth\Guard');
$auth = m::mock('\Orchestra\Contracts\Auth\Guard');
$stub = new Factory($auth);

$mock1 = $stub->make('mock-one');
Expand Down

0 comments on commit d9fc948

Please sign in to comment.