@@ -330,4 +330,85 @@ public function testSendWithMarkdownShouldEscapeSpecialCharacters()
330
330
331
331
$ transport ->send (new ChatMessage ('I contain special characters _ * [ ] ( ) ~ ` > # + - = | { } . ! to send. ' ));
332
332
}
333
+
334
+ public function testSendPhotoWithOptions ()
335
+ {
336
+ $ response = $ this ->createMock (ResponseInterface::class);
337
+ $ response ->expects ($ this ->exactly (2 ))
338
+ ->method ('getStatusCode ' )
339
+ ->willReturn (200 );
340
+
341
+ $ content = <<<JSON
342
+ {
343
+ "ok": true,
344
+ "result": {
345
+ "message_id": 1,
346
+ "from": {
347
+ "id": 12345678,
348
+ "is_bot": true,
349
+ "first_name": "YourBot",
350
+ "username": "YourBot"
351
+ },
352
+ "chat": {
353
+ "id": 1234567890,
354
+ "first_name": "John",
355
+ "last_name": "Doe",
356
+ "username": "JohnDoe",
357
+ "type": "private"
358
+ },
359
+ "date": 1459958199,
360
+ "photo": [
361
+ {
362
+ "file_id": "ABCDEF",
363
+ "file_unique_id" : "ABCDEF1",
364
+ "file_size": 1378,
365
+ "width": 90,
366
+ "height": 51
367
+ },
368
+ {
369
+ "file_id": "ABCDEF",
370
+ "file_unique_id" : "ABCDEF2",
371
+ "file_size": 19987,
372
+ "width": 320,
373
+ "height": 180
374
+ }
375
+ ],
376
+ "caption": "Hello from Bot!"
377
+ }
378
+ }
379
+ JSON ;
380
+
381
+ $ response ->expects ($ this ->once ())
382
+ ->method ('getContent ' )
383
+ ->willReturn ($ content )
384
+ ;
385
+
386
+ $ expectedBody = [
387
+ 'photo ' => 'https://image.ur.l/ ' ,
388
+ 'has_spoiler ' => true ,
389
+ 'chat_id ' => 'testChannel ' ,
390
+ 'parse_mode ' => 'MarkdownV2 ' ,
391
+ 'caption ' => 'testMessage ' ,
392
+ ];
393
+
394
+ $ client = new MockHttpClient (function (string $ method , string $ url , array $ options = []) use ($ response , $ expectedBody ): ResponseInterface {
395
+ $ this ->assertStringEndsWith ('/sendPhoto ' , $ url );
396
+ $ this ->assertSame ($ expectedBody , json_decode ($ options ['body ' ], true ));
397
+
398
+ return $ response ;
399
+ });
400
+
401
+ $ transport = self ::createTransport ($ client , 'testChannel ' );
402
+
403
+ $ messageOptions = new TelegramOptions ();
404
+ $ messageOptions
405
+ ->photo ('https://image.ur.l/ ' )
406
+ ->hasSpoiler (true )
407
+ ;
408
+
409
+ $ sentMessage = $ transport ->send (new ChatMessage ('testMessage ' , $ messageOptions ));
410
+
411
+ $ this ->assertEquals (1 , $ sentMessage ->getMessageId ());
412
+ $ this ->assertEquals ('telegram://api.telegram.org?channel=testChannel ' , $ sentMessage ->getTransport ());
413
+ }
333
414
}
0 commit comments