1<?php
2
3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
4// See the LICENCE file in the repository root for full licence text.
5
6namespace Tests\Models\OAuth;
7
8use App\Models\OAuth\Client;
9use App\Models\User;
10use Tests\TestCase;
11
12class GroupPermissionTest extends TestCase
13{
14 /**
15 * TODO: maybe an exclusion list of when groups are allowed with token instead...
16 *
17 * @dataProvider groupsDataProvider
18 *
19 * @return void
20 */
21 public function testGroupWithOAuth(string $group, string $method, bool $inGroup)
22 {
23 $user = User::factory()->withGroup($group)->create();
24 $client = Client::factory()->create(['user_id' => $user]);
25 $token = $this->createToken($user, ['*'], $client);
26 $this->actAsUserWithToken($token);
27
28 $this->assertSame($inGroup, auth()->user()->$method());
29 }
30
31 /**
32 * @dataProvider groupsDataProvider
33 *
34 * @return void
35 */
36 public function testGroupWithoutOAuth(string $group, string $method)
37 {
38 $user = User::factory()->withGroup($group)->create();
39 $this->actAsUser($user);
40
41 $this->assertTrue(auth()->user()->$method());
42 }
43
44 public static function groupsDataProvider()
45 {
46 return [
47 ['admin', 'isAdmin', false],
48 ['alumni', 'isAlumni', false],
49 ['announce', 'isChatAnnouncer', true],
50 ['bng', 'isBNG', false],
51 ['bot', 'isBot', true],
52 ['dev', 'isDev', false],
53 ['gmt', 'isGMT', false],
54 ['loved', 'isProjectLoved', false],
55 ['nat', 'isNAT', false],
56 ];
57 }
58}