the browser-facing portion of osu!
at master 2.1 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 6declare(strict_types=1); 7 8namespace Tests\Controllers; 9 10use App\Models\Chat\Channel; 11use App\Models\Chat\UserChannel; 12use App\Models\User; 13use Tests\TestCase; 14 15class ChatControllerTest extends TestCase 16{ 17 public function testRequestParamsChannelIdUnhide() 18 { 19 $sender = User::factory()->withGroup('announce')->create(); 20 $user = User::factory()->create(); 21 $channel = Channel::factory()->type('announce', [$sender, $user])->create(); 22 $fragment = ['channel_id' => $channel->getKey()]; 23 24 UserChannel::where($fragment)->update(['hidden' => true]); 25 26 $this->actAsUser($user, true); 27 $this 28 ->get(route('chat.index', $fragment)) 29 ->assertSuccessful(); 30 31 app('OsuAuthorize')->resetCache(); 32 $channel->refresh(); 33 $this->assertFalse($this->invokeMethod($channel, 'userChannelFor', [$user])->isHidden()); 34 35 app('OsuAuthorize')->resetCache(); 36 $channel->refresh(); 37 $this->assertTrue($this->invokeMethod($channel, 'userChannelFor', [$sender])->isHidden()); 38 } 39 40 public function testRequestParamsSendtoUnhide() 41 { 42 $user1 = User::factory()->create(); 43 $user2 = User::factory()->create(); 44 $channel = Channel::factory()->type('pm', [$user1, $user2])->create(); 45 $fragment = ['channel_id' => $channel->getKey()]; 46 47 UserChannel::where($fragment)->update(['hidden' => true]); 48 49 $this->actAsUser($user1, true); 50 $this 51 ->get(route('chat.index', ['sendto' => $user2->getKey()])) 52 ->assertSuccessful(); 53 54 app('OsuAuthorize')->resetCache(); 55 $channel->refresh(); 56 $this->assertFalse($this->invokeMethod($channel, 'userChannelFor', [$user1])->isHidden()); 57 58 app('OsuAuthorize')->resetCache(); 59 $channel->refresh(); 60 $this->assertTrue($this->invokeMethod($channel, 'userChannelFor', [$user2])->isHidden()); 61 } 62}