@@ -509,7 +509,7 @@ class EventRequestParserTest extends TestCase
509509 ]
510510 }
511511 }
512- },
512+ },
513513 {
514514 "type":"message",
515515 "mode":"active",
@@ -549,6 +549,68 @@ class EventRequestParserTest extends TestCase
549549 "trackingId": "track_id"
550550 },
551551 "replyToken":"replytoken"
552+ },
553+ {
554+ "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA",
555+ "type": "message",
556+ "mode": "active",
557+ "timestamp": 1462629479859,
558+ "source": {
559+ "type": "user",
560+ "userId": "U4af4980629..."
561+ },
562+ "message": {
563+ "id": "325708",
564+ "type": "text",
565+ "text": "@example Hello, world! (love)",
566+ "mention": {
567+ "mentionees": [
568+ {
569+ "index": 0,
570+ "length": 8,
571+ "userId": "U0123456789abcd0123456789abcdef"
572+ }
573+ ]
574+ }
575+ }
576+ },
577+ {
578+ "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA",
579+ "type": "message",
580+ "mode": "active",
581+ "timestamp": 1462629479859,
582+ "source": {
583+ "type": "user",
584+ "userId": "U0123456789abcd0123456789abcdef"
585+ },
586+ "message": {
587+ "id": "325708",
588+ "type": "text",
589+ "text": "@example message without mentionee userId",
590+ "mention": {
591+ "mentionees": [
592+ {
593+ "index": 0,
594+ "length": 8
595+ }
596+ ]
597+ }
598+ }
599+ },
600+ {
601+ "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA",
602+ "type": "message",
603+ "mode": "active",
604+ "timestamp": 1462629479859,
605+ "source": {
606+ "type": "user",
607+ "userId": "U0123456789abcd0123456789abcdef"
608+ },
609+ "message": {
610+ "id": "325708",
611+ "type": "text",
612+ "text": "message without mention"
613+ }
552614 }
553615 ]
554616}
@@ -565,13 +627,13 @@ public function testParseEventRequest()
565627 }), ['channelSecret ' => 'testsecret ' ]);
566628 list ($ destination , $ events ) = $ bot ->parseEventRequest (
567629 $ this ::$ json ,
568- '72gRU3rSwbF9yWd6+dqOK7IwIbDE+/TLu56PKoysdHE = ' ,
630+ 'Q4tp1jGo39vhlcbd4QiQ/9I+zoJDwGIkPP22wgoOjDI = ' ,
569631 false
570632 );
571633
572634 $ this ->assertEquals ($ destination , 'U0123456789abcdef0123456789abcd ' );
573635
574- $ this ->assertEquals (count ($ events ), 32 );
636+ $ this ->assertEquals (count ($ events ), 35 );
575637
576638 {
577639 // text
@@ -987,5 +1049,65 @@ public function testParseEventRequest()
9871049 /** @var UnsendMessage $event */
9881050 $ this ->assertEquals ('track_id ' , $ event ->getTrackingId ());
9891051 }
1052+
1053+ {
1054+ // text
1055+ $ event = $ events [32 ];
1056+ $ this ->assertEquals (1462629479859 , $ event ->getTimestamp ());
1057+ $ this ->assertEquals ('active ' , $ event ->getMode ());
1058+ $ this ->assertTrue ($ event ->isUserEvent ());
1059+ $ this ->assertEquals ('U4af4980629... ' , $ event ->getUserId ());
1060+ $ this ->assertEquals ('U4af4980629... ' , $ event ->getEventSourceId ());
1061+ $ this ->assertInstanceOf ('LINE\LINEBot\Event\MessageEvent ' , $ event );
1062+ $ this ->assertInstanceOf ('LINE\LINEBot\Event\MessageEvent\TextMessage ' , $ event );
1063+ /** @var TextMessage $event */
1064+ $ this ->assertEquals ('nHuyWiB7yP5Zw52FIkcQobQuGDXCTA ' , $ event ->getReplyToken ());
1065+ $ this ->assertEquals ('325708 ' , $ event ->getMessageId ());
1066+ $ this ->assertEquals ('text ' , $ event ->getMessageType ());
1067+ $ this ->assertEquals ('@example Hello, world! (love) ' , $ event ->getText ());
1068+ $ mentioneeInfo = $ event ->getMentionees ()[0 ];
1069+ $ this ->assertEquals (0 , $ mentioneeInfo ->getIndex ());
1070+ $ this ->assertEquals (8 , $ mentioneeInfo ->getLength ());
1071+ $ this ->assertEquals ('U0123456789abcd0123456789abcdef ' , $ mentioneeInfo ->getUserId ());
1072+ }
1073+
1074+ {
1075+ // text without mentionee userId
1076+ $ event = $ events [33 ];
1077+ $ this ->assertEquals (1462629479859 , $ event ->getTimestamp ());
1078+ $ this ->assertEquals ('active ' , $ event ->getMode ());
1079+ $ this ->assertTrue ($ event ->isUserEvent ());
1080+ $ this ->assertEquals ('U0123456789abcd0123456789abcdef ' , $ event ->getUserId ());
1081+ $ this ->assertEquals ('U0123456789abcd0123456789abcdef ' , $ event ->getEventSourceId ());
1082+ $ this ->assertInstanceOf ('LINE\LINEBot\Event\MessageEvent ' , $ event );
1083+ $ this ->assertInstanceOf ('LINE\LINEBot\Event\MessageEvent\TextMessage ' , $ event );
1084+ /** @var TextMessage $event */
1085+ $ this ->assertEquals ('nHuyWiB7yP5Zw52FIkcQobQuGDXCTA ' , $ event ->getReplyToken ());
1086+ $ this ->assertEquals ('325708 ' , $ event ->getMessageId ());
1087+ $ this ->assertEquals ('text ' , $ event ->getMessageType ());
1088+ $ this ->assertEquals ('@example message without mentionee userId ' , $ event ->getText ());
1089+ $ mentioneeInfo = $ event ->getMentionees ()[0 ];
1090+ $ this ->assertEquals (0 , $ mentioneeInfo ->getIndex ());
1091+ $ this ->assertEquals (8 , $ mentioneeInfo ->getLength ());
1092+ $ this ->assertEquals (null , $ mentioneeInfo ->getUserId ());
1093+ }
1094+
1095+ {
1096+ // text without mention
1097+ $ event = $ events [34 ];
1098+ $ this ->assertEquals (1462629479859 , $ event ->getTimestamp ());
1099+ $ this ->assertEquals ('active ' , $ event ->getMode ());
1100+ $ this ->assertTrue ($ event ->isUserEvent ());
1101+ $ this ->assertEquals ('U0123456789abcd0123456789abcdef ' , $ event ->getUserId ());
1102+ $ this ->assertEquals ('U0123456789abcd0123456789abcdef ' , $ event ->getEventSourceId ());
1103+ $ this ->assertInstanceOf ('LINE\LINEBot\Event\MessageEvent ' , $ event );
1104+ $ this ->assertInstanceOf ('LINE\LINEBot\Event\MessageEvent\TextMessage ' , $ event );
1105+ /** @var TextMessage $event */
1106+ $ this ->assertEquals ('nHuyWiB7yP5Zw52FIkcQobQuGDXCTA ' , $ event ->getReplyToken ());
1107+ $ this ->assertEquals ('325708 ' , $ event ->getMessageId ());
1108+ $ this ->assertEquals ('text ' , $ event ->getMessageType ());
1109+ $ this ->assertEquals ('message without mention ' , $ event ->getText ());
1110+ $ this ->assertEquals (null , $ event ->getMentionees ());
1111+ }
9901112 }
9911113}
0 commit comments