the browser-facing portion of osu!
at master 2.2 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\BeatmapDiscussion; 9use App\Models\BeatmapDiscussionPost; 10use App\Models\Beatmapset; 11use App\Models\User; 12use Tests\TestCase; 13 14class BeatmapDiscussionPostTransformerTest extends TestCase 15{ 16 /** @var BeatmapDiscussion */ 17 protected $beatmapDiscussion; 18 19 /** @var BeatmapDiscussionPost */ 20 protected $deletedPost; 21 22 /** 23 * @dataProvider groupsDataProvider 24 */ 25 public function testWithOAuth(?string $groupIdentifier) 26 { 27 $viewer = User::factory()->withGroup($groupIdentifier)->create(); 28 $this->actAsScopedUser($viewer); 29 30 $json = json_item($this->deletedPost, 'BeatmapDiscussionPost'); 31 $this->assertEmpty($json); 32 } 33 34 /** 35 * @dataProvider groupsDataProvider 36 */ 37 public function testWithoutOAuth(?string $groupIdentifier, bool $visible) 38 { 39 $viewer = User::factory()->withGroup($groupIdentifier)->create(); 40 $this->actAsUser($viewer); 41 42 $json = json_item($this->deletedPost, 'BeatmapDiscussionPost'); 43 44 if ($visible) { 45 $this->assertNotEmpty($json); 46 } else { 47 $this->assertEmpty($json); 48 } 49 } 50 51 public static function groupsDataProvider() 52 { 53 return [ 54 ['admin', true], 55 ['bng', false], 56 ['gmt', true], 57 ['nat', true], 58 [null, false], 59 ]; 60 } 61 62 protected function setUp(): void 63 { 64 parent::setUp(); 65 66 $mapper = User::factory()->create(); 67 $beatmapset = Beatmapset::factory()->owner($mapper)->withDiscussion()->create(); 68 69 $this->beatmapDiscussion = $beatmapset->beatmapDiscussions()->first(); 70 $this->beatmapDiscussion->beatmapDiscussionPosts()->saveMany(BeatmapDiscussionPost::factory()->count(2)->make()); 71 $this->deletedPost = $this->beatmapDiscussion->beatmapDiscussionPosts()->last(); 72 73 $this->deletedPost->softDeleteOrExplode($mapper); 74 } 75}