1
+ <?php
2
+
3
+ namespace NotificationChannels \Telegram \Test ;
4
+
5
+ use NotificationChannels \Telegram \TelegramMessage ;
6
+
7
+ class TelegramMessageTest extends \PHPUnit_Framework_TestCase
8
+ {
9
+ /** @test */
10
+ public function it_accepts_content_when_constructed ()
11
+ {
12
+ $ message = new TelegramMessage ('Laravel Notification Channels are awesome! ' );
13
+ $ this ->assertEquals ('Laravel Notification Channels are awesome! ' , $ message ->payload ['text ' ]);
14
+ }
15
+
16
+ /** @test */
17
+ public function the_default_parse_mode_is_markdown ()
18
+ {
19
+ $ message = new TelegramMessage ();
20
+ $ this ->assertEquals ('Markdown ' , $ message ->payload ['parse_mode ' ]);
21
+ }
22
+
23
+ /** @test */
24
+ public function the_recipients_chat_id_can_be_set ()
25
+ {
26
+ $ message = new TelegramMessage ();
27
+ $ message ->to (12345 );
28
+ $ this ->assertEquals (12345 , $ message ->payload ['chat_id ' ]);
29
+ }
30
+
31
+ /** @test */
32
+ public function the_notification_message_can_be_set ()
33
+ {
34
+ $ message = new TelegramMessage ();
35
+ $ message ->content ('Laravel Notification Channels are awesome! ' );
36
+ $ this ->assertEquals ('Laravel Notification Channels are awesome! ' , $ message ->payload ['text ' ]);
37
+ }
38
+
39
+ /** @test */
40
+ public function an_inline_button_can_be_added_to_the_messsage ()
41
+ {
42
+ $ message = new TelegramMessage ();
43
+ $ message ->button ('Laravel ' , 'https://laravel.com ' );
44
+ $ this ->assertEquals ('{"inline_keyboard":[[{"text":"Laravel","url":"https:\/\/laravel.com"}]]} ' , $ message ->payload ['reply_markup ' ]);
45
+ }
46
+
47
+ /** @test */
48
+ public function additional_options_can_be_set_for_the_message ()
49
+ {
50
+ $ message = new TelegramMessage ();
51
+ $ message ->options (['foo ' => 'bar ' ]);
52
+ $ this ->assertEquals ('bar ' , $ message ->payload ['foo ' ]);
53
+ }
54
+
55
+ /** @test */
56
+ public function it_can_determine_if_the_recipient_chat_id_has_not_been_set ()
57
+ {
58
+ $ message = new TelegramMessage ();
59
+ $ this ->assertTrue ($ message ->toNotGiven ());
60
+
61
+ $ message ->to (12345 );
62
+ $ this ->assertFalse ($ message ->toNotGiven ());
63
+ }
64
+
65
+ /** @test */
66
+ public function it_can_return_the_payload_as_an_array ()
67
+ {
68
+ $ message = new TelegramMessage ('Laravel Notification Channels are awesome! ' );
69
+ $ message ->to (12345 );
70
+ $ message ->options (['foo ' => 'bar ' ]);
71
+ $ message ->button ('Laravel ' , 'https://laravel.com ' );
72
+ $ expected = [
73
+ "text " => "Laravel Notification Channels are awesome! " ,
74
+ "parse_mode " => "Markdown " ,
75
+ "chat_id " => 12345 ,
76
+ "foo " => "bar " ,
77
+ "reply_markup " => '{"inline_keyboard":[[{"text":"Laravel","url":"https:\/\/laravel.com"}]]} ' ,
78
+ ];
79
+
80
+ $ this ->assertEquals ($ expected , $ message ->toArray ());
81
+ }
82
+ }
0 commit comments