1
0
mirror of https://github.com/flarum/core.git synced 2025-08-06 08:27:42 +02:00

Remove deprecated policy and visibility scoping events

This commit is contained in:
Alexander Skvortsov
2021-01-20 12:13:40 -05:00
parent c887093e67
commit 54fd02e839
7 changed files with 25 additions and 220 deletions

View File

@@ -118,29 +118,6 @@ class ShowTest extends TestCase
$this->assertEquals(2, Arr::get($json, 'data.relationships.posts.data.0.id'));
}
/**
* @test
*/
public function when_allowed_guests_can_see_hidden_posts()
{
/** @var Dispatcher $events */
$events = $this->app()->getContainer()->make(Dispatcher::class);
$events->listen(ScopeModelVisibility::class, function (ScopeModelVisibility $event) {
if ($event->ability === 'hidePosts') {
$event->query->whereRaw('1=1');
}
});
$response = $this->send(
$this->request('GET', '/api/discussions/4')
);
$json = json_decode($response->getBody()->getContents(), true);
$this->assertEquals(2, Arr::get($json, 'data.relationships.posts.data.0.id'));
}
/**
* @test
*/

View File

@@ -18,6 +18,7 @@ use Flarum\Tests\integration\RetrievesAuthorizedUsers;
use Flarum\Tests\integration\TestCase;
use Flarum\User\User;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Arr;
class ModelVisibilityTest extends TestCase
{
@@ -46,6 +47,27 @@ class ModelVisibilityTest extends TestCase
]);
}
/**
* @test
*/
public function when_allowed_guests_can_see_hidden_posts()
{
$this->extend(
(new Extend\ModelVisibility(CommentPost::class))
->scope(function (User $user, Builder $query) {
$query->whereRaw('1=1');
}, 'hidePosts')
);
$response = $this->send(
$this->request('GET', '/api/discussions/2')
);
$json = json_decode($response->getBody()->getContents(), true);
$this->assertEquals(1, Arr::get($json, 'data.relationships.posts.data.0.id'));
}
/**
* @test
*/