Skip to content

Commit

Permalink
Merge pull request #177 from sykmhmh/master
Browse files Browse the repository at this point in the history
 Changed LocationMessage for message without title or address key
  • Loading branch information
Vaduz authored Oct 25, 2018
2 parents f8ab3a8 + 40dcadd commit 3541bd4
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 20 deletions.
8 changes: 4 additions & 4 deletions src/LINEBot/Event/MessageEvent/LocationMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,21 @@ public function __construct($event)
/**
* Returns title of the location message.
*
* @return string
* @return string|null
*/
public function getTitle()
{
return $this->message['title'];
return array_key_exists('title', $this->message) ? $this->message['title'] : null;
}

/**
* Returns address of the location message.
*
* @return string
* @return string|null
*/
public function getAddress()
{
return $this->message['address'];
return array_key_exists('address', $this->message) ? $this->message['address'] : null;
}

/**
Expand Down
90 changes: 74 additions & 16 deletions tests/LINEBot/EventRequestParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,38 @@ class EventRequestParserTest extends TestCase
"longitude":134.23
}
},
{
"type":"message",
"timestamp":12345678901234,
"source":{
"type":"user",
"userId":"userid"
},
"replyToken":"replytoken",
"message":{
"id":"contentid",
"type":"location",
"address":"tokyo",
"latitude":-34.12,
"longitude":134.23
}
},
{
"type":"message",
"timestamp":12345678901234,
"source":{
"type":"user",
"userId":"userid"
},
"replyToken":"replytoken",
"message":{
"id":"contentid",
"type":"location",
"title":"label",
"latitude":-34.12,
"longitude":134.23
}
},
{
"type":"message",
"timestamp":12345678901234,
Expand Down Expand Up @@ -298,9 +330,9 @@ public function testParseEventRequest()
{
$bot = new LINEBot(new DummyHttpClient($this, function () {
}), ['channelSecret' => 'testsecret']);
$events = $bot->parseEventRequest($this::$json, 'a4mKmptGCa6Kx/5PU6Ug3zC2SyLzzf9whz9/FbaR4HQ=');
$events = $bot->parseEventRequest($this::$json, 'GQivZqf1zAwZFxrU7Nxc25D1aE8X0P5QGsA/bOhztdM=');

$this->assertEquals(count($events), 20);
$this->assertEquals(count($events), 22);

{
// text
Expand Down Expand Up @@ -384,8 +416,34 @@ public function testParseEventRequest()
}

{
// sticker
// location when not set title attribute
$event = $events[6];
$this->assertInstanceOf('LINE\LINEBot\Event\MessageEvent\LocationMessage', $event);
/** @var LocationMessage $event */
$this->assertEquals('replytoken', $event->getReplyToken());
$this->assertEquals('location', $event->getMessageType());
$this->assertNull($event->getTitle());
$this->assertEquals('tokyo', $event->getAddress());
$this->assertEquals('-34.12', $event->getLatitude());
$this->assertEquals('134.23', $event->getLongitude());
}

{
// location when not set address attribute
$event = $events[7];
$this->assertInstanceOf('LINE\LINEBot\Event\MessageEvent\LocationMessage', $event);
/** @var LocationMessage $event */
$this->assertEquals('replytoken', $event->getReplyToken());
$this->assertEquals('location', $event->getMessageType());
$this->assertEquals('label', $event->getTitle());
$this->assertNull($event->getAddress());
$this->assertEquals('-34.12', $event->getLatitude());
$this->assertEquals('134.23', $event->getLongitude());
}

{
// sticker
$event = $events[8];
$this->assertInstanceOf('LINE\LINEBot\Event\MessageEvent\StickerMessage', $event);
/** @var StickerMessage $event */
$this->assertEquals('replytoken', $event->getReplyToken());
Expand All @@ -396,39 +454,39 @@ public function testParseEventRequest()

{
// follow
$event = $events[7];
$event = $events[9];
$this->assertInstanceOf('LINE\LINEBot\Event\FollowEvent', $event);
/** @var FollowEvent $event */
$this->assertEquals('replytoken', $event->getReplyToken());
}

{
// unfollow
$event = $events[8];
$event = $events[10];
$this->assertInstanceOf('LINE\LINEBot\Event\UnfollowEvent', $event);
/** @var UnfollowEvent $event */
$this->assertTrue($event->getReplyToken() === null);
}

{
// join
$event = $events[9];
$event = $events[11];
$this->assertInstanceOf('LINE\LINEBot\Event\JoinEvent', $event);
/** @var JoinEvent $event */
$this->assertEquals('replytoken', $event->getReplyToken());
}

{
// leave
$event = $events[10];
$event = $events[12];
$this->assertInstanceOf('LINE\LINEBot\Event\LeaveEvent', $event);
/** @var LeaveEvent $event */
$this->assertTrue($event->getReplyToken() === null);
}

{
// postback
$event = $events[11];
$event = $events[13];
$this->assertInstanceOf('LINE\LINEBot\Event\PostbackEvent', $event);
/** @var PostbackEvent $event */
$this->assertEquals('replytoken', $event->getReplyToken());
Expand All @@ -438,7 +496,7 @@ public function testParseEventRequest()

{
// beacon
$event = $events[12];
$event = $events[14];
$this->assertInstanceOf('LINE\LINEBot\Event\BeaconDetectionEvent', $event);
/** @var BeaconDetectionEvent $event */
$this->assertEquals('replytoken', $event->getReplyToken());
Expand All @@ -449,7 +507,7 @@ public function testParseEventRequest()

{
// unknown event (event source: user)
$event = $events[13];
$event = $events[15];
$this->assertInstanceOf('LINE\LINEBot\Event\UnknownEvent', $event);
/** @var UnknownEvent $event */
$this->assertEquals('__unknown__', $event->getType());
Expand All @@ -463,7 +521,7 @@ public function testParseEventRequest()

{
// unknown event (event source: unknown)
$event = $events[14];
$event = $events[16];
$this->assertInstanceOf('LINE\LINEBot\Event\UnknownEvent', $event);
/** @var UnknownEvent $event */
$this->assertEquals('__unknown__', $event->getType());
Expand All @@ -476,7 +534,7 @@ public function testParseEventRequest()

{
// message event & unknown message event
$event = $events[15];
$event = $events[17];
$this->assertInstanceOf('LINE\LINEBot\Event\MessageEvent', $event);
$this->assertInstanceOf('LINE\LINEBot\Event\MessageEvent\UnknownMessage', $event);
/** @var UnknownMessage $event */
Expand All @@ -485,7 +543,7 @@ public function testParseEventRequest()

{
// file message
$event = $events[16];
$event = $events[18];
$this->assertInstanceOf('LINE\LINEBot\Event\MessageEvent', $event);
$this->assertInstanceOf('LINE\LINEBot\Event\MessageEvent\FileMessage', $event);
/** @var FileMessage $event */
Expand All @@ -497,7 +555,7 @@ public function testParseEventRequest()

{
// postback date
$event = $events[17];
$event = $events[19];
$this->assertInstanceOf('LINE\LINEBot\Event\PostbackEvent', $event);
/** @var PostbackEvent $event */
$this->assertEquals('replytoken', $event->getReplyToken());
Expand All @@ -507,7 +565,7 @@ public function testParseEventRequest()

{
// postback time
$event = $events[18];
$event = $events[20];
$this->assertInstanceOf('LINE\LINEBot\Event\PostbackEvent', $event);
/** @var PostbackEvent $event */
$this->assertEquals('replytoken', $event->getReplyToken());
Expand All @@ -517,7 +575,7 @@ public function testParseEventRequest()

{
// postback datetime
$event = $events[19];
$event = $events[21];
$this->assertInstanceOf('LINE\LINEBot\Event\PostbackEvent', $event);
/** @var PostbackEvent $event */
$this->assertEquals('replytoken', $event->getReplyToken());
Expand Down

0 comments on commit 3541bd4

Please sign in to comment.