-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathWritingTest.php
111 lines (95 loc) · 3.59 KB
/
WritingTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
/*
* This file is part of JoliCode's Slack PHP API project.
*
* (c) JoliCode <coucou@jolicode.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace JoliCode\Slack\Tests;
use JoliCode\Slack\Api\Model\ChatPostMessagePostResponse200;
use JoliCode\Slack\Api\Model\FilesUploadPostResponse200;
use JoliCode\Slack\ClientFactory;
use Nyholm\Psr7\Stream;
use PHPUnit\Framework\TestCase;
class WritingTest extends TestCase
{
public function testItCanPostAttachment()
{
$client = ClientFactory::create($_SERVER['SLACK_TOKEN']);
$response = $client->chatPostMessage([
'username' => 'User A',
'channel' => $_SERVER['SLACK_TEST_CHANNEL'],
'text' => 'Message with attachment',
'attachments' => json_encode([[
'fallback' => 'JoliCode',
'image_url' => 'https://jolicode.com/images/valeurs_huma.png',
]]),
]);
self::assertInstanceOf(ChatPostMessagePostResponse200::class, $response);
self::assertContains($response->getMessage()->getAttachments()[0]->getImageUrl(), 'https://jolicode.com/images/valeurs_huma.png');
}
public function testItCanPostMessageWithBlock()
{
$client = ClientFactory::create($_SERVER['SLACK_TOKEN']);
$response = $client->chatPostMessage([
'username' => 'User C',
'channel' => $_SERVER['SLACK_TEST_CHANNEL'],
'text' => 'Message with blocks',
'blocks' => json_encode([
[
'type' => 'section',
'text' => [
'type' => 'mrkdwn',
'text' => ':tada: Blocks are working!',
],
],
[
'type' => 'divider',
],
[
'type' => 'context',
'elements' => [
[
'type' => 'mrkdwn',
'text' => ':woman-running: Best test ever',
],
],
],
]),
]);
self::assertInstanceOf(ChatPostMessagePostResponse200::class, $response);
self::assertNotEmpty($response->getMessage()->getBlocks());
}
public function testItCanPostAMessageAndThenAThreadResponse()
{
$client = ClientFactory::create($_SERVER['SLACK_TOKEN']);
/** @var ChatPostMessagePostResponse200 $response */
$response = $client->chatPostMessage([
'username' => 'User A',
'channel' => $_SERVER['SLACK_TEST_CHANNEL'],
'text' => 'First message',
]);
$response2 = $client->chatPostMessage([
'username' => 'User B',
'channel' => $_SERVER['SLACK_TEST_CHANNEL'],
'text' => 'First response in a Thread',
'thread_ts' => $response->getMessage()->getTs(),
]);
$this->assertTrue($response2->getOk());
}
public function testItCanUploadFile()
{
$client = ClientFactory::create($_SERVER['SLACK_TOKEN']);
/** @var FilesUploadPostResponse200 $response */
$response = $client->filesUpload([
'channels' => $_SERVER['SLACK_TEST_CHANNEL'],
'title' => 'Uploaded image',
'filename' => 'test-image.png',
'filetype' => 'png',
'file' => Stream::create(fopen(__DIR__.'/resources/test-image.png', 'r')),
]);
$this->assertTrue($response->getOk());
}
}