Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support chrome_button_text and chrome_button_url #70

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 145 additions & 17 deletions src/main/php/Gomoob/Pushwoosh/Model/Notification/Chrome.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,36 @@ class Chrome implements \JsonSerializable
*
* @var string
*/
private $image;

private $image;

/**
* Text of the first button
*
* @var string
*/
private $buttonTextOne;

/**
* Url of the first button
*
* @var
*/
private $buttonUrlOne;

/**
* Text of the second button
*
* @var string
*/
private $buttonTextTwo;

/**
* Url of the second button
*
* @var
*/
private $buttonUrlTwo;

/**
* Utility function used to create a new Chrome instance.
*
Expand All @@ -62,7 +90,7 @@ public function getGcmTtl()
{
return $this->gcmTtl;
}

/**
* Gets the full path URL to the icon, or the path to the file in resources of the extension.
*
Expand All @@ -72,7 +100,7 @@ public function getIcon()
{
return $this->icon;
}

/**
* Gets the header of the message.
*
Expand All @@ -91,24 +119,68 @@ public function getTitle()
public function getImage()
{
return $this->image;
}

}

/**
* Gets the text of the first button.
*
* @return string $text The text of the first button.
*/
public function getButtonTextOne()
{
return $this->buttonTextOne;
}

/**
* Gets the url of the first button.
*
* @return string $url The url of the first button.*
*/
public function getButtonUrlOne()
{
return $this->buttonUrlOne;
}

/**
* Gets the text of the second button.
*
* @return string $text The text of the second button.*
*/
public function getButtonTextTwo()
{
return $this->buttonTextTwo;
}

/**
* Gets the url of the second button.
*
* @return string $url The url of the second button.
*/
public function getButtonUrlTwo()
{
return $this->buttonUrlTwo;
}

/**
* {@inheritdoc}
*/
public function jsonSerialize()
{
$json = [];

isset($this->gcmTtl) ? $json['chrome_gcm_ttl'] = $this->gcmTtl : false;
isset($this->icon) ? $json['chrome_icon'] = $this->icon : false;
isset($this->title) ? $json['chrome_title'] = $this->title : false;
isset($this->image) ? $json['chrome_image'] = $this->image : false;

isset($this->buttonTextOne) ? $json['chrome_button_text1'] = $this->buttonTextOne : false;
isset($this->buttonUrlOne) ? $json['chrome_button_url1'] = $this->buttonUrlOne : false;
isset($this->buttonTextTwo) ? $json['chrome_button_text2'] = $this->buttonTextTwo : false;
isset($this->buttonUrlTwo) ? $json['chrome_button_url2'] = $this->buttonUrlTwo : false;

return $json;

}

/**
* Sets the time to live parameter - the maximum lifespan of a message in seconds.
*
Expand All @@ -119,10 +191,10 @@ public function jsonSerialize()
public function setGcmTtl($gcmTtl)
{
$this->gcmTtl = $gcmTtl;

return $this;
}

/**
* Sets the full path URL to the icon, or the path to the file in resources of the extension.
*
Expand All @@ -133,10 +205,10 @@ public function setGcmTtl($gcmTtl)
public function setIcon($icon)
{
$this->icon = $icon;

return $this;
}

/**
* Sets the header of the message.
*
Expand All @@ -147,7 +219,7 @@ public function setIcon($icon)
public function setTitle($title)
{
$this->title = $title;

return $this;
}

Expand All @@ -161,7 +233,63 @@ public function setTitle($title)
public function setImage($image)
{
$this->image = $image;

return $this;
}
}

/**
* Sets the text of the first button.
*
* @param string $text The text of the first button.
*
* @return \Gomoob\Pushwoosh\Model\Notification\Chrome this instance.
*/
public function setButtonTextOne($text)
{
$this->buttonTextOne = $text;

return $this;
}

/**
* Sets the url of the first button.
*
* @param string $url The url of the first button.
*
* @return \Gomoob\Pushwoosh\Model\Notification\Chrome this instance.
*/
public function setButtonUrlOne($url)
{
$this->buttonUrlOne = $url;

return $this;
}

/**
* Sets the text of the second button.
*
* @param string $text The text of the second button.
*
* @return \Gomoob\Pushwoosh\Model\Notification\Chrome this instance.
*/
public function setButtonTextTwo($text)
{
$this->buttonTextTwo = $text;

return $this;
}

/**
* Sets the url of the second button.
*
* @param string $url The url of the second button.
*
* @return \Gomoob\Pushwoosh\Model\Notification\Chrome this instance.
*/
public function setButtonUrlTwo($url)
{
$this->buttonUrlTwo = $url;

return $this;
}
}
54 changes: 51 additions & 3 deletions src/test/php/Gomoob/Pushwoosh/Model/Notification/ChromeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,48 @@ public function testGetSetImage()
$chrome = new Chrome();
$this->assertSame($chrome, $chrome->setImage('Image'));
$this->assertSame('Image', $chrome->getImage());
}

}

/**
* Test method for the <code>#getButtonTextOne()</code> and <code>#setButtonTextOne($text)</code> functions.
*/
public function testGetButtonTextOne()
{
$chrome = new Chrome();
$this->assertSame($chrome, $chrome->setButtonTextOne('ButtonTextOne'));
$this->assertSame('ButtonTextOne', $chrome->getButtonTextOne());
}

/**
* Test method for the <code>#getButtonUrlOne()</code> and <code>#setButtonUrlOne($url)</code> functions.
*/
public function testGetButtonUrlOne()
{
$chrome = new Chrome();
$this->assertSame($chrome, $chrome->setButtonUrlOne('ButtonUrlOne'));
$this->assertSame('ButtonUrlOne', $chrome->getButtonUrlOne());
}

/**
* Test method for the <code>#getButtonTextTwo()</code> and <code>#setButtonTextTwo($text)</code> functions.
*/
public function testGetButtonTextTwo()
{
$chrome = new Chrome();
$this->assertSame($chrome, $chrome->setButtonTextTwo('ButtonTextTwo'));
$this->assertSame('ButtonTextTwo', $chrome->getButtonTextTwo());
}

/**
* Test method for the <code>#getButtonUrlTwo()</code> and <code>#setButtonUrlTwo($url)</code> functions.
*/
public function testGetButtonUrlTwo()
{
$chrome = new Chrome();
$this->assertSame($chrome, $chrome->setButtonUrlTwo('ButtonUrlTwo'));
$this->assertSame('ButtonUrlTwo', $chrome->getButtonUrlTwo());
}

/**
* Test method for the <code>#jsonSerialize()</code> function.
*/
Expand All @@ -76,12 +116,20 @@ public function testJsonSerialize()
->setIcon('icon')
->setTitle('Title')
->setImage('Image')
->setButtonTextOne('ButtonTextOne')
->setButtonUrlOne('ButtonUrlOne')
->setButtonTextTwo('ButtonTextTwo')
->setButtonUrlTwo('ButtonUrlTwo')
->jsonSerialize();

$this->assertCount(4, $array);
$this->assertCount(8, $array);
$this->assertSame(3600, $array['chrome_gcm_ttl']);
$this->assertSame('icon', $array['chrome_icon']);
$this->assertSame('Title', $array['chrome_title']);
$this->assertSame('Image', $array['chrome_image']);
$this->assertSame('ButtonTextOne', $array['chrome_button_text1']);
$this->assertSame('ButtonUrlOne', $array['chrome_button_url1']);
$this->assertSame('ButtonTextTwo', $array['chrome_button_text2']);
$this->assertSame('ButtonUrlTwo', $array['chrome_button_url2']);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,10 @@ public function testJsonSerialize()
->setIcon('icon')
->setTitle('Title')
->setImage('Image')
->setButtonTextOne('ButtonTextOne')
->setButtonUrlOne('ButtonUrlOne')
->setButtonTextTwo('ButtonTextTwo')
->setButtonUrlTwo('ButtonUrlTwo')
)
->setIOS(
IOS::create()
Expand Down Expand Up @@ -590,7 +594,7 @@ public function testJsonSerialize()
->jsonSerialize();

// Test the generic properties
$this->assertCount(65, $array);
$this->assertCount(69, $array);
$this->assertSame('now', $array['send_date']);
$this->assertSame('America/New_York', $array['timezone']);
$this->assertTrue($array['ignore_user_timezone']);
Expand Down Expand Up @@ -668,6 +672,10 @@ public function testJsonSerialize()
$this->assertSame('icon', $array['chrome_icon']);
$this->assertSame('Title', $array['chrome_title']);
$this->assertSame('Image', $array['chrome_image']);
$this->assertSame('ButtonTextOne', $array['chrome_button_text1']);
$this->assertSame('ButtonUrlOne', $array['chrome_button_url1']);
$this->assertSame('ButtonTextTwo', $array['chrome_button_text2']);
$this->assertSame('ButtonUrlTwo', $array['chrome_button_url2']);

// Test IOS parameters
$this->assertSame(1, $array['apns_trim_content']);
Expand Down