the browser-facing portion of osu!
at master 92 lines 3.0 kB view raw
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\BeatmapsetEvent; 10use App\Models\User; 11use Tests\TestCase; 12 13class BeatmapsetEventTransformerTest extends TestCase 14{ 15 /** @var Beatmapset */ 16 protected $beatmapset; 17 18 /** 19 * @dataProvider dataProvider 20 */ 21 public function testWithOAuth(?string $groupIdentifier, string $eventType, bool $visibleWithOAuth) 22 { 23 $event = $this->beatmapset->events()->create([ 24 'type' => $eventType, 25 ]); 26 27 $viewer = User::factory()->withGroup($groupIdentifier)->create(); 28 $this->actAsScopedUser($viewer); 29 30 $json = json_item($event, 'BeatmapsetEvent'); 31 32 if ($visibleWithOAuth) { 33 $this->assertArrayHasKey('user_id', $json); 34 } else { 35 $this->assertArrayNotHasKey('user_id', $json); 36 } 37 } 38 39 /** 40 * @dataProvider dataProvider 41 */ 42 public function testWithoutOAuth(?string $groupIdentifier, string $eventType, bool $visibleWithOAuth, bool $visibleWithoutOAuth) 43 { 44 $event = $this->beatmapset->events()->create([ 45 'type' => $eventType, 46 ]); 47 48 $viewer = User::factory()->withGroup($groupIdentifier)->create(); 49 $this->actAsUser($viewer); 50 51 $json = json_item($event, 'BeatmapsetEvent'); 52 53 if ($visibleWithoutOAuth) { 54 $this->assertArrayHasKey('user_id', $json); 55 } else { 56 $this->assertArrayNotHasKey('user_id', $json); 57 } 58 } 59 60 public static function dataProvider() 61 { 62 // one event type of each priviledge type. 63 return [ 64 ['admin', BeatmapsetEvent::NOMINATE, true, true], // public 65 ['admin', BeatmapsetEvent::KUDOSU_ALLOW, false, true], // kudosuModeration 66 ['admin', BeatmapsetEvent::DISCUSSION_DELETE, false, true], // moderation 67 68 ['bng', BeatmapsetEvent::NOMINATE, true, true], 69 ['bng', BeatmapsetEvent::KUDOSU_ALLOW, false, true], 70 ['bng', BeatmapsetEvent::DISCUSSION_DELETE, false, false], 71 72 ['gmt', BeatmapsetEvent::NOMINATE, true, true], 73 ['gmt', BeatmapsetEvent::KUDOSU_ALLOW, false, true], 74 ['gmt', BeatmapsetEvent::DISCUSSION_DELETE, false, true], 75 76 ['nat', BeatmapsetEvent::NOMINATE, true, true], 77 ['nat', BeatmapsetEvent::KUDOSU_ALLOW, false, true], 78 ['nat', BeatmapsetEvent::DISCUSSION_DELETE, false, true], 79 80 [null, BeatmapsetEvent::NOMINATE, true, true], 81 [null, BeatmapsetEvent::KUDOSU_ALLOW, false, false], 82 [null, BeatmapsetEvent::DISCUSSION_DELETE, false, false], 83 ]; 84 } 85 86 protected function setUp(): void 87 { 88 parent::setUp(); 89 90 $this->beatmapset = Beatmapset::factory()->owner()->withDiscussion()->create(); 91 } 92}