@@ -331,7 +331,7 @@ public function testSendWithMarkdownShouldEscapeSpecialCharacters()
331331 $ transport ->send (new ChatMessage ('I contain special characters _ * [ ] ( ) ~ ` > # + - = | { } . ! to send. ' ));
332332 }
333333
334- public function testSendPhotoWithOptions ()
334+ public function testSendPhotoByHttpUrlWithOptions ()
335335 {
336336 $ response = $ this ->createMock (ResponseInterface::class);
337337 $ response ->expects ($ this ->exactly (2 ))
@@ -412,7 +412,88 @@ public function testSendPhotoWithOptions()
412412 $ this ->assertEquals ('telegram://api.telegram.org?channel=testChannel ' , $ sentMessage ->getTransport ());
413413 }
414414
415- public function testSendLocalPhotoWithOptions ()
415+ public function testSendPhotoByFileIdWithOptions ()
5D39
code>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 ()
416497 {
417498 $ response = $ this ->createMock (ResponseInterface::class);
418499 $ response ->expects ($ this ->exactly (2 ))
@@ -470,11 +551,6 @@ public function testSendLocalPhotoWithOptions()
470551
471552 $ this ->assertSame ('Content-Length: 576 ' , $ options ['normalized_headers ' ]['content-length ' ][0 ]);
472553 $ expectedBody = <<<BODY
473- -- {$ matches ['boundary ' ]}
474- Content-Disposition: form-data; name="photo"; filename="fixtures.png"
475- Content-Type: image/png
476-
477- %s
478554 -- {$ matches ['boundary ' ]}
479555 Content-Disposition: form-data; name="has_spoiler"
480556
@@ -488,6 +564,11 @@ public function testSendLocalPhotoWithOptions()
488564
489565 MarkdownV2
490566 -- {$ matches ['boundary ' ]}
567+ Content-Disposition: form-data; name="photo"; filename="fixtures.png"
568+ Content-Type: image/png
569+
570+ %s
571+ -- {$ matches ['boundary ' ]}
491572 Content-Disposition: form-data; name="caption"
492573
493574 testMessage
@@ -510,7 +591,7 @@ public function testSendLocalPhotoWithOptions()
510591
511592 $ messageOptions = new TelegramOptions ();
512593 $ messageOptions
513- ->photo (__DIR__ .'/fixtures.png ' )
594+ ->uploadPhoto (__DIR__ .'/fixtures.png ' )
514595 ->hasSpoiler (true )
515596 ;
516597
0 commit comments