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\Comment;
9use App\Models\User;
10use Tests\TestCase;
11
12class CommentTransformerTest extends TestCase
13{
14 /**
15 * @dataProvider groupsDataProvider
16 */
17 public function testWithOAuth(?string $groupIdentifier)
18 {
19 $viewer = User::factory()->withGroup($groupIdentifier)->create();
20 $comment = Comment::factory()->deleted()->create();
21 $this->actAsScopedUser($viewer);
22
23 $json = json_item($comment, 'Comment');
24
25 $this->assertArrayNotHasKey('message', $json);
26 $this->assertArrayNotHasKey('message_html', $json);
27 }
28
29 /**
30 * @dataProvider groupsDataProvider
31 */
32 public function testWithoutOAuth(?string $groupIdentifier, bool $visible)
33 {
34 $viewer = User::factory()->withGroup($groupIdentifier)->create();
35 $comment = Comment::factory()->deleted()->create();
36 $this->actAsUser($viewer);
37
38 $json = json_item($comment, 'Comment');
39
40 if ($visible) {
41 $this->assertArrayHasKey('message', $json);
42 $this->assertArrayHasKey('message_html', $json);
43 } else {
44 $this->assertArrayNotHasKey('message', $json);
45 $this->assertArrayNotHasKey('message_html', $json);
46 }
47 }
48
49 public static function groupsDataProvider()
50 {
51 return [
52 ['admin', true],
53 ['bng', false],
54 ['gmt', true],
55 ['nat', true],
56 [null, false],
57 ];
58 }
59}