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\Transformers;
7
8use App\Models\Beatmap;
9use App\Models\Beatmapset;
10use App\Models\User;
11use Tests\TestCase;
12
13class BeatmapTransformerTest extends TestCase
14{
15 /** @var Beatmap */
16 protected $deletedBeatmap;
17
18 /**
19 * @dataProvider groupsDataProvider
20 */
21 public function testWithOAuth(?string $groupIdentifier)
22 {
23 $viewer = User::factory()->withGroup($groupIdentifier)->create();
24 $this->actAsScopedUser($viewer);
25
26 $json = json_item($this->deletedBeatmap, 'Beatmap');
27
28 $this->assertEmpty($json);
29 }
30
31 /**
32 * @dataProvider groupsDataProvider
33 */
34 public function testWithoutOAuth(?string $groupIdentifier, bool $visible)
35 {
36 $viewer = User::factory()->withGroup($groupIdentifier)->create();
37 $this->actAsUser($viewer);
38
39 $json = json_item($this->deletedBeatmap, 'Beatmap');
40
41 if ($visible) {
42 $this->assertNotEmpty($json);
43 } else {
44 $this->assertEmpty($json);
45 }
46 }
47
48 public static function groupsDataProvider()
49 {
50 return [
51 ['admin', true],
52 ['bng', true],
53 ['gmt', true],
54 ['nat', true],
55 [null, false],
56 ];
57 }
58
59 protected function setUp(): void
60 {
61 parent::setUp();
62
63 $beatmapset = Beatmapset::factory()->deleted()->withDiscussion()->create();
64 $this->deletedBeatmap = $beatmapset->beatmaps()->first();
65 $this->deletedBeatmap->delete();
66 }
67}