the browser-facing portion of osu!
at master 1.8 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\Models\Forum; 7 8use App\Models\Forum\Post; 9use Tests\TestCase; 10 11class PostTest extends TestCase 12{ 13 public function testPostTextPresenceCheck() 14 { 15 $post = new Post(['post_text' => 'this is a content']); 16 17 $post->isValid(); 18 $this->assertFalse(isset($post->validationErrors()->all()['post_text'])); 19 } 20 21 public function testPostTextPresenceCheckEmpty() 22 { 23 $post = new Post(['post_text' => '']); 24 25 $post->isValid(); 26 $this->assertArrayHasKey('post_text', $post->validationErrors()->all()); 27 $this->assertStringContainsString('Post body is required', $post->validationErrors()->toSentence()); 28 } 29 30 public function testPostTextPresenceCheckQuoteOnly() 31 { 32 $post = new Post(['post_text' => '[quote]this is a quote[/quote]']); 33 34 $post->isValid(); 35 $this->assertArrayHasKey('base', $post->validationErrors()->all()); 36 $this->assertStringContainsString('Your reply contains only a quote', $post->validationErrors()->toSentence()); 37 } 38 39 public function testPostTextSkipPresenceCheckEmpty() 40 { 41 $post = new Post(['post_text' => '']); 42 $post->skipBodyPresenceCheck(); 43 44 $post->isValid(); 45 $this->assertFalse(isset($post->validationErrors()->all()['post_text'])); 46 } 47 48 public function testPostTextSkipPresenceCheckQuoteOnly() 49 { 50 $post = new Post(['post_text' => '[quote]this is a quote[/quote]']); 51 $post->skipBodyPresenceCheck(); 52 53 $post->isValid(); 54 $this->assertFalse(isset($post->validationErrors()->all()['post_text'])); 55 } 56}