diff --git a/CHANGELOG.md b/CHANGELOG.md index 819a78f5..047891a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,33 @@ # Telegram Bot API for PHP Change Log +## 0.21.1 June 12, 2026 + +- New #200: Add `RichText` interface and 25 rich text types: `RichTextBold`, `RichTextItalic`, `RichTextUnderline`, + `RichTextStrikethrough`, `RichTextSpoiler`, `RichTextDateTime`, `RichTextTextMention`, `RichTextSubscript`, + `RichTextSuperscript`, `RichTextMarked`, `RichTextCode`, `RichTextCustomEmoji`, `RichTextMathematicalExpression`, + `RichTextUrl`, `RichTextEmailAddress`, `RichTextPhoneNumber`, `RichTextBankCardNumber`, `RichTextMention`, + `RichTextHashtag`, `RichTextCashtag`, `RichTextBotCommand`, `RichTextAnchor`, `RichTextAnchorLink`, + `RichTextReference`, `RichTextReferenceLink`. +- New #200: Add `RichBlockCaption`, `RichBlockTableCell`, and `RichBlockListItem` types. +- New #200: Add `RichBlock` interface and 21 rich block types: `RichBlockParagraph`, `RichBlockSectionHeading`, + `RichBlockPreformatted`, `RichBlockFooter`, `RichBlockDivider`, `RichBlockMathematicalExpression`, + `RichBlockAnchor`, `RichBlockList`, `RichBlockBlockQuotation`, `RichBlockPullQuotation`, `RichBlockCollage`, + `RichBlockSlideshow`, `RichBlockTable`, `RichBlockDetails`, `RichBlockMap`, `RichBlockAnimation`, + `RichBlockAudio`, `RichBlockPhoto`, `RichBlockVideo`, `RichBlockVoiceNote`, `RichBlockThinking`. +- New #200: Add `RichMessage` type. +- New #200: Add `InputRichMessage` and `InputRichMessageContent` types. +- New #200: Add `SendRichMessage` and `SendRichMessageDraft` methods. +- New #200: Add `richMessage` parameter to `EditMessageText` method. +- New #200: Add `richMessage` field to `Message` type. +- New #200: Add `supportsJoinRequestQueries` field to `User` type. +- New #200: Add `guardBot` field to `ChatFullInfo` type. +- New #200: Add `queryId` field to `ChatJoinRequest` type. +- New #200: Add `AnswerChatJoinRequestQuery` and `SendChatJoinRequestWebApp` methods. +- New #200: Add `Link` type. +- New #200: Add `link` field to `PollMedia` type. +- New #200: Add `InputMediaLink` type. +- Enh #200: Make `text` parameter of `EditMessageText` method optional. + ## 0.21 May 9, 2026 - New #199: Add `supportsGuestQueries` field to `User` type. diff --git a/README.md b/README.md index 52ec9e79..2a31569e 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ The package provides a simple and convenient way to interact with the Telegram Bot API. -✔️ Telegram Bot API 10.0 (May 8, 2026) is **fully supported**. +✔️ Telegram Bot API 10.1 (June 11, 2026) is **fully supported**. ♻️ **Zero dependencies** — no third-party libraries, only native PHP. diff --git a/src/Method/AnswerChatJoinRequestQuery.php b/src/Method/AnswerChatJoinRequestQuery.php new file mode 100644 index 00000000..e074d1e5 --- /dev/null +++ b/src/Method/AnswerChatJoinRequestQuery.php @@ -0,0 +1,45 @@ + + */ +final readonly class AnswerChatJoinRequestQuery implements MethodInterface +{ + public function __construct( + private string $chatJoinRequestQueryId, + private string $result, + ) {} + + public function getHttpMethod(): HttpMethod + { + return HttpMethod::POST; + } + + public function getApiMethod(): string + { + return 'answerChatJoinRequestQuery'; + } + + public function getData(): array + { + return [ + 'chat_join_request_query_id' => $this->chatJoinRequestQueryId, + 'result' => $this->result, + ]; + } + + public function getResultType(): TrueValue + { + return new TrueValue(); + } +} diff --git a/src/Method/SendChatJoinRequestWebApp.php b/src/Method/SendChatJoinRequestWebApp.php new file mode 100644 index 00000000..dfff00ca --- /dev/null +++ b/src/Method/SendChatJoinRequestWebApp.php @@ -0,0 +1,45 @@ + + */ +final readonly class SendChatJoinRequestWebApp implements MethodInterface +{ + public function __construct( + private string $chatJoinRequestQueryId, + private string $webAppUrl, + ) {} + + public function getHttpMethod(): HttpMethod + { + return HttpMethod::POST; + } + + public function getApiMethod(): string + { + return 'sendChatJoinRequestWebApp'; + } + + public function getData(): array + { + return [ + 'chat_join_request_query_id' => $this->chatJoinRequestQueryId, + 'web_app_url' => $this->webAppUrl, + ]; + } + + public function getResultType(): TrueValue + { + return new TrueValue(); + } +} diff --git a/src/Method/SendRichMessage.php b/src/Method/SendRichMessage.php new file mode 100644 index 00000000..3f7226c4 --- /dev/null +++ b/src/Method/SendRichMessage.php @@ -0,0 +1,76 @@ + + */ +final readonly class SendRichMessage implements MethodInterface +{ + public function __construct( + private int|string $chatId, + private InputRichMessage $richMessage, + private ?string $businessConnectionId = null, + private ?int $messageThreadId = null, + private ?int $directMessagesTopicId = null, + private ?bool $disableNotification = null, + private ?bool $protectContent = null, + private ?bool $allowPaidBroadcast = null, + private ?string $messageEffectId = null, + private ?SuggestedPostParameters $suggestedPostParameters = null, + private ?ReplyParameters $replyParameters = null, + private InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $replyMarkup = null, + ) {} + + public function getHttpMethod(): HttpMethod + { + return HttpMethod::POST; + } + + public function getApiMethod(): string + { + return 'sendRichMessage'; + } + + public function getData(): array + { + return array_filter( + [ + 'business_connection_id' => $this->businessConnectionId, + 'chat_id' => $this->chatId, + 'message_thread_id' => $this->messageThreadId, + 'direct_messages_topic_id' => $this->directMessagesTopicId, + 'rich_message' => $this->richMessage->toRequestArray(), + 'disable_notification' => $this->disableNotification, + 'protect_content' => $this->protectContent, + 'allow_paid_broadcast' => $this->allowPaidBroadcast, + 'message_effect_id' => $this->messageEffectId, + 'suggested_post_parameters' => $this->suggestedPostParameters?->toRequestArray(), + 'reply_parameters' => $this->replyParameters?->toRequestArray(), + 'reply_markup' => $this->replyMarkup?->toRequestArray(), + ], + static fn(mixed $value): bool => $value !== null, + ); + } + + public function getResultType(): ObjectValue + { + return new ObjectValue(Message::class); + } +} diff --git a/src/Method/SendRichMessageDraft.php b/src/Method/SendRichMessageDraft.php new file mode 100644 index 00000000..0004be16 --- /dev/null +++ b/src/Method/SendRichMessageDraft.php @@ -0,0 +1,53 @@ + + */ +final readonly class SendRichMessageDraft implements MethodInterface +{ + public function __construct( + private int $chatId, + private int $draftId, + private InputRichMessage $richMessage, + private ?int $messageThreadId = null, + ) {} + + public function getHttpMethod(): HttpMethod + { + return HttpMethod::POST; + } + + public function getApiMethod(): string + { + return 'sendRichMessageDraft'; + } + + public function getData(): array + { + return array_filter( + [ + 'chat_id' => $this->chatId, + 'message_thread_id' => $this->messageThreadId, + 'draft_id' => $this->draftId, + 'rich_message' => $this->richMessage->toRequestArray(), + ], + static fn(mixed $value): bool => $value !== null, + ); + } + + public function getResultType(): TrueValue + { + return new TrueValue(); + } +} diff --git a/src/Method/UpdatingMessage/EditMessageText.php b/src/Method/UpdatingMessage/EditMessageText.php index 2f407d3f..82cbfa50 100644 --- a/src/Method/UpdatingMessage/EditMessageText.php +++ b/src/Method/UpdatingMessage/EditMessageText.php @@ -8,6 +8,7 @@ use Phptg\BotApi\Transport\HttpMethod; use Phptg\BotApi\MethodInterface; use Phptg\BotApi\Type\InlineKeyboardMarkup; +use Phptg\BotApi\Type\InputRichMessage; use Phptg\BotApi\Type\LinkPreviewOptions; use Phptg\BotApi\Type\Message; use Phptg\BotApi\Type\MessageEntity; @@ -23,7 +24,7 @@ * @param MessageEntity[]|null $entities */ public function __construct( - private string $text, + private ?string $text = null, private ?string $businessConnectionId = null, private int|string|null $chatId = null, private ?int $messageId = null, @@ -32,6 +33,7 @@ public function __construct( private ?array $entities = null, private ?LinkPreviewOptions $linkPreviewOptions = null, private ?InlineKeyboardMarkup $replyMarkup = null, + private ?InputRichMessage $richMessage = null, ) {} public function getHttpMethod(): HttpMethod @@ -59,6 +61,7 @@ public function getData(): array $this->entities, ), 'link_preview_options' => $this->linkPreviewOptions?->toRequestArray(), + 'rich_message' => $this->richMessage?->toRequestArray(), 'reply_markup' => $this->replyMarkup?->toRequestArray(), ], static fn(mixed $value): bool => $value !== null, diff --git a/src/ParseResult/ObjectFactory.php b/src/ParseResult/ObjectFactory.php index 14a8a772..48e8bda4 100644 --- a/src/ParseResult/ObjectFactory.php +++ b/src/ParseResult/ObjectFactory.php @@ -13,6 +13,7 @@ use ReflectionProperty; use Phptg\BotApi\ParseResult\ValueProcessor\BackgroundFillValue; use Phptg\BotApi\ParseResult\ValueProcessor\BackgroundTypeValue; +use Phptg\BotApi\ParseResult\ValueProcessor\RichBlockValue; use Phptg\BotApi\ParseResult\ValueProcessor\BooleanValue; use Phptg\BotApi\ParseResult\ValueProcessor\ChatBoostSourceValue; use Phptg\BotApi\ParseResult\ValueProcessor\ChatMemberValue; @@ -28,6 +29,7 @@ use Phptg\BotApi\ParseResult\ValueProcessor\ValueProcessorInterface; use Phptg\BotApi\Type\BackgroundFill; use Phptg\BotApi\Type\BackgroundType; +use Phptg\BotApi\Type\RichBlock; use Phptg\BotApi\Type\ChatBoostSource; use Phptg\BotApi\Type\ChatMember; use Phptg\BotApi\Type\MessageOrigin; @@ -165,6 +167,7 @@ private function getTypeMap(): array 'bool' => new BooleanValue(), DateTimeImmutable::class => new DateValue(), ChatBoostSource::class => new ChatBoostSourceValue(), + RichBlock::class => new RichBlockValue(), BackgroundFill::class => new BackgroundFillValue(), BackgroundType::class => new BackgroundTypeValue(), ChatMember::class => new ChatMemberValue(), diff --git a/src/ParseResult/ValueProcessor/RichBlockValue.php b/src/ParseResult/ValueProcessor/RichBlockValue.php new file mode 100644 index 00000000..b45afe0f --- /dev/null +++ b/src/ParseResult/ValueProcessor/RichBlockValue.php @@ -0,0 +1,71 @@ + + */ +final readonly class RichBlockValue extends InterfaceValue +{ + public function getTypeKey(): string + { + return 'type'; + } + + public function getClassMap(): array + { + return [ + 'paragraph' => RichBlockParagraph::class, + 'heading' => RichBlockSectionHeading::class, + 'pre' => RichBlockPreformatted::class, + 'footer' => RichBlockFooter::class, + 'divider' => RichBlockDivider::class, + 'mathematical_expression' => RichBlockMathematicalExpression::class, + 'anchor' => RichBlockAnchor::class, + 'list' => RichBlockList::class, + 'blockquote' => RichBlockBlockQuotation::class, + 'pullquote' => RichBlockPullQuotation::class, + 'collage' => RichBlockCollage::class, + 'slideshow' => RichBlockSlideshow::class, + 'table' => RichBlockTable::class, + 'details' => RichBlockDetails::class, + 'map' => RichBlockMap::class, + 'animation' => RichBlockAnimation::class, + 'audio' => RichBlockAudio::class, + 'photo' => RichBlockPhoto::class, + 'video' => RichBlockVideo::class, + 'voice_note' => RichBlockVoiceNote::class, + 'thinking' => RichBlockThinking::class, + ]; + } + + public function getUnknownTypeMessage(): string + { + return 'Unknown rich block type.'; + } +} diff --git a/src/ParseResult/ValueProcessor/RichTextValue.php b/src/ParseResult/ValueProcessor/RichTextValue.php new file mode 100644 index 00000000..d20e1cb5 --- /dev/null +++ b/src/ParseResult/ValueProcessor/RichTextValue.php @@ -0,0 +1,111 @@ + + */ +#[Attribute(Attribute::TARGET_PARAMETER)] +final readonly class RichTextValue implements ValueProcessorInterface +{ + /** + * @var array> + */ + private const CLASS_MAP = [ + 'bold' => RichTextBold::class, + 'italic' => RichTextItalic::class, + 'underline' => RichTextUnderline::class, + 'strikethrough' => RichTextStrikethrough::class, + 'spoiler' => RichTextSpoiler::class, + 'date_time' => RichTextDateTime::class, + 'text_mention' => RichTextTextMention::class, + 'subscript' => RichTextSubscript::class, + 'superscript' => RichTextSuperscript::class, + 'marked' => RichTextMarked::class, + 'code' => RichTextCode::class, + 'custom_emoji' => RichTextCustomEmoji::class, + 'mathematical_expression' => RichTextMathematicalExpression::class, + 'url' => RichTextUrl::class, + 'email_address' => RichTextEmailAddress::class, + 'phone_number' => RichTextPhoneNumber::class, + 'bank_card_number' => RichTextBankCardNumber::class, + 'mention' => RichTextMention::class, + 'hashtag' => RichTextHashtag::class, + 'cashtag' => RichTextCashtag::class, + 'bot_command' => RichTextBotCommand::class, + 'anchor' => RichTextAnchor::class, + 'anchor_link' => RichTextAnchorLink::class, + 'reference' => RichTextReference::class, + 'reference_link' => RichTextReferenceLink::class, + ]; + + public function process(mixed $value, ?string $key, ObjectFactory $objectFactory): string|array|RichText + { + if (is_string($value)) { + return $value; + } + + if (is_array($value)) { + if (array_is_list($value)) { + return array_map( + fn(mixed $item): string|array|RichText => $this->process($item, $key, $objectFactory), + $value, + ); + } + return $this->createObject($value, $key, $objectFactory); + } + + throw new InvalidTypeOfValueInResultException($key, $value, 'string or array'); + } + + private function createObject(array $value, ?string $key, ObjectFactory $objectFactory): RichText + { + if (!isset($value['type'])) { + throw new NotFoundKeyInResultException('type'); + } + if (!is_string($value['type'])) { + throw new InvalidTypeOfValueInResultException('type', $value['type'], 'string'); + } + $className = self::CLASS_MAP[$value['type']] + ?? throw new TelegramParseResultException('Unknown rich text type.'); + return $objectFactory->create($value, $key, $className); + } +} diff --git a/src/TelegramBotApi.php b/src/TelegramBotApi.php index 632be497..9253d0b4 100644 --- a/src/TelegramBotApi.php +++ b/src/TelegramBotApi.php @@ -10,6 +10,7 @@ use Psr\Log\LoggerInterface; use SensitiveParameter; use Phptg\BotApi\Method\AnswerCallbackQuery; +use Phptg\BotApi\Method\AnswerChatJoinRequestQuery; use Phptg\BotApi\Method\ApproveChatJoinRequest; use Phptg\BotApi\Method\ApproveSuggestedPost; use Phptg\BotApi\Method\BanChatMember; @@ -116,6 +117,9 @@ use Phptg\BotApi\Method\SendVenue; use Phptg\BotApi\Method\SendVideo; use Phptg\BotApi\Method\SendVideoNote; +use Phptg\BotApi\Method\SendChatJoinRequestWebApp; +use Phptg\BotApi\Method\SendRichMessage; +use Phptg\BotApi\Method\SendRichMessageDraft; use Phptg\BotApi\Method\SendVoice; use Phptg\BotApi\Method\SetBusinessAccountBio; use Phptg\BotApi\Method\SetBusinessAccountGiftSettings; @@ -215,6 +219,7 @@ use Phptg\BotApi\Type\PreparedKeyboardButton; use Phptg\BotApi\Type\InputChecklist; use Phptg\BotApi\Type\InputFile; +use Phptg\BotApi\Type\InputRichMessage; use Phptg\BotApi\Type\InputMedia; use Phptg\BotApi\Type\InputMediaAudio; use Phptg\BotApi\Type\InputMediaDocument; @@ -394,6 +399,14 @@ public function answerCallbackQuery( ); } + /** + * @see https://core.telegram.org/bots/api#answerchatjoinrequestquery + */ + public function answerChatJoinRequestQuery(string $chatJoinRequestQueryId, string $result): FailResult|true + { + return $this->call(new AnswerChatJoinRequestQuery($chatJoinRequestQueryId, $result)); + } + /** * @see https://core.telegram.org/bots/api#answerinlinequery * @@ -1059,7 +1072,7 @@ public function editMessageReplyMarkup( * @param MessageEntity[]|null $entities */ public function editMessageText( - string $text, + ?string $text = null, ?string $businessConnectionId = null, int|string|null $chatId = null, ?int $messageId = null, @@ -1068,6 +1081,7 @@ public function editMessageText( ?array $entities = null, ?LinkPreviewOptions $linkPreviewOptions = null, ?InlineKeyboardMarkup $replyMarkup = null, + ?InputRichMessage $richMessage = null, ): FailResult|Message|true { return $this->call( new EditMessageText( @@ -1080,6 +1094,7 @@ public function editMessageText( $entities, $linkPreviewOptions, $replyMarkup, + $richMessage, ), ); } @@ -2936,6 +2951,68 @@ public function sendVoice( ); } + /** + * @see https://core.telegram.org/bots/api#sendchatjoinrequestwebapp + */ + public function sendChatJoinRequestWebApp(string $chatJoinRequestQueryId, string $webAppUrl): FailResult|true + { + return $this->call(new SendChatJoinRequestWebApp($chatJoinRequestQueryId, $webAppUrl)); + } + + /** + * @see https://core.telegram.org/bots/api#sendrichmessage + */ + public function sendRichMessage( + int|string $chatId, + InputRichMessage $richMessage, + ?string $businessConnectionId = null, + ?int $messageThreadId = null, + ?int $directMessagesTopicId = null, + ?bool $disableNotification = null, + ?bool $protectContent = null, + ?bool $allowPaidBroadcast = null, + ?string $messageEffectId = null, + ?SuggestedPostParameters $suggestedPostParameters = null, + ?ReplyParameters $replyParameters = null, + InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $replyMarkup = null, + ): FailResult|Message { + return $this->call( + new SendRichMessage( + $chatId, + $richMessage, + $businessConnectionId, + $messageThreadId, + $directMessagesTopicId, + $disableNotification, + $protectContent, + $allowPaidBroadcast, + $messageEffectId, + $suggestedPostParameters, + $replyParameters, + $replyMarkup, + ), + ); + } + + /** + * @see https://core.telegram.org/bots/api#sendrichmessagedraft + */ + public function sendRichMessageDraft( + int $chatId, + int $draftId, + InputRichMessage $richMessage, + ?int $messageThreadId = null, + ): FailResult|true { + return $this->call( + new SendRichMessageDraft( + $chatId, + $draftId, + $richMessage, + $messageThreadId, + ), + ); + } + /** * @see https://core.telegram.org/bots/api#setbusinessaccountbio */ diff --git a/src/Type/ChatFullInfo.php b/src/Type/ChatFullInfo.php index a1bf69d8..e5f8ac8e 100644 --- a/src/Type/ChatFullInfo.php +++ b/src/Type/ChatFullInfo.php @@ -74,5 +74,6 @@ public function __construct( public ?UniqueGiftColors $uniqueGiftColors = null, public ?int $paidMessageStarCount = null, public ?Audio $firstProfileAudio = null, + public ?User $guardBot = null, ) {} } diff --git a/src/Type/ChatJoinRequest.php b/src/Type/ChatJoinRequest.php index 18ff46fb..b82c891e 100644 --- a/src/Type/ChatJoinRequest.php +++ b/src/Type/ChatJoinRequest.php @@ -20,5 +20,6 @@ public function __construct( public DateTimeImmutable $date, public ?string $bio = null, public ?ChatInviteLink $inviteLink = null, + public ?string $queryId = null, ) {} } diff --git a/src/Type/Inline/InputRichMessageContent.php b/src/Type/Inline/InputRichMessageContent.php new file mode 100644 index 00000000..0ec35c41 --- /dev/null +++ b/src/Type/Inline/InputRichMessageContent.php @@ -0,0 +1,26 @@ + $this->richMessage->toRequestArray(), + ]; + } +} diff --git a/src/Type/InputMediaLink.php b/src/Type/InputMediaLink.php new file mode 100644 index 00000000..85551ce8 --- /dev/null +++ b/src/Type/InputMediaLink.php @@ -0,0 +1,32 @@ + $this->getType(), + 'url' => $this->url, + ]; + } +} diff --git a/src/Type/InputRichMessage.php b/src/Type/InputRichMessage.php new file mode 100644 index 00000000..08211e24 --- /dev/null +++ b/src/Type/InputRichMessage.php @@ -0,0 +1,33 @@ + $this->html, + 'markdown' => $this->markdown, + 'is_rtl' => $this->isRtl, + 'skip_entity_detection' => $this->skipEntityDetection, + ], + static fn(mixed $value): bool => $value !== null, + ); + } +} diff --git a/src/Type/Link.php b/src/Type/Link.php new file mode 100644 index 00000000..6c9fd6d3 --- /dev/null +++ b/src/Type/Link.php @@ -0,0 +1,17 @@ + $blocks + */ + public function __construct( + #[ArrayMap(RichBlockValue::class)] + public array $blocks, + #[RichTextValue] + public string|array|RichText|null $credit = null, + ) {} + + public function getType(): string + { + return 'blockquote'; + } +} diff --git a/src/Type/RichBlockCaption.php b/src/Type/RichBlockCaption.php new file mode 100644 index 00000000..6fe2738d --- /dev/null +++ b/src/Type/RichBlockCaption.php @@ -0,0 +1,22 @@ + $blocks + */ + public function __construct( + #[ArrayMap(RichBlockValue::class)] + public array $blocks, + public ?RichBlockCaption $caption = null, + ) {} + + public function getType(): string + { + return 'collage'; + } +} diff --git a/src/Type/RichBlockDetails.php b/src/Type/RichBlockDetails.php new file mode 100644 index 00000000..83bca953 --- /dev/null +++ b/src/Type/RichBlockDetails.php @@ -0,0 +1,33 @@ + $blocks + */ + public function __construct( + #[RichTextValue] + public string|array|RichText $summary, + #[ArrayMap(RichBlockValue::class)] + public array $blocks, + public ?true $isOpen = null, + ) {} + + public function getType(): string + { + return 'details'; + } +} diff --git a/src/Type/RichBlockDivider.php b/src/Type/RichBlockDivider.php new file mode 100644 index 00000000..8c4f85a3 --- /dev/null +++ b/src/Type/RichBlockDivider.php @@ -0,0 +1,18 @@ + $items + */ + public function __construct( + #[ArrayOfObjectsValue(RichBlockListItem::class)] + public array $items, + ) {} + + public function getType(): string + { + return 'list'; + } +} diff --git a/src/Type/RichBlockListItem.php b/src/Type/RichBlockListItem.php new file mode 100644 index 00000000..547e20f9 --- /dev/null +++ b/src/Type/RichBlockListItem.php @@ -0,0 +1,29 @@ + $blocks + */ + public function __construct( + public string $label, + #[ArrayMap(RichBlockValue::class)] + public array $blocks, + public ?true $hasCheckbox = null, + public ?true $isChecked = null, + public ?int $value = null, + public ?string $type = null, + ) {} +} diff --git a/src/Type/RichBlockMap.php b/src/Type/RichBlockMap.php new file mode 100644 index 00000000..243ab61b --- /dev/null +++ b/src/Type/RichBlockMap.php @@ -0,0 +1,26 @@ + $photo + */ + public function __construct( + #[ArrayOfObjectsValue(PhotoSize::class)] + public array $photo, + public ?true $hasSpoiler = null, + public ?RichBlockCaption $caption = null, + ) {} + + public function getType(): string + { + return 'photo'; + } +} diff --git a/src/Type/RichBlockPreformatted.php b/src/Type/RichBlockPreformatted.php new file mode 100644 index 00000000..750cc4bd --- /dev/null +++ b/src/Type/RichBlockPreformatted.php @@ -0,0 +1,26 @@ + $blocks + */ + public function __construct( + #[ArrayMap(RichBlockValue::class)] + public array $blocks, + public ?RichBlockCaption $caption = null, + ) {} + + public function getType(): string + { + return 'slideshow'; + } +} diff --git a/src/Type/RichBlockTable.php b/src/Type/RichBlockTable.php new file mode 100644 index 00000000..829ea5b3 --- /dev/null +++ b/src/Type/RichBlockTable.php @@ -0,0 +1,33 @@ +> $cells + */ + public function __construct( + #[ArrayOfArraysOfObjectsValue(RichBlockTableCell::class)] + public array $cells, + public ?true $isBordered = null, + public ?true $isStriped = null, + #[RichTextValue] + public string|array|RichText|null $caption = null, + ) {} + + public function getType(): string + { + return 'table'; + } +} diff --git a/src/Type/RichBlockTableCell.php b/src/Type/RichBlockTableCell.php new file mode 100644 index 00000000..0a188422 --- /dev/null +++ b/src/Type/RichBlockTableCell.php @@ -0,0 +1,25 @@ + $blocks + */ + public function __construct( + #[ArrayMap(RichBlockValue::class)] + public array $blocks, + public ?true $isRtl = null, + ) {} +} diff --git a/src/Type/RichText.php b/src/Type/RichText.php new file mode 100644 index 00000000..0291085e --- /dev/null +++ b/src/Type/RichText.php @@ -0,0 +1,15 @@ + $this->hasTopicsEnabled, 'allows_users_to_create_topics' => $this->allowsUsersToCreateTopics, 'can_manage_bots' => $this->canManageBots, + 'supports_join_request_queries' => $this->supportsJoinRequestQueries, ], static fn(mixed $value): bool => $value !== null, ); diff --git a/tests/Method/AnswerChatJoinRequestQueryTest.php b/tests/Method/AnswerChatJoinRequestQueryTest.php new file mode 100644 index 00000000..207b6060 --- /dev/null +++ b/tests/Method/AnswerChatJoinRequestQueryTest.php @@ -0,0 +1,40 @@ +getHttpMethod()); + assertSame('answerChatJoinRequestQuery', $method->getApiMethod()); + assertSame( + [ + 'chat_join_request_query_id' => 'qid1', + 'result' => 'approve', + ], + $method->getData(), + ); + } + + public function testPrepareResult(): void + { + $method = new AnswerChatJoinRequestQuery('qid1', 'approve'); + + $preparedResult = TestHelper::createSuccessStubApi(true)->call($method); + + assertTrue($preparedResult); + } +} diff --git a/tests/Method/SendChatJoinRequestWebAppTest.php b/tests/Method/SendChatJoinRequestWebAppTest.php new file mode 100644 index 00000000..798043cd --- /dev/null +++ b/tests/Method/SendChatJoinRequestWebAppTest.php @@ -0,0 +1,40 @@ +getHttpMethod()); + assertSame('sendChatJoinRequestWebApp', $method->getApiMethod()); + assertSame( + [ + 'chat_join_request_query_id' => 'qid1', + 'web_app_url' => 'https://example.com/app', + ], + $method->getData(), + ); + } + + public function testPrepareResult(): void + { + $method = new SendChatJoinRequestWebApp('qid1', 'https://example.com/app'); + + $preparedResult = TestHelper::createSuccessStubApi(true)->call($method); + + assertTrue($preparedResult); + } +} diff --git a/tests/Method/SendRichMessageDraftTest.php b/tests/Method/SendRichMessageDraftTest.php new file mode 100644 index 00000000..00eea397 --- /dev/null +++ b/tests/Method/SendRichMessageDraftTest.php @@ -0,0 +1,59 @@ +Hello'); + $method = new SendRichMessageDraft(12, 1, $richMessage); + + assertSame(HttpMethod::POST, $method->getHttpMethod()); + assertSame('sendRichMessageDraft', $method->getApiMethod()); + assertSame( + [ + 'chat_id' => 12, + 'draft_id' => 1, + 'rich_message' => $richMessage->toRequestArray(), + ], + $method->getData(), + ); + } + + public function testFull(): void + { + $richMessage = new InputRichMessage(html: 'Hello', isRtl: true); + $method = new SendRichMessageDraft(12, 1, $richMessage, 99); + + assertSame( + [ + 'chat_id' => 12, + 'message_thread_id' => 99, + 'draft_id' => 1, + 'rich_message' => $richMessage->toRequestArray(), + ], + $method->getData(), + ); + } + + public function testPrepareResult(): void + { + $method = new SendRichMessageDraft(12, 1, new InputRichMessage(html: 'Hello')); + + $preparedResult = TestHelper::createSuccessStubApi(true)->call($method); + + assertTrue($preparedResult); + } +} diff --git a/tests/Method/SendRichMessageTest.php b/tests/Method/SendRichMessageTest.php new file mode 100644 index 00000000..9c7b11a8 --- /dev/null +++ b/tests/Method/SendRichMessageTest.php @@ -0,0 +1,91 @@ +Hello')); + + assertSame(HttpMethod::POST, $method->getHttpMethod()); + assertSame('sendRichMessage', $method->getApiMethod()); + assertSame( + [ + 'chat_id' => 12, + 'rich_message' => ['html' => 'Hello'], + ], + $method->getData(), + ); + } + + public function testFull(): void + { + $richMessage = new InputRichMessage(html: 'Hello', isRtl: true); + $replyParameters = new ReplyParameters(23); + $replyMarkup = new ForceReply(); + $suggestedPostParameters = new SuggestedPostParameters(new SuggestedPostPrice('USD', 10)); + $method = new SendRichMessage( + 12, + $richMessage, + 'bcid1', + 99, + 123, + true, + false, + true, + 'meid1', + $suggestedPostParameters, + $replyParameters, + $replyMarkup, + ); + + assertSame( + [ + 'business_connection_id' => 'bcid1', + 'chat_id' => 12, + 'message_thread_id' => 99, + 'direct_messages_topic_id' => 123, + 'rich_message' => ['html' => 'Hello', 'is_rtl' => true], + 'disable_notification' => true, + 'protect_content' => false, + 'allow_paid_broadcast' => true, + 'message_effect_id' => 'meid1', + 'suggested_post_parameters' => $suggestedPostParameters->toRequestArray(), + 'reply_parameters' => $replyParameters->toRequestArray(), + 'reply_markup' => $replyMarkup->toRequestArray(), + ], + $method->getData(), + ); + } + + public function testPrepareResult(): void + { + $method = new SendRichMessage(12, new InputRichMessage(html: 'Hello')); + + $preparedResult = TestHelper::createSuccessStubApi([ + 'message_id' => 7, + 'date' => 1620000000, + 'chat' => [ + 'id' => 1, + 'type' => 'private', + ], + ])->call($method); + + assertSame(7, $preparedResult->messageId); + } +} diff --git a/tests/Method/UpdatingMessage/EditMessageTextTest.php b/tests/Method/UpdatingMessage/EditMessageTextTest.php index 593375dc..c9b41a34 100644 --- a/tests/Method/UpdatingMessage/EditMessageTextTest.php +++ b/tests/Method/UpdatingMessage/EditMessageTextTest.php @@ -11,6 +11,7 @@ use Phptg\BotApi\Tests\Support\TestHelper; use Phptg\BotApi\Type\InlineKeyboardButton; use Phptg\BotApi\Type\InlineKeyboardMarkup; +use Phptg\BotApi\Type\InputRichMessage; use Phptg\BotApi\Type\LinkPreviewOptions; use Phptg\BotApi\Type\Message; use Phptg\BotApi\Type\MessageEntity; @@ -40,6 +41,7 @@ public function testFull(): void $messageEntity = new MessageEntity('bold', 0, 4); $linkPreviewOptions = new LinkPreviewOptions(true); $replyMarkup = new InlineKeyboardMarkup([[new InlineKeyboardButton('hello')]]); + $richMessage = new InputRichMessage(html: 'Hello'); $method = new EditMessageText( 'test', 'bcid1', @@ -50,6 +52,7 @@ public function testFull(): void [$messageEntity], $linkPreviewOptions, $replyMarkup, + $richMessage, ); assertSame( @@ -62,6 +65,7 @@ public function testFull(): void 'parse_mode' => 'HTML', 'entities' => [$messageEntity->toRequestArray()], 'link_preview_options' => $linkPreviewOptions->toRequestArray(), + 'rich_message' => $richMessage->toRequestArray(), 'reply_markup' => $replyMarkup->toRequestArray(), ], $method->getData(), diff --git a/tests/ParseResult/ValueProcessor/RichBlockValueTest.php b/tests/ParseResult/ValueProcessor/RichBlockValueTest.php new file mode 100644 index 00000000..fd0af026 --- /dev/null +++ b/tests/ParseResult/ValueProcessor/RichBlockValueTest.php @@ -0,0 +1,37 @@ +process( + ['type' => 'paragraph', 'text' => 'hello'], + null, + new ObjectFactory(), + ); + + assertInstanceOf(RichBlockParagraph::class, $result); + } + + public function testUnknown(): void + { + $processor = new RichBlockValue(); + $objectFactory = new ObjectFactory(); + + $this->expectException(TelegramParseResultException::class); + $this->expectExceptionMessage('Unknown rich block type.'); + $processor->process(['type' => 'unknown'], null, $objectFactory); + } +} diff --git a/tests/ParseResult/ValueProcessor/RichTextValueTest.php b/tests/ParseResult/ValueProcessor/RichTextValueTest.php new file mode 100644 index 00000000..c9ad1c03 --- /dev/null +++ b/tests/ParseResult/ValueProcessor/RichTextValueTest.php @@ -0,0 +1,93 @@ +process('hello', null, new ObjectFactory()); + + assertIsString($result); + } + + public function testArray(): void + { + $result = (new RichTextValue())->process( + [ + 'hello', + ['type' => 'bold', 'text' => 'world'], + ], + null, + new ObjectFactory(), + ); + + assertEquals(['hello', new RichTextBold('world')], $result); + } + + public function testRichText(): void + { + $result = (new RichTextValue())->process( + ['type' => 'bold', 'text' => 'hello'], + null, + new ObjectFactory(), + ); + + assertEquals(new RichTextBold('hello'), $result); + } + + public function testInvalidType(): void + { + $processor = new RichTextValue(); + $objectFactory = new ObjectFactory(); + + $this->expectException(InvalidTypeOfValueInResultException::class); + $this->expectExceptionMessage('Invalid type of value. Expected type is "string or array", but got "int".'); + $processor->process(42, null, $objectFactory); + } + + public function testMissingTypeKey(): void + { + $processor = new RichTextValue(); + $objectFactory = new ObjectFactory(); + + $this->expectException(NotFoundKeyInResultException::class); + $this->expectExceptionMessage('Not found key "type" in result object.'); + $processor->process(['foo' => 'bar'], null, $objectFactory); + } + + public function testInvalidTypeKey(): void + { + $processor = new RichTextValue(); + $objectFactory = new ObjectFactory(); + + $this->expectException(InvalidTypeOfValueInResultException::class); + $this->expectExceptionMessage( + 'Invalid type of value for key "type". Expected type is "string", but got "int".', + ); + $processor->process(['type' => 42], null, $objectFactory); + } + + public function testUnknownType(): void + { + $processor = new RichTextValue(); + $objectFactory = new ObjectFactory(); + + $this->expectException(TelegramParseResultException::class); + $this->expectExceptionMessage('Unknown rich text type.'); + $processor->process(['type' => 'unknown'], null, $objectFactory); + } +} diff --git a/tests/TelegramBotApi/TelegramBotApiTest.php b/tests/TelegramBotApi/TelegramBotApiTest.php index 00ef28c7..047fb26c 100644 --- a/tests/TelegramBotApi/TelegramBotApiTest.php +++ b/tests/TelegramBotApi/TelegramBotApiTest.php @@ -35,6 +35,7 @@ use Phptg\BotApi\Type\SentGuestMessage; use Phptg\BotApi\Type\InputChecklist; use Phptg\BotApi\Type\InputFile; +use Phptg\BotApi\Type\InputRichMessage; use Phptg\BotApi\Type\InputMediaPhoto; use Phptg\BotApi\Type\InputProfilePhotoStatic; use Phptg\BotApi\Type\InputStoryContentPhoto; @@ -498,6 +499,15 @@ public function testAnswerCallbackQuery(): void assertTrue($result); } + public function testAnswerChatJoinRequestQuery(): void + { + $api = TestHelper::createSuccessStubApi(true); + + $result = $api->answerChatJoinRequestQuery('qid1', 'approve'); + + assertTrue($result); + } + public function testAnswerGuestQuery(): void { $api = TestHelper::createSuccessStubApi([ @@ -2322,6 +2332,41 @@ public function testSendVoice(): void assertSame(7, $result->messageId); } + public function testSendChatJoinRequestWebApp(): void + { + $api = TestHelper::createSuccessStubApi(true); + + $result = $api->sendChatJoinRequestWebApp('qid1', 'https://example.com/app'); + + assertTrue($result); + } + + public function testSendRichMessage(): void + { + $api = TestHelper::createSuccessStubApi([ + 'message_id' => 7, + 'date' => 1620000000, + 'chat' => [ + 'id' => 1, + 'type' => 'private', + ], + ]); + + $result = $api->sendRichMessage(12, new InputRichMessage(html: 'Hello')); + + assertInstanceOf(Message::class, $result); + assertSame(7, $result->messageId); + } + + public function testSendRichMessageDraft(): void + { + $api = TestHelper::createSuccessStubApi(true); + + $result = $api->sendRichMessageDraft(12, 1, new InputRichMessage(html: 'Hello')); + + assertTrue($result); + } + public function testSetChatAdministratorCustomTitle(): void { $api = TestHelper::createSuccessStubApi(true); diff --git a/tests/Type/ChatFullInfoTest.php b/tests/Type/ChatFullInfoTest.php index f5c5f8f4..09e68b8d 100644 --- a/tests/Type/ChatFullInfoTest.php +++ b/tests/Type/ChatFullInfoTest.php @@ -20,6 +20,7 @@ use Phptg\BotApi\Type\ReactionTypeCustomEmoji; use Phptg\BotApi\Type\Audio; use Phptg\BotApi\Type\UniqueGiftColors; +use Phptg\BotApi\Type\User; use Phptg\BotApi\Type\UserRating; use function PHPUnit\Framework\assertCount; @@ -87,6 +88,7 @@ public function testBase(): void assertNull($info->uniqueGiftColors); assertNull($info->paidMessageStarCount); assertNull($info->firstProfileAudio); + assertNull($info->guardBot); } public function testFromTelegramResult(): void @@ -213,6 +215,11 @@ public function testFromTelegramResult(): void 'dark_theme_other_colors' => [0x2A2A2A, 0x3A3A3A], ], 'paid_message_star_count' => 100, + 'guard_bot' => [ + 'id' => 42, + 'is_bot' => true, + 'first_name' => 'GuardBot', + ], ], null, ChatFullInfo::class); assertSame(23, $info->id); @@ -314,5 +321,9 @@ public function testFromTelegramResult(): void assertSame(180, $info->firstProfileAudio->duration); assertSame('Artist', $info->firstProfileAudio->performer); assertSame('Song', $info->firstProfileAudio->title); + + assertInstanceOf(User::class, $info->guardBot); + assertSame(42, $info->guardBot->id); + assertSame('GuardBot', $info->guardBot->firstName); } } diff --git a/tests/Type/ChatJoinRequestTest.php b/tests/Type/ChatJoinRequestTest.php index 2b6719e3..5abaabf6 100644 --- a/tests/Type/ChatJoinRequestTest.php +++ b/tests/Type/ChatJoinRequestTest.php @@ -31,6 +31,7 @@ public function testBase(): void assertSame($date, $chatJoinRequest->date); assertNull($chatJoinRequest->bio); assertNull($chatJoinRequest->inviteLink); + assertNull($chatJoinRequest->queryId); } public function testFromTelegramResult(): void @@ -59,6 +60,7 @@ public function testFromTelegramResult(): void 'is_primary' => false, 'is_revoked' => false, ], + 'query_id' => 'qid123', ]; $chatJoinRequest = (new ObjectFactory())->create($result, null, ChatJoinRequest::class); @@ -75,5 +77,7 @@ public function testFromTelegramResult(): void assertInstanceOf(ChatInviteLink::class, $chatJoinRequest->inviteLink); assertSame('https://t.me/joinchat/x1', $chatJoinRequest->inviteLink->inviteLink); + + assertSame('qid123', $chatJoinRequest->queryId); } } diff --git a/tests/Type/Inline/InputRichMessageContentTest.php b/tests/Type/Inline/InputRichMessageContentTest.php new file mode 100644 index 00000000..83c8e849 --- /dev/null +++ b/tests/Type/Inline/InputRichMessageContentTest.php @@ -0,0 +1,28 @@ +Hello'); + $content = new InputRichMessageContent($richMessage); + + assertSame($richMessage, $content->richMessage); + assertSame( + [ + 'rich_message' => ['html' => 'Hello'], + ], + $content->toRequestArray(), + ); + } +} diff --git a/tests/Type/InputMediaLinkTest.php b/tests/Type/InputMediaLinkTest.php new file mode 100644 index 00000000..f1ffc994 --- /dev/null +++ b/tests/Type/InputMediaLinkTest.php @@ -0,0 +1,44 @@ +getType()); + assertSame( + [ + 'type' => 'link', + 'url' => 'https://example.com', + ], + $inputMedia->toRequestArray(), + ); + } + + public function testBaseWithFileCollector(): void + { + $inputMedia = new InputMediaLink('https://example.com'); + + $fileCollector = new FileCollector(); + assertSame( + [ + 'type' => 'link', + 'url' => 'https://example.com', + ], + $inputMedia->toRequestArray($fileCollector), + ); + assertEmpty($fileCollector->get()); + } +} diff --git a/tests/Type/InputRichMessageTest.php b/tests/Type/InputRichMessageTest.php new file mode 100644 index 00000000..05ab0594 --- /dev/null +++ b/tests/Type/InputRichMessageTest.php @@ -0,0 +1,50 @@ +html); + assertNull($message->markdown); + assertNull($message->isRtl); + assertNull($message->skipEntityDetection); + assertSame([], $message->toRequestArray()); + } + + public function testFull(): void + { + $message = new InputRichMessage( + html: 'Hello', + markdown: '**Hello**', + isRtl: true, + skipEntityDetection: true, + ); + + assertSame('Hello', $message->html); + assertSame('**Hello**', $message->markdown); + assertTrue($message->isRtl); + assertTrue($message->skipEntityDetection); + assertSame( + [ + 'html' => 'Hello', + 'markdown' => '**Hello**', + 'is_rtl' => true, + 'skip_entity_detection' => true, + ], + $message->toRequestArray(), + ); + } +} diff --git a/tests/Type/LinkTest.php b/tests/Type/LinkTest.php new file mode 100644 index 00000000..304b7177 --- /dev/null +++ b/tests/Type/LinkTest.php @@ -0,0 +1,30 @@ +url); + } + + public function testFromTelegramResult(): void + { + $link = (new ObjectFactory())->create([ + 'url' => 'https://example.com', + ], null, Link::class); + + assertSame('https://example.com', $link->url); + } +} diff --git a/tests/Type/MessageTest.php b/tests/Type/MessageTest.php index aafd4dee..4471912f 100644 --- a/tests/Type/MessageTest.php +++ b/tests/Type/MessageTest.php @@ -20,6 +20,7 @@ use Phptg\BotApi\Type\GeneralForumTopicUnhidden; use Phptg\BotApi\Type\GiveawayCreated; use Phptg\BotApi\Type\Message; +use Phptg\BotApi\Type\RichMessage; use Phptg\BotApi\Type\MessageOriginHiddenUser; use Phptg\BotApi\Type\PaidMediaPhoto; use Phptg\BotApi\Type\Payment\RefundedPayment; @@ -263,6 +264,11 @@ public function testFromTelegramResult(): void 'send_date' => 1640995200, ], 'effect_id' => 'e235', + 'rich_message' => [ + 'blocks' => [ + ['type' => 'paragraph', 'text' => 'hello'], + ], + ], 'animation' => [ 'file_id' => 'an1', 'file_unique_id' => 'fu1', @@ -737,6 +743,7 @@ public function testFromTelegramResult(): void assertSame('https://example.com/lpo', $message->linkPreviewOptions?->url); assertSame('e235', $message->effectId); + assertInstanceOf(RichMessage::class, $message->richMessage); assertSame('an1', $message->animation?->fileId); assertSame('f2', $message->audio?->fileId); assertSame('f3', $message->document?->fileId); diff --git a/tests/Type/PollMediaTest.php b/tests/Type/PollMediaTest.php index b88cc376..f24fef69 100644 --- a/tests/Type/PollMediaTest.php +++ b/tests/Type/PollMediaTest.php @@ -6,9 +6,11 @@ use PHPUnit\Framework\TestCase; use Phptg\BotApi\ParseResult\ObjectFactory; +use Phptg\BotApi\Type\Link; use Phptg\BotApi\Type\PollMedia; use function PHPUnit\Framework\assertCount; +use function PHPUnit\Framework\assertInstanceOf; use function PHPUnit\Framework\assertNull; use function PHPUnit\Framework\assertSame; @@ -27,6 +29,7 @@ public function testBase(): void assertNull($pollMedia->sticker); assertNull($pollMedia->venue); assertNull($pollMedia->video); + assertNull($pollMedia->link); } public function testFromTelegramResult(): void @@ -97,6 +100,9 @@ public function testFromTelegramResult(): void 'height' => 1080, 'duration' => 30, ], + 'link' => [ + 'url' => 'https://example.com', + ], ], null, PollMedia::class); assertSame('animation_file_id', $pollMedia->animation?->fileId); @@ -110,5 +116,7 @@ public function testFromTelegramResult(): void assertSame('sticker_file_id', $pollMedia->sticker?->fileId); assertSame('Kremlin', $pollMedia->venue?->title); assertSame('video_file_id', $pollMedia->video?->fileId); + assertInstanceOf(Link::class, $pollMedia->link); + assertSame('https://example.com', $pollMedia->link->url); } } diff --git a/tests/Type/RichBlockAnchorTest.php b/tests/Type/RichBlockAnchorTest.php new file mode 100644 index 00000000..38f8a4eb --- /dev/null +++ b/tests/Type/RichBlockAnchorTest.php @@ -0,0 +1,33 @@ +getType()); + assertSame('section1', $anchor->name); + } + + public function testFromTelegramResult(): void + { + $anchor = (new ObjectFactory())->create([ + 'type' => 'anchor', + 'name' => 'section1', + ], null, RichBlockAnchor::class); + + assertSame('anchor', $anchor->getType()); + assertSame('section1', $anchor->name); + } +} diff --git a/tests/Type/RichBlockAnimationTest.php b/tests/Type/RichBlockAnimationTest.php new file mode 100644 index 00000000..df9a4ea3 --- /dev/null +++ b/tests/Type/RichBlockAnimationTest.php @@ -0,0 +1,81 @@ +getType()); + assertSame($animation, $block->animation); + assertNull($block->hasSpoiler); + assertNull($block->caption); + } + + public function testFull(): void + { + $animation = new Animation('f123', 'fullF123', 640, 480, 10); + $caption = new RichBlockCaption('animation'); + $block = new RichBlockAnimation($animation, true, $caption); + + assertSame('animation', $block->getType()); + assertTrue($block->hasSpoiler); + assertSame($caption, $block->caption); + } + + public function testFromTelegramResult(): void + { + $block = (new ObjectFactory())->create([ + 'type' => 'animation', + 'animation' => [ + 'file_id' => 'f123', + 'file_unique_id' => 'fullF123', + 'width' => 640, + 'height' => 480, + 'duration' => 10, + ], + ], null, RichBlockAnimation::class); + + assertSame('animation', $block->getType()); + assertInstanceOf(Animation::class, $block->animation); + assertNull($block->hasSpoiler); + assertNull($block->caption); + } + + public function testFromTelegramResultFull(): void + { + $block = (new ObjectFactory())->create([ + 'type' => 'animation', + 'animation' => [ + 'file_id' => 'f123', + 'file_unique_id' => 'fullF123', + 'width' => 640, + 'height' => 480, + 'duration' => 10, + ], + 'has_spoiler' => true, + 'caption' => ['text' => 'animation'], + ], null, RichBlockAnimation::class); + + assertSame('animation', $block->getType()); + assertInstanceOf(Animation::class, $block->animation); + assertTrue($block->hasSpoiler); + assertInstanceOf(RichBlockCaption::class, $block->caption); + } +} diff --git a/tests/Type/RichBlockAudioTest.php b/tests/Type/RichBlockAudioTest.php new file mode 100644 index 00000000..17c95ede --- /dev/null +++ b/tests/Type/RichBlockAudioTest.php @@ -0,0 +1,71 @@ +getType()); + assertSame($audio, $block->audio); + assertNull($block->caption); + } + + public function testFull(): void + { + $audio = new Audio('f123', 'fullF123', 180); + $caption = new RichBlockCaption('audio'); + $block = new RichBlockAudio($audio, $caption); + + assertSame('audio', $block->getType()); + assertSame($caption, $block->caption); + } + + public function testFromTelegramResult(): void + { + $block = (new ObjectFactory())->create([ + 'type' => 'audio', + 'audio' => [ + 'file_id' => 'f123', + 'file_unique_id' => 'fullF123', + 'duration' => 180, + ], + ], null, RichBlockAudio::class); + + assertSame('audio', $block->getType()); + assertInstanceOf(Audio::class, $block->audio); + assertNull($block->caption); + } + + public function testFromTelegramResultFull(): void + { + $block = (new ObjectFactory())->create([ + 'type' => 'audio', + 'audio' => [ + 'file_id' => 'f123', + 'file_unique_id' => 'fullF123', + 'duration' => 180, + ], + 'caption' => ['text' => 'audio'], + ], null, RichBlockAudio::class); + + assertSame('audio', $block->getType()); + assertInstanceOf(Audio::class, $block->audio); + assertInstanceOf(RichBlockCaption::class, $block->caption); + } +} diff --git a/tests/Type/RichBlockBlockQuotationTest.php b/tests/Type/RichBlockBlockQuotationTest.php new file mode 100644 index 00000000..87dc3631 --- /dev/null +++ b/tests/Type/RichBlockBlockQuotationTest.php @@ -0,0 +1,69 @@ +getType()); + assertCount(1, $blockquote->blocks); + assertNull($blockquote->credit); + } + + public function testFull(): void + { + $blockquote = new RichBlockBlockQuotation([new RichBlockParagraph('hello')], 'credit'); + + assertSame('blockquote', $blockquote->getType()); + assertCount(1, $blockquote->blocks); + assertSame('credit', $blockquote->credit); + } + + public function testFromTelegramResult(): void + { + $blockquote = (new ObjectFactory())->create([ + 'type' => 'blockquote', + 'blocks' => [ + ['type' => 'paragraph', 'text' => 'hello'], + ], + ], null, RichBlockBlockQuotation::class); + + assertSame('blockquote', $blockquote->getType()); + assertCount(1, $blockquote->blocks); + assertInstanceOf(RichBlockParagraph::class, $blockquote->blocks[0]); + assertNull($blockquote->credit); + } + + public function testFromTelegramResultFull(): void + { + $blockquote = (new ObjectFactory())->create([ + 'type' => 'blockquote', + 'blocks' => [ + ['type' => 'paragraph', 'text' => 'hello'], + ], + 'credit' => ['type' => 'bold', 'text' => 'author'], + ], null, RichBlockBlockQuotation::class); + + assertSame('blockquote', $blockquote->getType()); + assertCount(1, $blockquote->blocks); + assertInstanceOf(RichBlockParagraph::class, $blockquote->blocks[0]); + assertInstanceOf(RichTextBold::class, $blockquote->credit); + assertSame('author', $blockquote->credit->text); + } +} diff --git a/tests/Type/RichBlockCaptionTest.php b/tests/Type/RichBlockCaptionTest.php new file mode 100644 index 00000000..149c2e35 --- /dev/null +++ b/tests/Type/RichBlockCaptionTest.php @@ -0,0 +1,55 @@ +text); + assertNull($caption->credit); + } + + public function testFull(): void + { + $caption = new RichBlockCaption('hello', 'world'); + + assertSame('hello', $caption->text); + assertSame('world', $caption->credit); + } + + public function testFromTelegramResult(): void + { + $caption = (new ObjectFactory())->create([ + 'text' => 'hello', + ], null, RichBlockCaption::class); + + assertSame('hello', $caption->text); + assertNull($caption->credit); + } + + public function testFromTelegramResultFull(): void + { + $caption = (new ObjectFactory())->create([ + 'text' => 'hello', + 'credit' => ['type' => 'bold', 'text' => 'world'], + ], null, RichBlockCaption::class); + + assertSame('hello', $caption->text); + assertInstanceOf(RichTextBold::class, $caption->credit); + assertSame('world', $caption->credit->text); + } +} diff --git a/tests/Type/RichBlockCollageTest.php b/tests/Type/RichBlockCollageTest.php new file mode 100644 index 00000000..bf1b02b3 --- /dev/null +++ b/tests/Type/RichBlockCollageTest.php @@ -0,0 +1,69 @@ +getType()); + assertCount(1, $collage->blocks); + assertNull($collage->caption); + } + + public function testFull(): void + { + $caption = new RichBlockCaption('caption text'); + $collage = new RichBlockCollage([new RichBlockParagraph('hello')], $caption); + + assertSame('collage', $collage->getType()); + assertCount(1, $collage->blocks); + assertSame($caption, $collage->caption); + } + + public function testFromTelegramResult(): void + { + $collage = (new ObjectFactory())->create([ + 'type' => 'collage', + 'blocks' => [ + ['type' => 'paragraph', 'text' => 'hello'], + ], + ], null, RichBlockCollage::class); + + assertSame('collage', $collage->getType()); + assertCount(1, $collage->blocks); + assertInstanceOf(RichBlockParagraph::class, $collage->blocks[0]); + assertNull($collage->caption); + } + + public function testFromTelegramResultFull(): void + { + $collage = (new ObjectFactory())->create([ + 'type' => 'collage', + 'blocks' => [ + ['type' => 'paragraph', 'text' => 'hello'], + ], + 'caption' => ['text' => 'caption text'], + ], null, RichBlockCollage::class); + + assertSame('collage', $collage->getType()); + assertCount(1, $collage->blocks); + assertInstanceOf(RichBlockParagraph::class, $collage->blocks[0]); + assertInstanceOf(RichBlockCaption::class, $collage->caption); + } +} diff --git a/tests/Type/RichBlockDetailsTest.php b/tests/Type/RichBlockDetailsTest.php new file mode 100644 index 00000000..822358b6 --- /dev/null +++ b/tests/Type/RichBlockDetailsTest.php @@ -0,0 +1,76 @@ +getType()); + assertSame('summary', $details->summary); + assertCount(1, $details->blocks); + assertNull($details->isOpen); + } + + public function testFull(): void + { + $details = new RichBlockDetails('summary', [new RichBlockParagraph('hello')], true); + + assertSame('details', $details->getType()); + assertSame('summary', $details->summary); + assertCount(1, $details->blocks); + assertTrue($details->isOpen); + } + + public function testFromTelegramResult(): void + { + $details = (new ObjectFactory())->create([ + 'type' => 'details', + 'summary' => 'summary', + 'blocks' => [ + ['type' => 'paragraph', 'text' => 'hello'], + ], + ], null, RichBlockDetails::class); + + assertSame('details', $details->getType()); + assertSame('summary', $details->summary); + assertCount(1, $details->blocks); + assertInstanceOf(RichBlockParagraph::class, $details->blocks[0]); + assertNull($details->isOpen); + } + + public function testFromTelegramResultFull(): void + { + $details = (new ObjectFactory())->create([ + 'type' => 'details', + 'summary' => ['type' => 'bold', 'text' => 'summary'], + 'blocks' => [ + ['type' => 'paragraph', 'text' => 'hello'], + ], + 'is_open' => true, + ], null, RichBlockDetails::class); + + assertSame('details', $details->getType()); + assertInstanceOf(RichTextBold::class, $details->summary); + assertSame('summary', $details->summary->text); + assertCount(1, $details->blocks); + assertInstanceOf(RichBlockParagraph::class, $details->blocks[0]); + assertTrue($details->isOpen); + } +} diff --git a/tests/Type/RichBlockDividerTest.php b/tests/Type/RichBlockDividerTest.php new file mode 100644 index 00000000..4ce69325 --- /dev/null +++ b/tests/Type/RichBlockDividerTest.php @@ -0,0 +1,30 @@ +getType()); + } + + public function testFromTelegramResult(): void + { + $divider = (new ObjectFactory())->create([ + 'type' => 'divider', + ], null, RichBlockDivider::class); + + assertSame('divider', $divider->getType()); + } +} diff --git a/tests/Type/RichBlockFooterTest.php b/tests/Type/RichBlockFooterTest.php new file mode 100644 index 00000000..541c1206 --- /dev/null +++ b/tests/Type/RichBlockFooterTest.php @@ -0,0 +1,33 @@ +getType()); + assertSame('hello', $footer->text); + } + + public function testFromTelegramResult(): void + { + $footer = (new ObjectFactory())->create([ + 'type' => 'footer', + 'text' => 'hello', + ], null, RichBlockFooter::class); + + assertSame('footer', $footer->getType()); + assertSame('hello', $footer->text); + } +} diff --git a/tests/Type/RichBlockListItemTest.php b/tests/Type/RichBlockListItemTest.php new file mode 100644 index 00000000..fa403bda --- /dev/null +++ b/tests/Type/RichBlockListItemTest.php @@ -0,0 +1,82 @@ +label); + assertCount(1, $item->blocks); + assertNull($item->hasCheckbox); + assertNull($item->isChecked); + assertNull($item->value); + assertNull($item->type); + } + + public function testFull(): void + { + $item = new RichBlockListItem('1.', [new RichBlockParagraph('hello')], true, true, 1, 'a'); + + assertSame('1.', $item->label); + assertTrue($item->hasCheckbox); + assertTrue($item->isChecked); + assertSame(1, $item->value); + assertSame('a', $item->type); + } + + public function testFromTelegramResult(): void + { + $item = (new ObjectFactory())->create([ + 'label' => '1.', + 'blocks' => [ + ['type' => 'paragraph', 'text' => 'hello'], + ], + ], null, RichBlockListItem::class); + + assertSame('1.', $item->label); + assertCount(1, $item->blocks); + assertInstanceOf(RichBlockParagraph::class, $item->blocks[0]); + assertNull($item->hasCheckbox); + assertNull($item->isChecked); + assertNull($item->value); + assertNull($item->type); + } + + public function testFromTelegramResultFull(): void + { + $item = (new ObjectFactory())->create([ + 'label' => '1.', + 'blocks' => [ + ['type' => 'paragraph', 'text' => 'hello'], + ], + 'has_checkbox' => true, + 'is_checked' => true, + 'value' => 1, + 'type' => 'a', + ], null, RichBlockListItem::class); + + assertSame('1.', $item->label); + assertCount(1, $item->blocks); + assertInstanceOf(RichBlockParagraph::class, $item->blocks[0]); + assertTrue($item->hasCheckbox); + assertTrue($item->isChecked); + assertSame(1, $item->value); + assertSame('a', $item->type); + } +} diff --git a/tests/Type/RichBlockListTest.php b/tests/Type/RichBlockListTest.php new file mode 100644 index 00000000..076e6dd7 --- /dev/null +++ b/tests/Type/RichBlockListTest.php @@ -0,0 +1,42 @@ +getType()); + assertCount(1, $list->items); + } + + public function testFromTelegramResult(): void + { + $list = (new ObjectFactory())->create([ + 'type' => 'list', + 'items' => [ + ['label' => '1.', 'blocks' => []], + ['label' => '2.', 'blocks' => []], + ], + ], null, RichBlockList::class); + + assertSame('list', $list->getType()); + assertCount(2, $list->items); + assertInstanceOf(RichBlockListItem::class, $list->items[0]); + assertSame('1.', $list->items[0]->label); + assertSame('2.', $list->items[1]->label); + } +} diff --git a/tests/Type/RichBlockMapTest.php b/tests/Type/RichBlockMapTest.php new file mode 100644 index 00000000..4df5d7c7 --- /dev/null +++ b/tests/Type/RichBlockMapTest.php @@ -0,0 +1,82 @@ +getType()); + assertSame($location, $map->location); + assertSame(15, $map->zoom); + assertSame(800, $map->width); + assertSame(600, $map->height); + assertNull($map->caption); + } + + public function testFull(): void + { + $location = new Location(55.75, 37.62); + $caption = new RichBlockCaption('Moscow'); + $map = new RichBlockMap($location, 15, 800, 600, $caption); + + assertSame('map', $map->getType()); + assertSame($location, $map->location); + assertSame(15, $map->zoom); + assertSame(800, $map->width); + assertSame(600, $map->height); + assertSame($caption, $map->caption); + } + + public function testFromTelegramResult(): void + { + $map = (new ObjectFactory())->create([ + 'type' => 'map', + 'location' => ['latitude' => 55.75, 'longitude' => 37.62], + 'zoom' => 15, + 'width' => 800, + 'height' => 600, + ], null, RichBlockMap::class); + + assertSame('map', $map->getType()); + assertInstanceOf(Location::class, $map->location); + assertSame(15, $map->zoom); + assertSame(800, $map->width); + assertSame(600, $map->height); + assertNull($map->caption); + } + + public function testFromTelegramResultFull(): void + { + $map = (new ObjectFactory())->create([ + 'type' => 'map', + 'location' => ['latitude' => 55.75, 'longitude' => 37.62], + 'zoom' => 15, + 'width' => 800, + 'height' => 600, + 'caption' => ['text' => 'Moscow'], + ], null, RichBlockMap::class); + + assertSame('map', $map->getType()); + assertInstanceOf(Location::class, $map->location); + assertSame(15, $map->zoom); + assertSame(800, $map->width); + assertSame(600, $map->height); + assertInstanceOf(RichBlockCaption::class, $map->caption); + } +} diff --git a/tests/Type/RichBlockMathematicalExpressionTest.php b/tests/Type/RichBlockMathematicalExpressionTest.php new file mode 100644 index 00000000..85a99673 --- /dev/null +++ b/tests/Type/RichBlockMathematicalExpressionTest.php @@ -0,0 +1,33 @@ +getType()); + assertSame('E = mc^2', $expression->expression); + } + + public function testFromTelegramResult(): void + { + $expression = (new ObjectFactory())->create([ + 'type' => 'mathematical_expression', + 'expression' => 'E = mc^2', + ], null, RichBlockMathematicalExpression::class); + + assertSame('mathematical_expression', $expression->getType()); + assertSame('E = mc^2', $expression->expression); + } +} diff --git a/tests/Type/RichBlockParagraphTest.php b/tests/Type/RichBlockParagraphTest.php new file mode 100644 index 00000000..a6ef7f89 --- /dev/null +++ b/tests/Type/RichBlockParagraphTest.php @@ -0,0 +1,33 @@ +getType()); + assertSame('hello', $paragraph->text); + } + + public function testFromTelegramResult(): void + { + $paragraph = (new ObjectFactory())->create([ + 'type' => 'paragraph', + 'text' => 'hello', + ], null, RichBlockParagraph::class); + + assertSame('paragraph', $paragraph->getType()); + assertSame('hello', $paragraph->text); + } +} diff --git a/tests/Type/RichBlockPhotoTest.php b/tests/Type/RichBlockPhotoTest.php new file mode 100644 index 00000000..ef368a9c --- /dev/null +++ b/tests/Type/RichBlockPhotoTest.php @@ -0,0 +1,77 @@ +getType()); + assertCount(1, $block->photo); + assertNull($block->hasSpoiler); + assertNull($block->caption); + } + + public function testFull(): void + { + $photo = new PhotoSize('f123', 'fullF123', 640, 480); + $caption = new RichBlockCaption('photo'); + $block = new RichBlockPhoto([$photo], true, $caption); + + assertSame('photo', $block->getType()); + assertTrue($block->hasSpoiler); + assertSame($caption, $block->caption); + } + + public function testFromTelegramResult(): void + { + $block = (new ObjectFactory())->create([ + 'type' => 'photo', + 'photo' => [ + ['file_id' => 'f123', 'file_unique_id' => 'fullF123', 'width' => 640, 'height' => 480], + ['file_id' => 'f456', 'file_unique_id' => 'fullF456', 'width' => 320, 'height' => 240], + ], + ], null, RichBlockPhoto::class); + + assertSame('photo', $block->getType()); + assertCount(2, $block->photo); + assertInstanceOf(PhotoSize::class, $block->photo[0]); + assertInstanceOf(PhotoSize::class, $block->photo[1]); + assertNull($block->hasSpoiler); + assertNull($block->caption); + } + + public function testFromTelegramResultFull(): void + { + $block = (new ObjectFactory())->create([ + 'type' => 'photo', + 'photo' => [ + ['file_id' => 'f123', 'file_unique_id' => 'fullF123', 'width' => 640, 'height' => 480], + ], + 'has_spoiler' => true, + 'caption' => ['text' => 'photo'], + ], null, RichBlockPhoto::class); + + assertSame('photo', $block->getType()); + assertCount(1, $block->photo); + assertTrue($block->hasSpoiler); + assertInstanceOf(RichBlockCaption::class, $block->caption); + } +} diff --git a/tests/Type/RichBlockPreformattedTest.php b/tests/Type/RichBlockPreformattedTest.php new file mode 100644 index 00000000..01221ad2 --- /dev/null +++ b/tests/Type/RichBlockPreformattedTest.php @@ -0,0 +1,61 @@ +getType()); + assertSame('hello', $pre->text); + assertNull($pre->language); + } + + public function testFull(): void + { + $pre = new RichBlockPreformatted('hello', 'php'); + + assertSame('pre', $pre->getType()); + assertSame('hello', $pre->text); + assertSame('php', $pre->language); + } + + public function testFromTelegramResult(): void + { + $pre = (new ObjectFactory())->create([ + 'type' => 'pre', + 'text' => 'hello', + ], null, RichBlockPreformatted::class); + + assertSame('pre', $pre->getType()); + assertSame('hello', $pre->text); + assertNull($pre->language); + } + + public function testFromTelegramResultFull(): void + { + $pre = (new ObjectFactory())->create([ + 'type' => 'pre', + 'text' => ['type' => 'bold', 'text' => 'hello'], + 'language' => 'python', + ], null, RichBlockPreformatted::class); + + assertSame('pre', $pre->getType()); + assertInstanceOf(RichTextBold::class, $pre->text); + assertSame('hello', $pre->text->text); + assertSame('python', $pre->language); + } +} diff --git a/tests/Type/RichBlockPullQuotationTest.php b/tests/Type/RichBlockPullQuotationTest.php new file mode 100644 index 00000000..8f6785bf --- /dev/null +++ b/tests/Type/RichBlockPullQuotationTest.php @@ -0,0 +1,62 @@ +getType()); + assertSame('hello', $pullquote->text); + assertNull($pullquote->credit); + } + + public function testFull(): void + { + $pullquote = new RichBlockPullQuotation('hello', 'credit'); + + assertSame('pullquote', $pullquote->getType()); + assertSame('hello', $pullquote->text); + assertSame('credit', $pullquote->credit); + } + + public function testFromTelegramResult(): void + { + $pullquote = (new ObjectFactory())->create([ + 'type' => 'pullquote', + 'text' => 'hello', + ], null, RichBlockPullQuotation::class); + + assertSame('pullquote', $pullquote->getType()); + assertSame('hello', $pullquote->text); + assertNull($pullquote->credit); + } + + public function testFromTelegramResultFull(): void + { + $pullquote = (new ObjectFactory())->create([ + 'type' => 'pullquote', + 'text' => ['type' => 'bold', 'text' => 'hello'], + 'credit' => ['type' => 'bold', 'text' => 'author'], + ], null, RichBlockPullQuotation::class); + + assertSame('pullquote', $pullquote->getType()); + assertInstanceOf(RichTextBold::class, $pullquote->text); + assertSame('hello', $pullquote->text->text); + assertInstanceOf(RichTextBold::class, $pullquote->credit); + assertSame('author', $pullquote->credit->text); + } +} diff --git a/tests/Type/RichBlockSectionHeadingTest.php b/tests/Type/RichBlockSectionHeadingTest.php new file mode 100644 index 00000000..47dca1f6 --- /dev/null +++ b/tests/Type/RichBlockSectionHeadingTest.php @@ -0,0 +1,36 @@ +getType()); + assertSame('hello', $heading->text); + assertSame(1, $heading->size); + } + + public function testFromTelegramResult(): void + { + $heading = (new ObjectFactory())->create([ + 'type' => 'heading', + 'text' => 'hello', + 'size' => 2, + ], null, RichBlockSectionHeading::class); + + assertSame('heading', $heading->getType()); + assertSame('hello', $heading->text); + assertSame(2, $heading->size); + } +} diff --git a/tests/Type/RichBlockSlideshowTest.php b/tests/Type/RichBlockSlideshowTest.php new file mode 100644 index 00000000..b1119d6f --- /dev/null +++ b/tests/Type/RichBlockSlideshowTest.php @@ -0,0 +1,69 @@ +getType()); + assertCount(1, $slideshow->blocks); + assertNull($slideshow->caption); + } + + public function testFull(): void + { + $caption = new RichBlockCaption('caption text'); + $slideshow = new RichBlockSlideshow([new RichBlockParagraph('hello')], $caption); + + assertSame('slideshow', $slideshow->getType()); + assertCount(1, $slideshow->blocks); + assertSame($caption, $slideshow->caption); + } + + public function testFromTelegramResult(): void + { + $slideshow = (new ObjectFactory())->create([ + 'type' => 'slideshow', + 'blocks' => [ + ['type' => 'paragraph', 'text' => 'hello'], + ], + ], null, RichBlockSlideshow::class); + + assertSame('slideshow', $slideshow->getType()); + assertCount(1, $slideshow->blocks); + assertInstanceOf(RichBlockParagraph::class, $slideshow->blocks[0]); + assertNull($slideshow->caption); + } + + public function testFromTelegramResultFull(): void + { + $slideshow = (new ObjectFactory())->create([ + 'type' => 'slideshow', + 'blocks' => [ + ['type' => 'paragraph', 'text' => 'hello'], + ], + 'caption' => ['text' => 'caption text'], + ], null, RichBlockSlideshow::class); + + assertSame('slideshow', $slideshow->getType()); + assertCount(1, $slideshow->blocks); + assertInstanceOf(RichBlockParagraph::class, $slideshow->blocks[0]); + assertInstanceOf(RichBlockCaption::class, $slideshow->caption); + } +} diff --git a/tests/Type/RichBlockTableCellTest.php b/tests/Type/RichBlockTableCellTest.php new file mode 100644 index 00000000..061e018e --- /dev/null +++ b/tests/Type/RichBlockTableCellTest.php @@ -0,0 +1,77 @@ +align); + assertSame('top', $cell->valign); + assertNull($cell->text); + assertNull($cell->isHeader); + assertNull($cell->colspan); + assertNull($cell->rowspan); + } + + public function testFull(): void + { + $cell = new RichBlockTableCell('center', 'middle', 'hello', true, 2, 3); + + assertSame('center', $cell->align); + assertSame('middle', $cell->valign); + assertSame('hello', $cell->text); + assertTrue($cell->isHeader); + assertSame(2, $cell->colspan); + assertSame(3, $cell->rowspan); + } + + public function testFromTelegramResult(): void + { + $cell = (new ObjectFactory())->create([ + 'align' => 'left', + 'valign' => 'top', + ], null, RichBlockTableCell::class); + + assertSame('left', $cell->align); + assertSame('top', $cell->valign); + assertNull($cell->text); + assertNull($cell->isHeader); + assertNull($cell->colspan); + assertNull($cell->rowspan); + } + + public function testFromTelegramResultFull(): void + { + $cell = (new ObjectFactory())->create([ + 'align' => 'center', + 'valign' => 'middle', + 'text' => ['type' => 'bold', 'text' => 'hello'], + 'is_header' => true, + 'colspan' => 2, + 'rowspan' => 3, + ], null, RichBlockTableCell::class); + + assertSame('center', $cell->align); + assertSame('middle', $cell->valign); + assertInstanceOf(RichTextBold::class, $cell->text); + assertSame('hello', $cell->text->text); + assertTrue($cell->isHeader); + assertSame(2, $cell->colspan); + assertSame(3, $cell->rowspan); + } +} diff --git a/tests/Type/RichBlockTableTest.php b/tests/Type/RichBlockTableTest.php new file mode 100644 index 00000000..5095041a --- /dev/null +++ b/tests/Type/RichBlockTableTest.php @@ -0,0 +1,98 @@ +getType()); + assertCount(1, $table->cells); + assertCount(1, $table->cells[0]); + assertSame('left', $table->cells[0][0]->align); + assertSame('top', $table->cells[0][0]->valign); + assertNull($table->isBordered); + assertNull($table->isStriped); + assertNull($table->caption); + } + + public function testFull(): void + { + $cell = new RichBlockTableCell('center', 'middle'); + $table = new RichBlockTable([[$cell]], true, true, 'caption'); + + assertSame('table', $table->getType()); + assertCount(1, $table->cells); + assertCount(1, $table->cells[0]); + assertSame('center', $table->cells[0][0]->align); + assertSame('middle', $table->cells[0][0]->valign); + assertTrue($table->isBordered); + assertTrue($table->isStriped); + assertSame('caption', $table->caption); + } + + public function testFromTelegramResult(): void + { + $table = (new ObjectFactory())->create([ + 'type' => 'table', + 'cells' => [ + [ + ['align' => 'left', 'valign' => 'top'], + ], + ], + ], null, RichBlockTable::class); + + assertSame('table', $table->getType()); + assertCount(1, $table->cells); + assertCount(1, $table->cells[0]); + assertInstanceOf(RichBlockTableCell::class, $table->cells[0][0]); + assertSame('left', $table->cells[0][0]->align); + assertSame('top', $table->cells[0][0]->valign); + assertNull($table->isBordered); + assertNull($table->isStriped); + assertNull($table->caption); + } + + public function testFromTelegramResultFull(): void + { + $table = (new ObjectFactory())->create([ + 'type' => 'table', + 'cells' => [ + [ + ['align' => 'center', 'valign' => 'middle'], + ], + ], + 'is_bordered' => true, + 'is_striped' => true, + 'caption' => ['type' => 'bold', 'text' => 'caption'], + ], null, RichBlockTable::class); + + assertSame('table', $table->getType()); + assertCount(1, $table->cells); + assertCount(1, $table->cells[0]); + assertInstanceOf(RichBlockTableCell::class, $table->cells[0][0]); + assertSame('center', $table->cells[0][0]->align); + assertSame('middle', $table->cells[0][0]->valign); + assertTrue($table->isBordered); + assertTrue($table->isStriped); + assertInstanceOf(RichTextBold::class, $table->caption); + assertSame('caption', $table->caption->text); + } +} diff --git a/tests/Type/RichBlockThinkingTest.php b/tests/Type/RichBlockThinkingTest.php new file mode 100644 index 00000000..6ba41f10 --- /dev/null +++ b/tests/Type/RichBlockThinkingTest.php @@ -0,0 +1,47 @@ +getType()); + assertSame('thinking...', $thinking->text); + } + + public function testFromTelegramResult(): void + { + $thinking = (new ObjectFactory())->create([ + 'type' => 'thinking', + 'text' => 'thinking...', + ], null, RichBlockThinking::class); + + assertSame('thinking', $thinking->getType()); + assertSame('thinking...', $thinking->text); + } + + public function testFromTelegramResultFull(): void + { + $thinking = (new ObjectFactory())->create([ + 'type' => 'thinking', + 'text' => ['type' => 'bold', 'text' => 'thinking...'], + ], null, RichBlockThinking::class); + + assertSame('thinking', $thinking->getType()); + assertInstanceOf(RichTextBold::class, $thinking->text); + assertSame('thinking...', $thinking->text->text); + } +} diff --git a/tests/Type/RichBlockVideoTest.php b/tests/Type/RichBlockVideoTest.php new file mode 100644 index 00000000..be4d7a26 --- /dev/null +++ b/tests/Type/RichBlockVideoTest.php @@ -0,0 +1,81 @@ +getType()); + assertSame($video, $block->video); + assertNull($block->hasSpoiler); + assertNull($block->caption); + } + + public function testFull(): void + { + $video = new Video('f123', 'fullF123', 640, 480, 60); + $caption = new RichBlockCaption('video'); + $block = new RichBlockVideo($video, true, $caption); + + assertSame('video', $block->getType()); + assertTrue($block->hasSpoiler); + assertSame($caption, $block->caption); + } + + public function testFromTelegramResult(): void + { + $block = (new ObjectFactory())->create([ + 'type' => 'video', + 'video' => [ + 'file_id' => 'f123', + 'file_unique_id' => 'fullF123', + 'width' => 640, + 'height' => 480, + 'duration' => 60, + ], + ], null, RichBlockVideo::class); + + assertSame('video', $block->getType()); + assertInstanceOf(Video::class, $block->video); + assertNull($block->hasSpoiler); + assertNull($block->caption); + } + + public function testFromTelegramResultFull(): void + { + $block = (new ObjectFactory())->create([ + 'type' => 'video', + 'video' => [ + 'file_id' => 'f123', + 'file_unique_id' => 'fullF123', + 'width' => 640, + 'height' => 480, + 'duration' => 60, + ], + 'has_spoiler' => true, + 'caption' => ['text' => 'video'], + ], null, RichBlockVideo::class); + + assertSame('video', $block->getType()); + assertInstanceOf(Video::class, $block->video); + assertTrue($block->hasSpoiler); + assertInstanceOf(RichBlockCaption::class, $block->caption); + } +} diff --git a/tests/Type/RichBlockVoiceNoteTest.php b/tests/Type/RichBlockVoiceNoteTest.php new file mode 100644 index 00000000..21651ce2 --- /dev/null +++ b/tests/Type/RichBlockVoiceNoteTest.php @@ -0,0 +1,71 @@ +getType()); + assertSame($voice, $block->voiceNote); + assertNull($block->caption); + } + + public function testFull(): void + { + $voice = new Voice('f123', 'fullF123', 60); + $caption = new RichBlockCaption('voice note'); + $block = new RichBlockVoiceNote($voice, $caption); + + assertSame('voice_note', $block->getType()); + assertSame($caption, $block->caption); + } + + public function testFromTelegramResult(): void + { + $block = (new ObjectFactory())->create([ + 'type' => 'voice_note', + 'voice_note' => [ + 'file_id' => 'f123', + 'file_unique_id' => 'fullF123', + 'duration' => 60, + ], + ], null, RichBlockVoiceNote::class); + + assertSame('voice_note', $block->getType()); + assertInstanceOf(Voice::class, $block->voiceNote); + assertNull($block->caption); + } + + public function testFromTelegramResultFull(): void + { + $block = (new ObjectFactory())->create([ + 'type' => 'voice_note', + 'voice_note' => [ + 'file_id' => 'f123', + 'file_unique_id' => 'fullF123', + 'duration' => 60, + ], + 'caption' => ['text' => 'voice note'], + ], null, RichBlockVoiceNote::class); + + assertSame('voice_note', $block->getType()); + assertInstanceOf(Voice::class, $block->voiceNote); + assertInstanceOf(RichBlockCaption::class, $block->caption); + } +} diff --git a/tests/Type/RichMessageTest.php b/tests/Type/RichMessageTest.php new file mode 100644 index 00000000..203405c8 --- /dev/null +++ b/tests/Type/RichMessageTest.php @@ -0,0 +1,61 @@ +blocks); + assertNull($message->isRtl); + } + + public function testFull(): void + { + $message = new RichMessage([new RichBlockParagraph('hello')], true); + + assertCount(1, $message->blocks); + assertTrue($message->isRtl); + } + + public function testFromTelegramResult(): void + { + $message = (new ObjectFactory())->create([ + 'blocks' => [ + ['type' => 'paragraph', 'text' => 'hello'], + ], + ], null, RichMessage::class); + + assertCount(1, $message->blocks); + assertInstanceOf(RichBlockParagraph::class, $message->blocks[0]); + assertNull($message->isRtl); + } + + public function testFromTelegramResultFull(): void + { + $message = (new ObjectFactory())->create([ + 'blocks' => [ + ['type' => 'paragraph', 'text' => 'hello'], + ], + 'is_rtl' => true, + ], null, RichMessage::class); + + assertCount(1, $message->blocks); + assertInstanceOf(RichBlockParagraph::class, $message->blocks[0]); + assertTrue($message->isRtl); + } +} diff --git a/tests/Type/RichTextAnchorLinkTest.php b/tests/Type/RichTextAnchorLinkTest.php new file mode 100644 index 00000000..d367f859 --- /dev/null +++ b/tests/Type/RichTextAnchorLinkTest.php @@ -0,0 +1,47 @@ +getType()); + assertSame('hello', $anchorLink->text); + assertSame('section1', $anchorLink->anchorName); + } + + public function testFromTelegramResult(): void + { + $anchorLink = (new ObjectFactory())->create([ + 'type' => 'anchor_link', + 'text' => 'hello', + 'anchor_name' => 'section1', + ], null, RichTextAnchorLink::class); + + assertSame('anchor_link', $anchorLink->getType()); + assertSame('hello', $anchorLink->text); + assertSame('section1', $anchorLink->anchorName); + } + + public function testEmptyAnchorName(): void + { + $anchorLink = (new ObjectFactory())->create([ + 'type' => 'anchor_link', + 'text' => 'back to top', + 'anchor_name' => '', + ], null, RichTextAnchorLink::class); + + assertSame('', $anchorLink->anchorName); + } +} diff --git a/tests/Type/RichTextAnchorTest.php b/tests/Type/RichTextAnchorTest.php new file mode 100644 index 00000000..120bd834 --- /dev/null +++ b/tests/Type/RichTextAnchorTest.php @@ -0,0 +1,33 @@ +getType()); + assertSame('section1', $anchor->name); + } + + public function testFromTelegramResult(): void + { + $anchor = (new ObjectFactory())->create([ + 'type' => 'anchor', + 'name' => 'section1', + ], null, RichTextAnchor::class); + + assertSame('anchor', $anchor->getType()); + assertSame('section1', $anchor->name); + } +} diff --git a/tests/Type/RichTextBankCardNumberTest.php b/tests/Type/RichTextBankCardNumberTest.php new file mode 100644 index 00000000..b04483b7 --- /dev/null +++ b/tests/Type/RichTextBankCardNumberTest.php @@ -0,0 +1,36 @@ +getType()); + assertSame('hello', $bankCardNumber->text); + assertSame('4111111111111111', $bankCardNumber->bankCardNumber); + } + + public function testFromTelegramResult(): void + { + $bankCardNumber = (new ObjectFactory())->create([ + 'type' => 'bank_card_number', + 'text' => 'hello', + 'bank_card_number' => '4111111111111111', + ], null, RichTextBankCardNumber::class); + + assertSame('bank_card_number', $bankCardNumber->getType()); + assertSame('hello', $bankCardNumber->text); + assertSame('4111111111111111', $bankCardNumber->bankCardNumber); + } +} diff --git a/tests/Type/RichTextBoldTest.php b/tests/Type/RichTextBoldTest.php new file mode 100644 index 00000000..4456a276 --- /dev/null +++ b/tests/Type/RichTextBoldTest.php @@ -0,0 +1,33 @@ +getType()); + assertSame('hello', $bold->text); + } + + public function testFromTelegramResult(): void + { + $bold = (new ObjectFactory())->create([ + 'type' => 'bold', + 'text' => 'hello', + ], null, RichTextBold::class); + + assertSame('bold', $bold->getType()); + assertSame('hello', $bold->text); + } +} diff --git a/tests/Type/RichTextBotCommandTest.php b/tests/Type/RichTextBotCommandTest.php new file mode 100644 index 00000000..683703b3 --- /dev/null +++ b/tests/Type/RichTextBotCommandTest.php @@ -0,0 +1,36 @@ +getType()); + assertSame('hello', $botCommand->text); + assertSame('/start', $botCommand->botCommand); + } + + public function testFromTelegramResult(): void + { + $botCommand = (new ObjectFactory())->create([ + 'type' => 'bot_command', + 'text' => 'hello', + 'bot_command' => '/start', + ], null, RichTextBotCommand::class); + + assertSame('bot_command', $botCommand->getType()); + assertSame('hello', $botCommand->text); + assertSame('/start', $botCommand->botCommand); + } +} diff --git a/tests/Type/RichTextCashtagTest.php b/tests/Type/RichTextCashtagTest.php new file mode 100644 index 00000000..661e830d --- /dev/null +++ b/tests/Type/RichTextCashtagTest.php @@ -0,0 +1,36 @@ +getType()); + assertSame('hello', $cashtag->text); + assertSame('$AAPL', $cashtag->cashtag); + } + + public function testFromTelegramResult(): void + { + $cashtag = (new ObjectFactory())->create([ + 'type' => 'cashtag', + 'text' => 'hello', + 'cashtag' => '$AAPL', + ], null, RichTextCashtag::class); + + assertSame('cashtag', $cashtag->getType()); + assertSame('hello', $cashtag->text); + assertSame('$AAPL', $cashtag->cashtag); + } +} diff --git a/tests/Type/RichTextCodeTest.php b/tests/Type/RichTextCodeTest.php new file mode 100644 index 00000000..e75fe908 --- /dev/null +++ b/tests/Type/RichTextCodeTest.php @@ -0,0 +1,33 @@ +getType()); + assertSame('hello', $code->text); + } + + public function testFromTelegramResult(): void + { + $code = (new ObjectFactory())->create([ + 'type' => 'code', + 'text' => 'hello', + ], null, RichTextCode::class); + + assertSame('code', $code->getType()); + assertSame('hello', $code->text); + } +} diff --git a/tests/Type/RichTextCustomEmojiTest.php b/tests/Type/RichTextCustomEmojiTest.php new file mode 100644 index 00000000..6e9466b4 --- /dev/null +++ b/tests/Type/RichTextCustomEmojiTest.php @@ -0,0 +1,36 @@ +getType()); + assertSame('emoji123', $customEmoji->customEmojiId); + assertSame('😀', $customEmoji->alternativeText); + } + + public function testFromTelegramResult(): void + { + $customEmoji = (new ObjectFactory())->create([ + 'type' => 'custom_emoji', + 'custom_emoji_id' => 'emoji123', + 'alternative_text' => '😀', + ], null, RichTextCustomEmoji::class); + + assertSame('custom_emoji', $customEmoji->getType()); + assertSame('emoji123', $customEmoji->customEmojiId); + assertSame('😀', $customEmoji->alternativeText); + } +} diff --git a/tests/Type/RichTextDateTimeTest.php b/tests/Type/RichTextDateTimeTest.php new file mode 100644 index 00000000..f5f61747 --- /dev/null +++ b/tests/Type/RichTextDateTimeTest.php @@ -0,0 +1,39 @@ +getType()); + assertSame('hello', $dateTime->text); + assertSame(1749600000, $dateTime->unixTime); + assertSame('Y-m-d H:i:s', $dateTime->dateTimeFormat); + } + + public function testFromTelegramResult(): void + { + $dateTime = (new ObjectFactory())->create([ + 'type' => 'date_time', + 'text' => 'hello', + 'unix_time' => 1749600000, + 'date_time_format' => 'Y-m-d H:i:s', + ], null, RichTextDateTime::class); + + assertSame('date_time', $dateTime->getType()); + assertSame('hello', $dateTime->text); + assertSame(1749600000, $dateTime->unixTime); + assertSame('Y-m-d H:i:s', $dateTime->dateTimeFormat); + } +} diff --git a/tests/Type/RichTextEmailAddressTest.php b/tests/Type/RichTextEmailAddressTest.php new file mode 100644 index 00000000..a71dc3fb --- /dev/null +++ b/tests/Type/RichTextEmailAddressTest.php @@ -0,0 +1,36 @@ +getType()); + assertSame('hello', $emailAddress->text); + assertSame('test@example.com', $emailAddress->emailAddress); + } + + public function testFromTelegramResult(): void + { + $emailAddress = (new ObjectFactory())->create([ + 'type' => 'email_address', + 'text' => 'hello', + 'email_address' => 'test@example.com', + ], null, RichTextEmailAddress::class); + + assertSame('email_address', $emailAddress->getType()); + assertSame('hello', $emailAddress->text); + assertSame('test@example.com', $emailAddress->emailAddress); + } +} diff --git a/tests/Type/RichTextHashtagTest.php b/tests/Type/RichTextHashtagTest.php new file mode 100644 index 00000000..fbb174d5 --- /dev/null +++ b/tests/Type/RichTextHashtagTest.php @@ -0,0 +1,36 @@ +getType()); + assertSame('hello', $hashtag->text); + assertSame('#world', $hashtag->hashtag); + } + + public function testFromTelegramResult(): void + { + $hashtag = (new ObjectFactory())->create([ + 'type' => 'hashtag', + 'text' => 'hello', + 'hashtag' => '#world', + ], null, RichTextHashtag::class); + + assertSame('hashtag', $hashtag->getType()); + assertSame('hello', $hashtag->text); + assertSame('#world', $hashtag->hashtag); + } +} diff --git a/tests/Type/RichTextItalicTest.php b/tests/Type/RichTextItalicTest.php new file mode 100644 index 00000000..e6d0a4d3 --- /dev/null +++ b/tests/Type/RichTextItalicTest.php @@ -0,0 +1,33 @@ +getType()); + assertSame('hello', $italic->text); + } + + public function testFromTelegramResult(): void + { + $italic = (new ObjectFactory())->create([ + 'type' => 'italic', + 'text' => 'hello', + ], null, RichTextItalic::class); + + assertSame('italic', $italic->getType()); + assertSame('hello', $italic->text); + } +} diff --git a/tests/Type/RichTextMarkedTest.php b/tests/Type/RichTextMarkedTest.php new file mode 100644 index 00000000..20855669 --- /dev/null +++ b/tests/Type/RichTextMarkedTest.php @@ -0,0 +1,33 @@ +getType()); + assertSame('hello', $marked->text); + } + + public function testFromTelegramResult(): void + { + $marked = (new ObjectFactory())->create([ + 'type' => 'marked', + 'text' => 'hello', + ], null, RichTextMarked::class); + + assertSame('marked', $marked->getType()); + assertSame('hello', $marked->text); + } +} diff --git a/tests/Type/RichTextMathematicalExpressionTest.php b/tests/Type/RichTextMathematicalExpressionTest.php new file mode 100644 index 00000000..d451ef2c --- /dev/null +++ b/tests/Type/RichTextMathematicalExpressionTest.php @@ -0,0 +1,33 @@ +getType()); + assertSame('E = mc^2', $expression->expression); + } + + public function testFromTelegramResult(): void + { + $expression = (new ObjectFactory())->create([ + 'type' => 'mathematical_expression', + 'expression' => 'E = mc^2', + ], null, RichTextMathematicalExpression::class); + + assertSame('mathematical_expression', $expression->getType()); + assertSame('E = mc^2', $expression->expression); + } +} diff --git a/tests/Type/RichTextMentionTest.php b/tests/Type/RichTextMentionTest.php new file mode 100644 index 00000000..1f37853f --- /dev/null +++ b/tests/Type/RichTextMentionTest.php @@ -0,0 +1,36 @@ +getType()); + assertSame('hello', $mention->text); + assertSame('johndoe', $mention->username); + } + + public function testFromTelegramResult(): void + { + $mention = (new ObjectFactory())->create([ + 'type' => 'mention', + 'text' => 'hello', + 'username' => 'johndoe', + ], null, RichTextMention::class); + + assertSame('mention', $mention->getType()); + assertSame('hello', $mention->text); + assertSame('johndoe', $mention->username); + } +} diff --git a/tests/Type/RichTextPhoneNumberTest.php b/tests/Type/RichTextPhoneNumberTest.php new file mode 100644 index 00000000..68860ff2 --- /dev/null +++ b/tests/Type/RichTextPhoneNumberTest.php @@ -0,0 +1,36 @@ +getType()); + assertSame('hello', $phoneNumber->text); + assertSame('+1234567890', $phoneNumber->phoneNumber); + } + + public function testFromTelegramResult(): void + { + $phoneNumber = (new ObjectFactory())->create([ + 'type' => 'phone_number', + 'text' => 'hello', + 'phone_number' => '+1234567890', + ], null, RichTextPhoneNumber::class); + + assertSame('phone_number', $phoneNumber->getType()); + assertSame('hello', $phoneNumber->text); + assertSame('+1234567890', $phoneNumber->phoneNumber); + } +} diff --git a/tests/Type/RichTextReferenceLinkTest.php b/tests/Type/RichTextReferenceLinkTest.php new file mode 100644 index 00000000..1bc660d1 --- /dev/null +++ b/tests/Type/RichTextReferenceLinkTest.php @@ -0,0 +1,36 @@ +getType()); + assertSame('hello', $referenceLink->text); + assertSame('ref1', $referenceLink->referenceName); + } + + public function testFromTelegramResult(): void + { + $referenceLink = (new ObjectFactory())->create([ + 'type' => 'reference_link', + 'text' => 'hello', + 'reference_name' => 'ref1', + ], null, RichTextReferenceLink::class); + + assertSame('reference_link', $referenceLink->getType()); + assertSame('hello', $referenceLink->text); + assertSame('ref1', $referenceLink->referenceName); + } +} diff --git a/tests/Type/RichTextReferenceTest.php b/tests/Type/RichTextReferenceTest.php new file mode 100644 index 00000000..7000dbe1 --- /dev/null +++ b/tests/Type/RichTextReferenceTest.php @@ -0,0 +1,36 @@ +getType()); + assertSame('hello', $reference->text); + assertSame('ref1', $reference->name); + } + + public function testFromTelegramResult(): void + { + $reference = (new ObjectFactory())->create([ + 'type' => 'reference', + 'text' => 'hello', + 'name' => 'ref1', + ], null, RichTextReference::class); + + assertSame('reference', $reference->getType()); + assertSame('hello', $reference->text); + assertSame('ref1', $reference->name); + } +} diff --git a/tests/Type/RichTextSpoilerTest.php b/tests/Type/RichTextSpoilerTest.php new file mode 100644 index 00000000..045a1925 --- /dev/null +++ b/tests/Type/RichTextSpoilerTest.php @@ -0,0 +1,33 @@ +getType()); + assertSame('hello', $spoiler->text); + } + + public function testFromTelegramResult(): void + { + $spoiler = (new ObjectFactory())->create([ + 'type' => 'spoiler', + 'text' => 'hello', + ], null, RichTextSpoiler::class); + + assertSame('spoiler', $spoiler->getType()); + assertSame('hello', $spoiler->text); + } +} diff --git a/tests/Type/RichTextStrikethroughTest.php b/tests/Type/RichTextStrikethroughTest.php new file mode 100644 index 00000000..3858f2e7 --- /dev/null +++ b/tests/Type/RichTextStrikethroughTest.php @@ -0,0 +1,33 @@ +getType()); + assertSame('hello', $strikethrough->text); + } + + public function testFromTelegramResult(): void + { + $strikethrough = (new ObjectFactory())->create([ + 'type' => 'strikethrough', + 'text' => 'hello', + ], null, RichTextStrikethrough::class); + + assertSame('strikethrough', $strikethrough->getType()); + assertSame('hello', $strikethrough->text); + } +} diff --git a/tests/Type/RichTextSubscriptTest.php b/tests/Type/RichTextSubscriptTest.php new file mode 100644 index 00000000..2ae2cab3 --- /dev/null +++ b/tests/Type/RichTextSubscriptTest.php @@ -0,0 +1,33 @@ +getType()); + assertSame('hello', $subscript->text); + } + + public function testFromTelegramResult(): void + { + $subscript = (new ObjectFactory())->create([ + 'type' => 'subscript', + 'text' => 'hello', + ], null, RichTextSubscript::class); + + assertSame('subscript', $subscript->getType()); + assertSame('hello', $subscript->text); + } +} diff --git a/tests/Type/RichTextSuperscriptTest.php b/tests/Type/RichTextSuperscriptTest.php new file mode 100644 index 00000000..ffe2bf3e --- /dev/null +++ b/tests/Type/RichTextSuperscriptTest.php @@ -0,0 +1,33 @@ +getType()); + assertSame('hello', $superscript->text); + } + + public function testFromTelegramResult(): void + { + $superscript = (new ObjectFactory())->create([ + 'type' => 'superscript', + 'text' => 'hello', + ], null, RichTextSuperscript::class); + + assertSame('superscript', $superscript->getType()); + assertSame('hello', $superscript->text); + } +} diff --git a/tests/Type/RichTextTextMentionTest.php b/tests/Type/RichTextTextMentionTest.php new file mode 100644 index 00000000..c9e1c2aa --- /dev/null +++ b/tests/Type/RichTextTextMentionTest.php @@ -0,0 +1,39 @@ +getType()); + assertSame('hello', $textMention->text); + assertSame($user, $textMention->user); + } + + public function testFromTelegramResult(): void + { + $textMention = (new ObjectFactory())->create([ + 'type' => 'text_mention', + 'text' => 'hello', + 'user' => ['id' => 123, 'is_bot' => false, 'first_name' => 'John'], + ], null, RichTextTextMention::class); + + assertSame('text_mention', $textMention->getType()); + assertSame('hello', $textMention->text); + assertSame(123, $textMention->user->id); + assertSame('John', $textMention->user->firstName); + } +} diff --git a/tests/Type/RichTextUnderlineTest.php b/tests/Type/RichTextUnderlineTest.php new file mode 100644 index 00000000..0b42f3d7 --- /dev/null +++ b/tests/Type/RichTextUnderlineTest.php @@ -0,0 +1,33 @@ +getType()); + assertSame('hello', $underline->text); + } + + public function testFromTelegramResult(): void + { + $underline = (new ObjectFactory())->create([ + 'type' => 'underline', + 'text' => 'hello', + ], null, RichTextUnderline::class); + + assertSame('underline', $underline->getType()); + assertSame('hello', $underline->text); + } +} diff --git a/tests/Type/RichTextUrlTest.php b/tests/Type/RichTextUrlTest.php new file mode 100644 index 00000000..37fadd16 --- /dev/null +++ b/tests/Type/RichTextUrlTest.php @@ -0,0 +1,36 @@ +getType()); + assertSame('hello', $url->text); + assertSame('https://example.com', $url->url); + } + + public function testFromTelegramResult(): void + { + $url = (new ObjectFactory())->create([ + 'type' => 'url', + 'text' => 'hello', + 'url' => 'https://example.com', + ], null, RichTextUrl::class); + + assertSame('url', $url->getType()); + assertSame('hello', $url->text); + assertSame('https://example.com', $url->url); + } +} diff --git a/tests/Type/UserTest.php b/tests/Type/UserTest.php index 05a67ae7..791f7474 100644 --- a/tests/Type/UserTest.php +++ b/tests/Type/UserTest.php @@ -35,6 +35,7 @@ public function testBase(): void assertNull($user->hasTopicsEnabled); assertNull($user->allowsUsersToCreateTopics); assertNull($user->canManageBots); + assertNull($user->supportsJoinRequestQueries); } public function testToRequestArray(): void @@ -57,6 +58,7 @@ public function testToRequestArray(): void true, true, true, + true, ); assertSame( @@ -78,6 +80,7 @@ public function testToRequestArray(): void 'has_topics_enabled' => true, 'allows_users_to_create_topics' => true, 'can_manage_bots' => true, + 'supports_join_request_queries' => true, ], $user->toRequestArray(), ); @@ -103,6 +106,7 @@ public function testFromTelegramResult(): void 'has_topics_enabled' => true, 'allows_users_to_create_topics' => true, 'can_manage_bots' => true, + 'supports_join_request_queries' => true, ], null, User::class); assertInstanceOf(User::class, $user); @@ -123,5 +127,6 @@ public function testFromTelegramResult(): void assertSame(true, $user->hasTopicsEnabled); assertSame(true, $user->allowsUsersToCreateTopics); assertSame(true, $user->canManageBots); + assertSame(true, $user->supportsJoinRequestQueries); } }