|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* T3Bot. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Frank Nägler <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* @link http://www.t3bot.de |
|
8
|
|
|
* @link http://wiki.typo3.org/T3Bot |
|
9
|
|
|
*/ |
|
10
|
|
|
namespace T3Bot\Tests\Unit\Commands; |
|
11
|
|
|
|
|
12
|
|
|
use T3Bot\Commands\BottyCommand; |
|
13
|
|
|
use T3Bot\Tests\Unit\BaseCommandTestCase; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Class BottyCommandTest. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
/** @noinspection LongInheritanceChainInspection */ |
|
20
|
|
|
class BottyCommandTest extends BaseCommandTestCase |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* Data provider. |
|
24
|
|
|
* |
|
25
|
|
|
* @return array |
|
26
|
|
|
*/ |
|
27
|
|
|
public function testDataProvider() |
|
28
|
|
|
{ |
|
29
|
|
|
$username = '<@U54321>'; |
|
30
|
|
|
|
|
31
|
|
|
return [ |
|
32
|
|
|
'daddy' => ['daddy', 'My daddy is Frank Nägler aka <@neoblack>'], |
|
33
|
|
|
'n8' => ['n8', 'Good night ' . $username . '! :sleeping:'], |
|
34
|
|
|
'nacht' => ['nacht', 'Good night ' . $username . '! :sleeping:'], |
|
35
|
|
|
'night' => ['night', 'Good night ' . $username . '! :sleeping:'], |
|
36
|
|
|
'hello' => ['hello', 'Hello ' . $username . ', nice to see you!'], |
|
37
|
|
|
'hallo' => ['hallo', 'Hello ' . $username . ', nice to see you!'], |
|
38
|
|
|
'ciao' => ['ciao', 'Bye, bye ' . $username . ', cu later alligator! :wave:'], |
|
39
|
|
|
'cu' => ['cu', 'Bye, bye ' . $username . ', cu later alligator! :wave:'], |
|
40
|
|
|
'thx' => ['thx', 'You are welcome ' . $username . '!'], |
|
41
|
|
|
'thank' => ['thank', 'You are welcome ' . $username . '!'], |
|
42
|
|
|
'drink' => ['drink', 'Coffee or beer ' . $username . '?'], |
|
43
|
|
|
'coffee' => ['coffee', 'Here is a :coffee: for you ' . $username . '!'], |
|
44
|
|
|
'beer' => ['beer', 'Here is a :t3beer: for you ' . $username . '!'], |
|
45
|
|
|
'coke' => ['coke', 'Coke is unhealthy ' . $username . '!'], |
|
46
|
|
|
'cola' => ['cola', 'Coke is unhealthy ' . $username . '!'], |
|
47
|
|
|
'cookie' => ['cookie', 'Here is a :cookie: for you ' . $username . '!'], |
|
48
|
|
|
'typo3' => ['typo3', ':typo3: TYPO3 CMS is the best open source CMS of the world!'], |
|
49
|
|
|
'dark' => ['dark', 'sure, we have cookies :cookie:'], |
|
50
|
|
|
//'cat' => ['cat', 'ok, here is some cat content '.$cats[array_rand($cats)]], |
|
51
|
|
|
'love' => ['love', 'I love you too, ' . $username . ':kiss:'], |
|
52
|
|
|
'no-matching' => ['foobar', null], |
|
53
|
|
|
]; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @test |
|
58
|
|
|
* @dataProvider testDataProvider |
|
59
|
|
|
* |
|
60
|
|
|
* @param string $keyword |
|
61
|
|
|
* @param string $response |
|
62
|
|
|
*/ |
|
63
|
|
|
public function processShowReturnsCorrectResponseForKnownKeywords($keyword, $response) |
|
64
|
|
|
{ |
|
65
|
|
|
$this->initCommandWithPayload(BottyCommand::class, [ |
|
66
|
|
|
'user' => 'U54321', |
|
67
|
|
|
'text' => 'botty ' . $keyword, |
|
68
|
|
|
]); |
|
69
|
|
|
$result = $this->command->process(); |
|
70
|
|
|
if ($response === null) { |
|
71
|
|
|
static::assertNull($response); |
|
72
|
|
|
} else { |
|
73
|
|
|
static::assertStringStartsWith($response, $result); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @test |
|
79
|
|
|
* @dataProvider testDataProvider |
|
80
|
|
|
*/ |
|
81
|
|
|
public function processShowReturnsCorrectResponseForHelpKeyword() |
|
82
|
|
|
{ |
|
83
|
|
|
$this->initCommandWithPayload(BottyCommand::class, [ |
|
84
|
|
|
'user' => 'U54321', |
|
85
|
|
|
'text' => 'botty help', |
|
86
|
|
|
]); |
|
87
|
|
|
$result = $this->command->process(); |
|
88
|
|
|
static::assertEquals(':link: <http://www.t3bot.de|My Homepage> | ' |
|
89
|
|
|
. ':link: <https://github.com/NeoBlack/T3Bot|Github> | ' |
|
90
|
|
|
. ':link: <http://wiki.typo3.org/T3Bot|Help for Commands>', $result); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|