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\Beatmapset;
9use App\Models\User;
10use Tests\TestCase;
11
12class BeatmapsetDescriptionTransformerTest extends TestCase
13{
14 protected Beatmapset $beatmapset;
15 protected User $mapper;
16
17 /**
18 * @dataProvider groupsDataProvider
19 */
20 public function testWithOAuth(?string $groupIdentifier)
21 {
22 $viewer = User::factory()->withGroup($groupIdentifier)->create();
23 $this->actAsScopedUser($viewer);
24
25 $json = json_item($this->beatmapset, 'BeatmapsetDescription');
26
27 $this->assertArrayNotHasKey('bbcode', $json);
28 }
29
30 /**
31 * @dataProvider groupsDataProvider
32 */
33 public function testWithoutOAuth(?string $groupIdentifier, bool $visible)
34 {
35 $viewer = User::factory()->withGroup($groupIdentifier)->create();
36 $this->actAsUser($viewer);
37
38 $json = json_item($this->beatmapset, 'BeatmapsetDescription');
39
40 if ($visible) {
41 $this->assertArrayHasKey('bbcode', $json);
42 } else {
43 $this->assertArrayNotHasKey('bbcode', $json);
44 }
45 }
46
47 public function testUserIsGuest()
48 {
49 $json = json_item($this->beatmapset, 'BeatmapsetDescription');
50
51 $this->assertArrayHasKey('description', $json);
52 $this->assertArrayNotHasKey('bbcode', $json);
53 }
54
55 public function testUserIsMapper()
56 {
57 $this->actAsUser($this->mapper);
58
59 $json = json_item($this->beatmapset, 'BeatmapsetDescription');
60
61 $this->assertArrayHasKey('description', $json);
62 $this->assertArrayHasKey('bbcode', $json);
63 }
64
65 public function testUserIsNotMapper()
66 {
67 $this->actAsUser(User::factory()->create());
68
69 $json = json_item($this->beatmapset, 'BeatmapsetDescription');
70
71 $this->assertArrayHasKey('description', $json);
72 $this->assertArrayNotHasKey('bbcode', $json);
73 }
74
75 public static function groupsDataProvider()
76 {
77 return [
78 ['admin', true],
79 ['bng', false],
80 ['gmt', true],
81 ['nat', true],
82 [null, false],
83 ];
84 }
85
86 protected function setUp(): void
87 {
88 parent::setUp();
89
90 $this->mapper = User::factory()->create();
91 $this->beatmapset = Beatmapset::factory()->create([
92 'user_id' => $this->mapper,
93 ]);
94 }
95}