123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370 |
- <?php
- require __DIR__ .'/../vendor/autoload.php';
- use PHPUnit\Framework\TestCase;
- class RichMessageTest extends TestCase
- {
- /**
- * Result of initializing the TextMessage.
- */
- public function testInitializeText()
- {
- $testText = 'test rich text';
- try {
- $richText = new \CMText\RichContent\Messages\TextMessage($testText);
- }catch (\Exception $e){
- $richText = null;
- }
- $this->assertInstanceOf(
- \CMText\RichContent\Messages\TextMessage::class,
- $richText
- );
- $this->assertJson( json_encode($richText) );
- $json = $richText->jsonSerialize();
- $this->assertObjectHasAttribute(
- 'text',
- $json
- );
- }
- public function testInitializeCard()
- {
- $text = 'test rich card text';
- $header = 'test rich card header text';
- $name = 'test media name';
- $uri = 'test://uri';
- $mimetype = 'test/mimetype';
- $media = new \CMText\RichContent\Messages\MediaContent(
- $name,
- $uri,
- $mimetype
- );
- $richCard = new \CMText\RichContent\Messages\CardMessage(
- $text,
- $header,
- $media
- );
- $this->assertInstanceOf(
- \CMText\RichContent\Messages\MediaContent::class,
- $media
- );
- $this->assertInstanceOf(
- \CMText\RichContent\Messages\CardMessage::class,
- $richCard
- );
- $this->assertJson( json_encode($richCard) );
- $json = json_decode( json_encode($richCard) );
- $this->assertObjectHasAttribute(
- 'text',
- $json
- );
- $this->assertObjectHasAttribute(
- 'header',
- $json
- );
- $this->assertObjectHasAttribute(
- 'media',
- $json
- );
- $this->assertObjectHasAttribute(
- 'mediaName',
- $json->media
- );
- $this->assertObjectHasAttribute(
- 'mediaUri',
- $json->media
- );
- $this->assertObjectHasAttribute(
- 'mimeType',
- $json->media
- );
- }
- public function testInitializeCarousel()
- {
- $carousel = new \CMText\RichContent\Messages\CarouselMessage(
- \CMText\RichContent\Messages\CarouselCardWidth::MEDIUM,
- [
- new \CMText\RichContent\Messages\CardMessage(
- 'test rich text',
- 'test rich header text',
- new \CMText\RichContent\Messages\MediaContent(
- 'test name',
- 'test://uri',
- 'test/mimetype'
- )
- ),
- new \CMText\RichContent\Messages\CardMessage(
- 'test rich text',
- 'test rich header text',
- new \CMText\RichContent\Messages\MediaContent(
- 'test name',
- 'test://uri',
- 'test/mimetype'
- )
- ),
- ]
- );
- $this->assertInstanceOf(
- \CMText\RichContent\Messages\CarouselMessage::class,
- $carousel
- );
- $this->assertJson( json_encode($carousel) );
- $json = json_decode( json_encode($carousel) );
- $this->assertObjectHasAttribute(
- 'carousel',
- $json
- );
- $this->assertObjectHasAttribute(
- 'cardWidth',
- $json->carousel
- );
- $this->assertEquals(
- \CMText\RichContent\Messages\CarouselCardWidth::MEDIUM,
- $json->carousel->cardWidth
- );
- $this->assertObjectHasAttribute(
- 'cards',
- $json->carousel
- );
- $this->assertCount(
- 2,
- $json->carousel->cards
- );
- }
- public function testInitializeMedia()
- {
- $media = new \CMText\RichContent\Messages\MediaMessage(
- 'test name',
- 'test://uri',
- 'test/mimetype'
- );
- $this->assertInstanceOf(
- \CMText\RichContent\Messages\MediaMessage::class,
- $media
- );
- $this->assertJson( json_encode($media) );
- $json = json_decode( json_encode($media) );
- $this->assertObjectHasAttribute(
- 'media',
- $json
- );
- $this->assertObjectHasAttribute(
- 'mediaName',
- $json->media
- );
- $this->assertObjectHasAttribute(
- 'mediaUri',
- $json->media
- );
- $this->assertObjectHasAttribute(
- 'mimeType',
- $json->media
- );
- }
- public function testApplyMessageToRichContent()
- {
- try {
- $richContent = new \CMText\RichContent\RichContent();
- $richContent->AddConversationPart(
- new \CMText\RichContent\Messages\TextMessage('test rich text')
- );
- $this->assertInstanceOf(
- \CMText\RichContent\RichContent::class,
- $richContent
- );
- $this->assertJson( json_encode($richContent) );
- $json = json_decode( json_encode($richContent) );
- $this->assertCount(
- 1,
- $json->conversation
- );
- // add too many Conversation parts
- for($i = 0; $i < \CMText\RichContent\RichContent::CONVERSATION_LENGTH_LIMIT; ++$i){
- $richContent->AddConversationPart(
- new \CMText\RichContent\Messages\TextMessage('test rich text')
- );
- }
- }catch (\CMText\Exceptions\ConversationLimitException $conversationLengthException){
- $this->assertInstanceOf(
- \CMText\Exceptions\ConversationLimitException::class,
- $conversationLengthException
- );
- }
- }
- public function testInitializeLocationPush()
- {
- $dynamicLocation = new \CMText\RichContent\Common\ViewLocationDynamic(
- 'CM HQ',
- 'Konijnenberg 30, Breda'
- );
- $this->assertInstanceOf(
- \CMText\RichContent\Common\ViewLocationBase::class,
- $dynamicLocation
- );
- $location = new \CMText\RichContent\Messages\LocationPushMessage( $dynamicLocation );
- $this->assertJson( json_encode($location) );
- $json = json_decode( json_encode($location) );
- $this->assertObjectHasAttribute(
- 'location',
- $json
- );
- $this->assertObjectHasAttribute(
- 'label',
- $json->location
- );
- $this->assertObjectHasAttribute(
- 'searchQuery',
- $json->location
- );
- $this->assertObjectNotHasAttribute(
- 'radius',
- $json->location
- );
- $staticLocation = new CMText\RichContent\Common\ViewLocationStatic(
- 'CM HQ',
- '51.603802',
- '4.770821',
- 3
- );
- $this->assertInstanceOf(
- \CMText\RichContent\Common\ViewLocationBase::class,
- $staticLocation
- );
- $location = new CMText\RichContent\Messages\LocationPushMessage( $staticLocation );
- $this->assertJson( json_encode($location) );
- $json = json_decode( json_encode($location) );
- $this->assertObjectHasAttribute(
- 'location',
- $json
- );
- $this->assertObjectHasAttribute(
- 'latitude',
- $json->location
- );
- $this->assertObjectHasAttribute(
- 'longitude',
- $json->location
- );
- $this->assertObjectHasAttribute(
- 'label',
- $json->location
- );
- $this->assertObjectHasAttribute(
- 'radius',
- $json->location
- );
- }
- public function testInitializeContactsMessage()
- {
- // set up all the Contact properties
- $contactProperties['address'] = new \CMText\RichContent\Common\ContactAddress('Breda', 'Netherlands', 'NL');
- $contactProperties['birthday'] = new \CMText\RichContent\Common\ContactBirthday( new DateTime() );
- $contactProperties['email'] = new \CMText\RichContent\Common\ContactEmail('info@cm.com');
- $contactProperties['name'] = new \CMText\RichContent\Common\ContactName('CM.com Be part of it.');
- $contactProperties['organization'] = new \CMText\RichContent\Common\ContactOrganization('CM.com', 'Development');
- $contactProperties['phonenumber'] = new \CMText\RichContent\Common\ContactPhonenumber('+31765727000');
- $contactProperties['url'] = new \CMText\RichContent\Common\ContactUrl('https://cm.com');
- // test full initialization
- $contact = new \CMText\RichContent\Common\Contact(
- $contactProperties['address'],
- $contactProperties['birthday'],
- $contactProperties['email'],
- $contactProperties['name'],
- $contactProperties['organization'],
- $contactProperties['phonenumber'],
- $contactProperties['url']
- );
- $contactsMessage = new \CMText\RichContent\Messages\ContactsMessage($contact);
- $this->assertInstanceOf(
- \CMText\RichContent\Messages\ContactsMessage::class,
- $contactsMessage
- );
- $contactsMessage->addContact($contact);
- $this->assertJson( json_encode($contactsMessage) );
- $json = json_decode(json_encode($contactsMessage));
- $this->assertObjectHasAttribute(
- 'contacts',
- $json
- );
- $this->assertCount(
- 2,
- $json->contacts
- );
- $this->assertObjectHasAttribute(
- 'org',
- $json->contacts[0]
- );
- }
- }
|