Skip to content

Commit

Permalink
Merge pull request #2 from redjanym/develop
Browse files Browse the repository at this point in the history
Fix "contentAvailable"
  • Loading branch information
redjanym committed May 4, 2017
2 parents dcdf4ae + 62d514c commit 5203666
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 16 deletions.
15 changes: 15 additions & 0 deletions src/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Message implements \JsonSerializable
private $notification;
private $collapseKey;
private $priority;
private $contentAvailable;
private $data;
private $recipients = [];
private $recipientType;
Expand Down Expand Up @@ -62,6 +63,17 @@ public function setPriority($priority)
return $this;
}

public function getContentAvailable()
{
return $this->contentAvailable;
}

public function setContentAvailable($contentAvailable)
{
$this->contentAvailable = $contentAvailable;
return $this;
}

public function setData(array $data)
{
$this->data = $data;
Expand Down Expand Up @@ -159,6 +171,9 @@ public function jsonSerialize()
if ($this->priority) {
$jsonData['priority'] = $this->priority;
}
if ($this->contentAvailable) {
$jsonData['content_available'] = $this->contentAvailable;
}
if ($this->notification) {
$jsonData['notification'] = $this->notification;
}
Expand Down
10 changes: 0 additions & 10 deletions src/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class Notification extends Message
private $sound;
private $clickAction;
private $tag;
private $content_available;

public function __construct($title = '', $body = '')
{
Expand Down Expand Up @@ -78,12 +77,6 @@ public function setTag($tag)
return $this;
}

public function setContentAvailable($content_available)
{
$this->content_available = $content_available;
return $this;
}

public function jsonSerialize()
{
$jsonData = $this->getJsonData();
Expand All @@ -108,9 +101,6 @@ public function jsonSerialize()
if ($this->tag) {
$jsonData['tag'] = $this->tag;
}
if ($this->content_available) {
$jsonData['content_available'] = $this->content_available;
}
return $jsonData;
}
}
15 changes: 15 additions & 0 deletions tests/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,19 @@ public function testJsonEncodeWorksOnDeviceRecipients()
json_encode($message)
);
}

public function testJsonSerializeWithContentAvailable()
{
$body = '{"to":"deviceId","content_available":true,"notification":{"title":"test","body":"a nice testing notification"}}';

$notification = new Notification('test', 'a nice testing notification');
$message = new Message();
$message->setNotification($notification);
$message->setContentAvailable(true);
$message->addRecipient(new Device('deviceId'));
$this->assertSame(
$body,
json_encode($message)
);
}
}
6 changes: 0 additions & 6 deletions tests/NotificationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,4 @@ public function testJsonSerializeWithIcon()
$this->fixture->setIcon('name');
$this->assertEquals(array('title' => 'foo', 'body' =>'bar', 'icon' => 'name'), $this->fixture->jsonSerialize());
}

public function testJsonSerializeWithContentAvailable()
{
$this->fixture->setContentAvailable(true);
$this->assertEquals(array('title' => 'foo', 'body' =>'bar', 'content_available' => true), $this->fixture->jsonSerialize());
}
}

0 comments on commit 5203666

Please sign in to comment.