the browser-facing portion of osu!
at master 3.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 6namespace Tests\Controllers; 7 8use App\Models\LegacyMatch\Event; 9use App\Models\LegacyMatch\LegacyMatch; 10use App\Models\User; 11use Tests\TestCase; 12 13class MatchesControllerTest extends TestCase 14{ 15 private $privateMatch; 16 private $privateMatchRoute; 17 private $publicMatch; 18 private $publicMatchRoute; 19 private $user; 20 21 public function testPublicMatchLoggedOut() // OK 22 { 23 $this 24 ->get($this->publicMatchRoute) 25 ->assertStatus(200); 26 } 27 28 public function testPublicMatchLoggedInNotParticipated() // OK 29 { 30 $this 31 ->actingAs($this->user) 32 ->get($this->publicMatchRoute) 33 ->assertStatus(200); 34 } 35 36 public function testPublicMatchLoggedInParticipated() // OK 37 { 38 Event::factory()->join()->create([ 39 'user_id' => $this->user->user_id, 40 'match_id' => $this->publicMatch->match_id, 41 ]); 42 43 $this 44 ->actingAs($this->user) 45 ->get($this->publicMatchRoute) 46 ->assertStatus(200); 47 } 48 49 public function testPrivateMatchLoggedOut() // Login Required 50 { 51 $this 52 ->get($this->privateMatchRoute) 53 ->assertSeeText('Please sign in to continue') 54 ->assertStatus(401); 55 } 56 57 public function testPrivateMatchLoggedInNotParticipated() // Access Denied 58 { 59 $this 60 ->actingAs($this->user) 61 ->get($this->privateMatchRoute) 62 ->assertStatus(403); 63 } 64 65 public function testPrivateMatchLoggedInHost() // OK 66 { 67 Event::factory()->stateCreate()->create([ 68 'user_id' => $this->user->user_id, 69 'match_id' => $this->privateMatch->match_id, 70 ]); 71 72 $this 73 ->actingAs($this->user) 74 ->get($this->privateMatchRoute) 75 ->assertStatus(200); 76 } 77 78 public function testPrivateMatchLoggedInParticipated() // OK 79 { 80 Event::factory()->join()->create([ 81 'user_id' => $this->user->user_id, 82 'match_id' => $this->privateMatch->match_id, 83 ]); 84 85 $this 86 ->actingAs($this->user) 87 ->get($this->privateMatchRoute) 88 ->assertStatus(200); 89 } 90 91 protected function setUp(): void 92 { 93 parent::setUp(); 94 95 $this->user = User::factory()->create(); 96 97 $this->publicMatch = LegacyMatch::factory()->create(); 98 Event::factory()->stateCreate()->create([ 99 'match_id' => $this->publicMatch->match_id, 100 ]); 101 $this->publicMatchRoute = route('matches.show', $this->publicMatch->match_id); 102 103 $this->privateMatch = LegacyMatch::factory()->private()->create(); 104 Event::factory()->stateCreate()->create([ 105 'match_id' => $this->privateMatch->match_id, 106 ]); 107 $this->privateMatchRoute = route('matches.show', $this->privateMatch->match_id); 108 } 109}