|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace NotificationChannels\Telegram\Test; |
| 4 | + |
| 5 | +use NotificationChannels\Telegram\TelegramPoll; |
| 6 | +use PHPUnit\Framework\TestCase; |
| 7 | + |
| 8 | +/** |
| 9 | + * Class TelegramPollTest. |
| 10 | + */ |
| 11 | +class TelegramPollTest extends TestCase |
| 12 | +{ |
| 13 | + /** @test */ |
| 14 | + public function it_accepts_question_when_constructed(): void |
| 15 | + { |
| 16 | + $message = new TelegramPoll("Aren't Laravel Notification Channels awesome?"); |
| 17 | + $this->assertEquals("Aren't Laravel Notification Channels awesome?", $message->getPayloadValue('question')); |
| 18 | + } |
| 19 | + |
| 20 | + /** @test */ |
| 21 | + public function the_recipients_chat_id_can_be_set(): void |
| 22 | + { |
| 23 | + $message = new TelegramPoll(); |
| 24 | + $message->to(12345); |
| 25 | + $this->assertEquals(12345, $message->getPayloadValue('chat_id')); |
| 26 | + } |
| 27 | + |
| 28 | + /** @test */ |
| 29 | + public function the_question_message_can_be_set(): void |
| 30 | + { |
| 31 | + $message = new TelegramPoll(); |
| 32 | + $message->question("Aren't Laravel Notification Channels awesome?"); |
| 33 | + $this->assertEquals("Aren't Laravel Notification Channels awesome?", $message->getPayloadValue('question')); |
| 34 | + } |
| 35 | + |
| 36 | + /** @test */ |
| 37 | + public function the_options_can_be_set_for_the_question(): void |
| 38 | + { |
| 39 | + $message = new TelegramPoll(); |
| 40 | + $message->choices(['Yes', 'No']); |
| 41 | + $this->assertEquals('["Yes","No"]', $message->getPayloadValue('options')); |
| 42 | + } |
| 43 | + |
| 44 | + /** @test */ |
| 45 | + public function it_can_determine_if_the_recipient_chat_id_has_not_been_set(): void |
| 46 | + { |
| 47 | + $message = new TelegramPoll(); |
| 48 | + $this->assertTrue($message->toNotGiven()); |
| 49 | + |
| 50 | + $message->to(12345); |
| 51 | + $this->assertFalse($message->toNotGiven()); |
| 52 | + } |
| 53 | + |
| 54 | + /** @test */ |
| 55 | + public function it_can_return_the_payload_as_an_array(): void |
| 56 | + { |
| 57 | + $message = new TelegramPoll("Aren't Laravel Notification Channels awesome?"); |
| 58 | + $message->to(12345); |
| 59 | + $message->choices(['Yes', 'No']); |
| 60 | + $expected = [ |
| 61 | + 'chat_id' => 12345, |
| 62 | + 'question' => "Aren't Laravel Notification Channels awesome?", |
| 63 | + 'options' => '["Yes","No"]', |
| 64 | + ]; |
| 65 | + |
| 66 | + $this->assertEquals($expected, $message->toArray()); |
| 67 | + } |
| 68 | +} |
0 commit comments