@@ -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,170 @@ 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
+
497
+ public function testSendPhotoByUrlWithOptions ()
498
+ {
499
+ $ response = $ this ->createMock (ResponseInterface::class);
500
+ $ response ->expects ($ this ->exactly (2 ))
501
+ ->method ('getStatusCode ' )
502
+ ->willReturn (200 );
503
+
504
+ $ content = <<<JSON
505
+ {
506
+ "ok": true,
507
+ "result": {
508
+ "message_id": 1,
509
+ "from": {
510
+ "id": 12345678,
511
+ "is_bot": true,
512
+ "first_name": "YourBot",
513
+ "username": "YourBot"
514
+ },
515
+ "chat": {
516
+ "id": 1234567890,
517
+ "first_name": "John",
518
+ "last_name": "Doe",
519
+ "username": "JohnDoe",
520
+ "type": "private"
521
+ },
522
+ "date": 1459958199,
523
+ "photo": [
524
+ {
525
+ "file_id": "ABCDEF",
526
+ "file_unique_id" : "ABCDEF1",
527
+ "file_size": 1378,
528
+ "width": 90,
529
+ "height": 51
530
+ },
531
+ {
532
+ "file_id": "ABCDEF",
533
+ "file_unique_id" : "ABCDEF2",
534
+ "file_size": 19987,
535
+ "width": 320,
536
+ "height": 180
537
+ }
538
+ ],
539
+ "caption": "Hello from Bot!"
540
+ }
541
+ }
542
+ JSON ;
543
+
544
+ $ response ->expects ($ this ->once ())
545
+ ->method ('getContent ' )
546
+ ->willReturn ($ content )
547
+ ;
548
+
549
+ $ expectedBody = [
550
+ 'photo ' => 'https://image.ur.l/ ' ,
551
+ 'has_spoiler ' => true ,
552
+ 'chat_id ' => 'testChannel ' ,
553
+ 'parse_mode ' => 'MarkdownV2 ' ,
554
+ 'caption ' => 'testMessage ' ,
555
+ ];
556
+
557
+ $ client = new MockHttpClient (function (string $ method , string $ url , array $ options = []) use ($ response , $ expectedBody ): ResponseInterface {
558
+ $ this ->assertStringEndsWith ('/sendPhoto ' , $ url );
559
+ $ this ->assertSame ($ expectedBody , json_decode ($ options ['body ' ], true ));
560
+
561
+ return $ response ;
562
+ });
563
+
564
+ $ transport = self ::createTransport ($ client , 'testChannel ' );
565
+
566
+ $ messageOptions = new TelegramOptions ();
567
+ $ messageOptions
568
+ ->photo ('https://image.ur.l/ ' )
569
+ ->hasSpoiler (true )
570
+ ;
571
+
572
+ $ sentMessage = $ transport ->send (new ChatMessage ('testMessage ' , $ messageOptions ));
573
+
574
+ $ this ->assertEquals (1 , $ sentMessage ->getMessageId ());
575
+ $ this ->assertEquals ('telegram://api.telegram.org?channel=testChannel ' , $ sentMessage ->getTransport ());
576
+ }
577
+
578
+ public function testSendPhotoByUploadWithOptions ()
416
579
{
417
580
$ response = $ this ->createMock (ResponseInterface::class);
418
581
$ response ->expects ($ this ->exactly (2 ))
@@ -470,11 +633,6 @@ public function testSendLocalPhotoWithOptions()
470
633
471
634
$ this ->assertSame ('Content-Length: 576 ' , $ options ['normalized_headers ' ]['content-length ' ][0 ]);
472
635
$ expectedBody = <<<BODY
473
- -- {$ matches ['boundary ' ]}
474
- Content-Disposition: form-data; name="photo"; filename="fixtures.png"
475
- Content-Type: image/png
476
-
477
- %s
478
636
-- {$ matches ['boundary ' ]}
479
637
Content-Disposition: form-data; name="has_spoiler"
480
638
@@ -488,6 +646,11 @@ public function testSendLocalPhotoWithOptions()
488
646
489
647
MarkdownV2
490
648
-- {$ matches ['boundary ' ]}
649
+ Content-Disposition: form-data; name="photo"; filename="fixtures.png"
650
+ Content-Type: image/png
651
+
652
+ %s
653
+ -- {$ matches ['boundary ' ]}
491
654
Content-Disposition: form-data; name="caption"
492
655
493
656
testMessage
@@ -510,7 +673,7 @@ public function testSendLocalPhotoWithOptions()
510
673
511
674
$ messageOptions = new TelegramOptions ();
512
675
$ messageOptions
513
- ->photo (__DIR__ .'/fixtures.png ' )
676
+ ->uploadPhoto (__DIR__ .'/fixtures.png ' )
514
677
->hasSpoiler (true )
515
678
;
516
679
0 commit comments