@@ -331,7 +331,7 @@ public function testSendWithMarkdownShouldEscapeSpecialCharacters()
331
331
$ transport ->send (new ChatMessage ('I contain special characters _ * [ ] ( ) ~ ` > # + - = | { } . ! to send. ' ));
332
332
}
333
333
334
- public function testSendPhotoWithOptions ()
334
+ public function testSendPhotoByHttpUrlWithOptions ()
335
335
{
336
336
$ response = $ this ->createMock (ResponseInterface::class);
337
337
$ response ->expects ($ this ->exactly (2 ))
@@ -412,7 +412,88 @@ public function testSendPhotoWithOptions()
412
412
$ this ->assertEquals ('telegram://api.telegram.org?channel=testChannel ' , $ sentMessage ->getTransport ());
413
413
}
414
414
415
- public function testSendLocalPhotoWithOptions ()
415
+ public function testSendPhotoByFileIdWithOptions ()
416
+ {
417
+ $ response = $ this ->createMock (ResponseInterface::class);
418
+ $ response ->expects ($ this ->exactly (2 ))
419
+ ->method ('getStatusCode ' )
420
+ ->willReturn (200 );
421
+
422
+ $ content = <<<JSON
423
+ {
424
+ "ok": true,
425
+ "result": {
426
+ "message_id": 1,
427
+ "from": {
428
+ "id": 12345678,
429
+ "is_bot": true,
430
+ "first_name": "YourBot",
431
+ "username": "YourBot"
432
+ },
433
+ "chat": {
434
+ "id": 1234567890,
435
+ "first_name": "John",
436
+ "last_name": "Doe",
437
+ "username": "JohnDoe",
438
+ "type": "private"
439
+ },
440
+ "date": 1459958199,
441
+ "photo": [
442
+ {
443
+ "file_id": "ABCDEF",
444
+ "file_unique_id" : "ABCDEF1",
445
+ "file_size": 1378,
446
+ "width": 90,
447
+ "height": 51
448
+ },
449
+ {
450
+ "file_id": "ABCDEF",
451
+ "file_unique_id" : "ABCDEF2",
452
+ "file_size": 19987,
453
+ "width": 320,
454
+ "height": 180
455
+ }
456
+ ],
457
+ "caption": "Hello from Bot!"
458
+ }
459
+ }
460
+ JSON ;
461
+
462
+ $ response ->expects ($ this ->once ())
463
+ ->method ('getContent ' )
464
+ ->willReturn ($ content )
465
+ ;
466
+
467
+ $ expectedBody = [
468
+ 'photo ' => 'ABCDEF ' ,
469
+ 'has_spoiler ' => true ,
470
+ 'chat_id ' => 'testChannel ' ,
471
+ 'parse_mode ' => 'MarkdownV2 ' ,
472
+ 'caption ' => 'testMessage ' ,
473
+ ];
474
+
475
+ $ client = new MockHttpClient (function (string $ method , string $ url , array $ options = []) use ($ response , $ expectedBody ): ResponseInterface {
476
+ $ this ->assertStringEndsWith ('/sendPhoto ' , $ url );
477
+ $ this ->assertSame ($ expectedBody , json_decode ($ options ['body ' ], true ));
478
+
479
+ return $ response ;
480
+ });
481
+
482
+ $ transport = self ::createTransport ($ client , 'testChannel ' );
483
+
484
+ $ messageOptions = new TelegramOptions ();
485
+ $ messageOptions
486
+ ->photo ('ABCDEF ' )
487
+ ->hasSpoiler (true )
488
+ ;
489
+
490
+ $ sentMessage = $ transport ->send (new ChatMessage ('testMessage ' , $ messageOptions ));
491
+
492
+ $ this ->assertEquals (1 , $ sentMessage ->getMessageId ());
493
+ $ this ->assertEquals ('telegram://api.telegram.org?channel=testChannel ' , $ sentMessage ->getTransport ());
494
+ }
495
+
496
+ public function testSendPhotoByUploadWithOptions ()
416
497
{
417
498
$ response = $ this ->createMock (ResponseInterface::class);
418
499
$ response ->expects ($ this ->exactly (2 ))
@@ -470,11 +551,6 @@ public function testSendLocalPhotoWithOptions()
470
551
471
552
$ this ->assertSame ('Content-Length: 576 ' , $ options ['normalized_headers ' ]['content-length ' ][0 ]);
472
553
$ expectedBody = <<<BODY
473
- -- {$ matches ['boundary ' ]}
474
- Content-Disposition: form-data; name="photo"; filename="fixtures.png"
475
- Content-Type: image/png
476
-
477
- %s
478
554
-- {$ matches ['boundary ' ]}
479
555
Content-Disposition: form-data; name="has_spoiler"
480
556
@@ -488,6 +564,11 @@ public function testSendLocalPhotoWithOptions()
488
564
489
565
MarkdownV2
490
566
-- {$ matches ['boundary ' ]}
567
+ Content-Disposition: form-data; name="photo"; filename="fixtures.png"
568
+ Content-Type: image/png
569
+
570
+ %s
571
+ -- {$ matches ['boundary ' ]}
491
572
Content-Disposition: form-data; name="caption"
492
573
493
574
testMessage
@@ -510,7 +591,7 @@ public function testSendLocalPhotoWithOptions()
510
591
511
592
$ messageOptions = new TelegramOptions ();
512
593
$ messageOptions
513
- ->photo (__DIR__ .'/fixtures.png ' )
594
+ ->uploadPhoto (__DIR__ .'/fixtures.png ' )
514
595
->hasSpoiler (true )
515
596
;
516
597
0 commit comments