mirror of
https://github.com/flarum/framework.git
synced 2025-02-01 00:28:29 +08:00
Fix failing tests + CS
This commit is contained in:
parent
0af6df7f95
commit
a03dcd4e3f
|
@ -33,4 +33,3 @@ class HasManyBuilder extends AbstractHasManyBuilder
|
|||
$this->actor = $actor;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -183,9 +183,7 @@ class Gate implements GateContract
|
|||
return $result;
|
||||
}
|
||||
|
||||
$callback = $this->resolveAuthCallback(
|
||||
$user, $ability, $arguments
|
||||
);
|
||||
$callback = $this->resolveAuthCallback($user, $ability, $arguments);
|
||||
|
||||
return call_user_func_array($callback, array_merge([$user], $arguments));
|
||||
}
|
||||
|
@ -224,7 +222,9 @@ class Gate implements GateContract
|
|||
} elseif (isset($this->abilities[$ability])) {
|
||||
return $this->abilities[$ability];
|
||||
} else {
|
||||
return function () { return false; };
|
||||
return function () {
|
||||
return false;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -266,9 +266,7 @@ class Gate implements GateContract
|
|||
// into the policy before methods with the arguments and get the result.
|
||||
$beforeArguments = array_merge([$user, $ability], $arguments);
|
||||
|
||||
$result = call_user_func_array(
|
||||
[$instance, 'before'], $beforeArguments
|
||||
);
|
||||
$result = call_user_func_array([$instance, 'before'], $beforeArguments);
|
||||
|
||||
// If we recieved a non-null result from the before method, we will return it
|
||||
// as the result of a check. This allows developers to override the checks
|
||||
|
@ -282,9 +280,7 @@ class Gate implements GateContract
|
|||
return false;
|
||||
}
|
||||
|
||||
return call_user_func_array(
|
||||
[$instance, $ability], array_merge([$user], $arguments)
|
||||
);
|
||||
return call_user_func_array([$instance, $ability], array_merge([$user], $arguments));
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -329,7 +325,13 @@ class Gate implements GateContract
|
|||
public function forUser($user)
|
||||
{
|
||||
return new static(
|
||||
$this->container, function () use ($user) { return $user; }, $this->abilities, $this->policies, $this->beforeCallbacks
|
||||
$this->container,
|
||||
function () use ($user) {
|
||||
return $user;
|
||||
},
|
||||
$this->abilities,
|
||||
$this->policies,
|
||||
$this->beforeCallbacks
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -31,4 +31,3 @@ class UserPolicy extends AbstractPolicy
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
namespace tests\Flarum\Admin\Middleware;
|
||||
|
||||
use Flarum\Admin\Middleware\AuthenticateWithCookie;
|
||||
use Flarum\Admin\Middleware\RequireAdministrateAbility;
|
||||
use Flarum\Core\Access\Gate;
|
||||
use Flarum\Core\Exception\PermissionDeniedException;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use Mockery as m;
|
||||
|
@ -9,19 +11,19 @@ use Psr\Http\Message\ResponseInterface;
|
|||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use tests\Test\TestCase;
|
||||
|
||||
class LoginWithCookieAndCheckAdminTest extends TestCase
|
||||
class RequireAdministrateAbilityTest extends TestCase
|
||||
{
|
||||
public function test_it_should_not_allow_invalid_logins()
|
||||
{
|
||||
$this->setExpectedException(PermissionDeniedException::class);
|
||||
|
||||
$container = m::mock(Container::class);
|
||||
$request = m::mock(ServerRequestInterface::class);
|
||||
$gate = m::mock(Gate::class);
|
||||
$request = m::mock(ServerRequestInterface::class)->shouldIgnoreMissing();
|
||||
$response = m::mock(ResponseInterface::class);
|
||||
|
||||
$request->shouldReceive('getCookieParams')->andReturn([]);
|
||||
$gate->shouldReceive('forUser->allows')->andReturn(false);
|
||||
|
||||
$middleware = new AuthenticateWithCookie($container);
|
||||
$middleware = new RequireAdministrateAbility($gate);
|
||||
$middleware->__invoke($request, $response);
|
||||
}
|
||||
}
|
|
@ -19,14 +19,14 @@ class DatabaseSettingsRepositoryTest extends TestCase
|
|||
|
||||
public function test_requesting_an_existing_setting_should_return_its_value()
|
||||
{
|
||||
$this->connection->shouldReceive("table->where->pluck")->andReturn('value');
|
||||
$this->connection->shouldReceive("table->where->value")->andReturn('value');
|
||||
|
||||
$this->assertEquals('value', $this->repository->get('key'));
|
||||
}
|
||||
|
||||
public function test_non_existent_setting_values_should_return_null()
|
||||
{
|
||||
$this->connection->shouldReceive("table->where->pluck")->andReturn(null);
|
||||
$this->connection->shouldReceive("table->where->value")->andReturn(null);
|
||||
|
||||
$this->assertEquals('default', $this->repository->get('key', 'default'));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user