1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the WoW-Apps/Symfony-Slack-Bot bundle for Symfony 3 |
4
|
|
|
* https://github.com/wow-apps/symfony-slack-bot |
5
|
|
|
* |
6
|
|
|
* (c) 2016 WoW-Apps |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace WowApps\SlackBundle\Tests\Traits; |
13
|
|
|
|
14
|
|
|
use WowApps\SlackBundle\Tests\TestCase; |
15
|
|
|
use WowApps\SlackBundle\Traits\SlackMessageTrait; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Trait SlackMessageTrait Test |
19
|
|
|
* |
20
|
|
|
* @author Alexey Samara <[email protected]> |
21
|
|
|
* @package WowApps\SlackBundle |
22
|
|
|
*/ |
23
|
|
|
class SlackMessageTraitTest extends TestCase |
24
|
|
|
{ |
25
|
|
|
use SlackMessageTrait; |
26
|
|
|
|
27
|
|
View Code Duplication |
public function testInlineMultilines() |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
$lines = []; |
30
|
|
|
for ($i = rand(parent::ARRAY_MIN_ITEMS, parent::ARRAY_MAX_ITEMS); $i <= parent::ARRAY_MAX_ITEMS; ++$i) { |
31
|
|
|
$randomString = $this->randomString(); |
32
|
|
|
$lines[] = $randomString; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
$expect = implode("\n", $lines); |
36
|
|
|
$actual = $this->inlineMultilines($lines); |
37
|
|
|
|
38
|
|
|
$this->assertEquals($expect, $actual); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
View Code Duplication |
public function testFormatBold() |
|
|
|
|
42
|
|
|
{ |
43
|
|
|
$randomString = $this->randomString(); |
44
|
|
|
$expect = sprintf('*%s*', $randomString); |
45
|
|
|
$actual = $this->formatBold($randomString); |
46
|
|
|
|
47
|
|
|
$this->assertEquals($expect, $actual); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
View Code Duplication |
public function testFormatItalic() |
|
|
|
|
51
|
|
|
{ |
52
|
|
|
$randomString = $this->randomString(); |
53
|
|
|
$expect = sprintf('_%s_', $randomString); |
54
|
|
|
$actual = $this->formatItalic($randomString); |
55
|
|
|
|
56
|
|
|
$this->assertEquals($expect, $actual); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
View Code Duplication |
public function testFormatStrikeThought() |
|
|
|
|
60
|
|
|
{ |
61
|
|
|
$randomString = $this->randomString(); |
62
|
|
|
$expect = sprintf('~%s~', $randomString); |
63
|
|
|
$actual = $this->formatStrikeThought($randomString); |
64
|
|
|
|
65
|
|
|
$this->assertEquals($expect, $actual); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function testFormatListMarker() |
69
|
|
|
{ |
70
|
|
|
$lines = []; |
71
|
|
|
for ($i = rand(parent::ARRAY_MIN_ITEMS, parent::ARRAY_MAX_ITEMS); $i <= parent::ARRAY_MAX_ITEMS; ++$i) { |
72
|
|
|
$randomString = $this->randomString(); |
73
|
|
|
$lines[] = $randomString; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
$expect = "\n"; |
77
|
|
|
foreach ($lines as $line) { |
78
|
|
|
$expect .= "• " . $line . "\n"; |
79
|
|
|
} |
80
|
|
|
$actual = $this->formatListMarker($lines); |
81
|
|
|
|
82
|
|
|
$this->assertEquals($expect, $actual); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function testFormatListNumeric() |
86
|
|
|
{ |
87
|
|
|
$lines = []; |
88
|
|
|
for ($i = rand(parent::ARRAY_MIN_ITEMS, parent::ARRAY_MAX_ITEMS); $i <= parent::ARRAY_MAX_ITEMS; ++$i) { |
89
|
|
|
$randomString = $this->randomString(); |
90
|
|
|
$lines[] = $randomString; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
$expect = "\n"; |
94
|
|
|
foreach ($lines as $key => $line) { |
95
|
|
|
$expect .= sprintf("%d. %s\n", $key + 1, $line); |
96
|
|
|
} |
97
|
|
|
$actual = $this->formatListNumeric($lines); |
98
|
|
|
|
99
|
|
|
$this->assertEquals($expect, $actual); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
View Code Duplication |
public function testFormatCode() |
|
|
|
|
103
|
|
|
{ |
104
|
|
|
$lines = []; |
105
|
|
|
for ($i = rand(parent::ARRAY_MIN_ITEMS, parent::ARRAY_MAX_ITEMS); $i <= parent::ARRAY_MAX_ITEMS; ++$i) { |
106
|
|
|
$randomString = $this->randomString(); |
107
|
|
|
$lines[] = $randomString; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
$expect = sprintf( |
111
|
|
|
"%s%s%s", |
112
|
|
|
"\n```", |
113
|
|
|
$this->inlineMultilines($lines), |
114
|
|
|
"```\n" |
115
|
|
|
); |
116
|
|
|
$actual = $this->formatCode($lines); |
117
|
|
|
|
118
|
|
|
$this->assertEquals($expect, $actual); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public function testNewLine() |
122
|
|
|
{ |
123
|
|
|
$expect = "\n"; |
124
|
|
|
$actual = $this->newLine(); |
125
|
|
|
|
126
|
|
|
$this->assertEquals($expect, $actual); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
public function testFormatLink() |
130
|
|
|
{ |
131
|
|
|
$url = $this->randomString(); |
132
|
|
|
$title = $this->randomString(); |
133
|
|
|
|
134
|
|
|
$expect = sprintf("<%s|%s>", $url, $title); |
135
|
|
|
$actual = $this->formatLink($title, $url); |
136
|
|
|
|
137
|
|
|
$this->assertEquals($expect, $actual); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
public function testEscapeCharacters() |
141
|
|
|
{ |
142
|
|
|
$expect = $testString = $this->randomString() . '<&>'; |
143
|
|
|
$expect = str_replace('&', '&', $expect); |
144
|
|
|
$expect = str_replace('<', '<', $expect); |
145
|
|
|
$expect = str_replace('>', '>', $expect); |
146
|
|
|
$actual = $this->escapeCharacters($testString); |
147
|
|
|
|
148
|
|
|
$this->assertEquals($expect, $actual); |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.