-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSendMediaGroupTest.php
More file actions
147 lines (130 loc) · 5.28 KB
/
SendMediaGroupTest.php
File metadata and controls
147 lines (130 loc) · 5.28 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php namespace Tests\Bot\Methods;
use Tests\TelegramTestCase;
use TelegramPro\Bot\Types\PhotoSize;
use TelegramPro\Bot\Methods\Types\Url;
use TelegramPro\Bot\Methods\SendPhoto;
use TelegramPro\Bot\Methods\SendVideo;
use TelegramPro\Bot\Methods\Types\Video;
use TelegramPro\Bot\Methods\Types\Message;
use TelegramPro\Bot\Methods\SendMediaGroup;
use TelegramPro\Bot\Methods\Types\MediaGroup;
use TelegramPro\Bot\Methods\Types\MethodError;
use TelegramPro\Bot\Methods\Types\MediaCaption;
use TelegramPro\Bot\Methods\FileUploads\FilePath;
use TelegramPro\Bot\Methods\FileUploads\VideoFile;
use TelegramPro\Bot\Methods\FileUploads\CanNotOpenFile;
use TelegramPro\Bot\Methods\FileUploads\InputPhotoFile;
use TelegramPro\Bot\Methods\FileUploads\InputMediaPhoto;
use TelegramPro\Bot\Methods\FileUploads\InputMediaVideo;
class SendMediaGroupTest extends TelegramTestCase
{
function testSendMediaGroupWithFilePath()
{
$response = SendMediaGroup::parameters(
$this->config->cyclingChatId(),
MediaGroup::items(
InputMediaPhoto::fromFilePath(
FilePath::fromString($this->media->image()),
MediaCaption::fromString('[SendMediaGroup] send image with file path')
),
InputMediaVideo::fromFilePath(
FilePath::fromString($this->media->video()),
MediaCaption::fromString('[SendMediaGroup] send video with file path')
)
)
)->send($this->telegram);
$this->isOk($response);
self::assertCount(2, $response->sentMessages());
self::assertInstanceOf(Message::class, $response->sentMessages()->get(0));
}
function testSendMediaGroupWithUrl()
{
$response = SendMediaGroup::parameters(
$this->config->cyclingChatId(),
MediaGroup::items(
InputMediaPhoto::fromUrl(
Url::fromString($this->media->imageUrl()),
MediaCaption::fromString('[SendMediaGroup] send image with url')
),
InputMediaVideo::fromUrl(
Url::fromString($this->media->videoUrl()),
MediaCaption::fromString('[SendMediaGroup] send video with url')
)
)
)->send($this->telegram);
$this->isOk($response);
self::assertCount(2, $response->sentMessages());
}
function testSendMediaGroupWithFileId()
{
$num = rand(0, 32767);
$response = SendPhoto::parameters(
$this->config->cyclingChatId(),
InputPhotoFile::fromFilePath(
FilePath::fromString($this->media->image())
),
MediaCaption::fromString('[SendMediaGroup] send media group with file id 1/4 ' . $num)
)->send($this->telegram);
/** @var PhotoSize $responsePhoto */
$this->isOk($response);
$responsePhoto = $response->sentMessage()->photo()[0];
$response = SendVideo::parameters(
$this->config->cyclingChatId(),
VideoFile::fromFilePath(
FilePath::fromString($this->media->video())
),
MediaCaption::fromString('[SendMediaGroup] send media group with file id 2/4 ' . $num)
)->send($this->telegram);
/** @var Video $responsePhoto */
$this->isOk($response);
$responseVideo = $response->sentMessage()->video();
$response = SendMediaGroup::parameters(
$this->config->cyclingChatId(),
MediaGroup::items(
InputMediaPhoto::fromFileId(
$responsePhoto->fileId(),
MediaCaption::fromString('[SendMediaGroup] send media group with file id 3/4')
),
InputMediaVideo::fromFileId(
$responseVideo->fileId(),
MediaCaption::fromString('[SendMediaGroup] send media group with file id 4/4')
)
)
)->send($this->telegram);
$this->isOk($response);
self::assertCount(2, $response->sentMessages());
}
function testCanNotSendNonExistentFile()
{
$this->expectException(CanNotOpenFile::class);
SendMediaGroup::parameters(
$this->config->cyclingChatId(),
MediaGroup::items(
InputMediaPhoto::fromFilePath(
FilePath::fromString('non existent file')
),
InputMediaPhoto::fromFilePath(
FilePath::fromString('non existent file')
)
)
)->send($this->telegram);
}
function testCanParseError()
{
$response = SendMediaGroup::parameters(
$this->config->cyclingChatId(),
MediaGroup::items(
InputMediaPhoto::fromUrl(
Url::fromString('http://non.existent.url')
),
InputMediaPhoto::fromUrl(
Url::fromString('http://non.existent.url')
)
)
)->send($this->telegram);
self::assertFalse($response->ok());
self::assertInstanceOf(MethodError::class, $response->error());
self::assertSame('400', $response->error()->code());
self::assertNotEmpty($response->error()->description());
}
}