the browser-facing portion of osu!
at master 1.6 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\Libraries; 7 8use App\Libraries\BBCodeFromDB; 9use Tests\TestCase; 10 11class BBCodeFromDBTest extends TestCase 12{ 13 /** 14 * @dataProvider examples 15 */ 16 public function testGenerateHTML($name, $path) 17 { 18 $dbFilePath = "{$path}/{$name}.db.txt"; 19 $htmlFilePath = "{$path}/{$name}.html"; 20 21 $text = new BBCodeFromDB(''); 22 $text->text = trim(file_get_contents($dbFilePath)); 23 24 $output = $this->normalizeHTML($text->toHTML()); 25 $referenceOutput = $this->normalizeHTML("<div class='bbcode'>".file_get_contents($htmlFilePath).'</div>'); 26 27 $this->assertSame($referenceOutput, $output); 28 } 29 30 /** 31 * @dataProvider removeQuoteExamples 32 */ 33 public function testRemoveBlockQuotes($name, $path) 34 { 35 $dbFilePath = "{$path}/{$name}.db.txt"; 36 $expectedFilePath = "{$path}/{$name}.expected.txt"; 37 38 $text = BBCodeFromDB::removeBlockQuotes(file_get_contents($dbFilePath)); 39 40 $this->assertStringEqualsFile($expectedFilePath, $text); 41 } 42 43 public static function examples() 44 { 45 return static::fileList(__DIR__.'/bbcode_examples', '.db.txt'); 46 } 47 48 public static function removeQuoteExamples() 49 { 50 return static::fileList(__DIR__.'/bbcode_examples/remove_quotes', '.db.txt'); 51 } 52 53 protected function setUp(): void 54 { 55 parent::setUp(); 56 57 config_set('osu.bbcode.uid', '1'); 58 } 59}