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;
7
8use App\Models\Changelog;
9use App\Models\ChangelogEntry;
10use Tests\TestCase;
11
12class ChangelogEntryTest extends TestCase
13{
14 /**
15 * @dataProvider dataForGetDisplayMessage
16 */
17 public function testGetDisplayMessage($message, $html)
18 {
19 $this->assertSame($html, ChangelogEntry::getDisplayMessage($message));
20 }
21
22 public function testConvertLegacyChangelogWithTitle()
23 {
24 $title = 'Some title';
25 $legacy = new Changelog(['message' => $title]);
26 $converted = ChangelogEntry::convertLegacy($legacy);
27 $this->assertSame($title, $converted->title);
28 $this->assertNull($converted->messageHtml());
29 }
30
31 public function testConvertLegacyChangelogWithTitleAndMessage()
32 {
33 $title = 'Some title';
34 $message = 'Some message';
35 $legacy = new Changelog(['message' => "{$title}\n\n---\n{$message}"]);
36 $converted = ChangelogEntry::convertLegacy($legacy);
37 $this->assertSame($title, $converted->title);
38 $this->assertSame("<div class='changelog-md'><p class=\"changelog-md__paragraph\">{$message}</p>\n</div>", $converted->messageHtml());
39 }
40
41 public function testConvertLegacyChangelogWithMessage()
42 {
43 $message = 'Some message';
44 $legacy = new Changelog(['message' => "---\n{$message}"]);
45 $converted = ChangelogEntry::convertLegacy($legacy);
46 $this->assertSame($message, $converted->title);
47 $this->assertNull($converted->messageHtml());
48 }
49
50 public function testGuessCategoryCapitalise()
51 {
52 $data = [
53 'repository' => ['full_name' => ''],
54 'pull_request' => [
55 'labels' => [
56 ['name' => 'forum'],
57 ],
58 ],
59 ];
60
61 $this->assertSame('Forum', ChangelogEntry::guessCategory($data));
62 }
63
64 public function testGuessCategoryDashToSpace()
65 {
66 $data = [
67 'repository' => ['full_name' => ''],
68 'pull_request' => [
69 'labels' => [
70 ['name' => 'beatmapset-discussion'],
71 ],
72 ],
73 ];
74
75 $this->assertSame('Beatmapset Discussion', ChangelogEntry::guessCategory($data));
76 }
77
78 public function testGuessCategoryMixedDashAndSpaceNoConversion()
79 {
80 $data = [
81 'repository' => ['full_name' => ''],
82 'pull_request' => [
83 'labels' => [
84 ['name' => 'beatmapset - discussion'],
85 ],
86 ],
87 ];
88
89 $this->assertSame('Beatmapset - Discussion', ChangelogEntry::guessCategory($data));
90 }
91
92 public function testGuessCategoryPrefixRemoval()
93 {
94 $data = [
95 'repository' => ['full_name' => ''],
96 'pull_request' => [
97 'labels' => [
98 ['name' => 'area:forum'],
99 ],
100 ],
101 ];
102
103 $this->assertSame('Forum', ChangelogEntry::guessCategory($data));
104 }
105
106 public function testIsPrivate()
107 {
108 $data = [
109 'repository' => ['full_name' => ''],
110 'pull_request' => [
111 'labels' => [
112 ['name' => 'javascript'],
113 ['name' => 'area:forum'],
114 ],
115 ],
116 ];
117
118 $this->assertFalse(ChangelogEntry::isPrivate($data));
119
120 $data = [
121 'repository' => ['full_name' => ''],
122 'pull_request' => [
123 'labels' => [
124 ['name' => 'javascript'],
125 ['name' => 'dependencies'],
126 ],
127 ],
128 ];
129
130 $this->assertTrue(ChangelogEntry::isPrivate($data));
131 }
132
133 public static function dataForGetDisplayMessage()
134 {
135 return [
136 ['Hidden', ''],
137 ["Visible\n\n---", 'Visible'],
138 ["---\nHidden", ''],
139 ['---Hidden', ''],
140 ['Still hidden---', ''],
141 ["Hidden\n---\n\nStill hidden", ''],
142 ["Hidden\n---\nStill hidden", ''],
143 ["Visible\n\n---\nHidden", 'Visible'],
144 ];
145 }
146}