diff --git a/src/main/php/Gomoob/Pushwoosh/Model/Notification/Huawei.php b/src/main/php/Gomoob/Pushwoosh/Model/Notification/Huawei.php new file mode 100644 index 0000000..1628a13 --- /dev/null +++ b/src/main/php/Gomoob/Pushwoosh/Model/Notification/Huawei.php @@ -0,0 +1,270 @@ +badges; + } + + public function getBanner() + { + return $this->banner; + } + + public function getCustomIcon() + { + return $this->customIcon; + } + + public function getGcmTtl() + { + return $this->gcmTtl; + } + + public function getHeader() + { + return $this->header; + } + + public function getIbc() + { + return $this->ibc; + } + + public function getIcon() + { + return $this->icon; + } + + public function getLed() + { + return $this->led; + } + + public function getPriority() + { + return $this->priority; + } + + public function getRootParams() + { + return $this->rootParams; + } + + public function getSound() + { + return $this->sound; + } + + public function isVibration() + { + return $this->vibration; + } + + public function jsonSerialize() + { + $json = []; + + if ($this->badges !== null) { + $json['huawei_android_badges'] = $this->badges; + } + + if ($this->banner !== null) { + $json['huawei_android_banner'] = $this->banner; + } + + if ($this->customIcon !== null) { + $json['huawei_android_custom_icon'] = $this->customIcon; + } + + if ($this->gcmTtl !== null) { + $json['huawei_android_gcm_ttl'] = $this->gcmTtl; + } + + if ($this->header !== null) { + $json['huawei_android_header'] = $this->header; + } + + if ($this->ibc !== null) { + $json['huawei_android_ibc'] = $this->ibc; + } + + if ($this->icon !== null) { + $json['huawei_android_icon'] = $this->icon; + } + + if ($this->led !== null) { + $json['huawei_android_led'] = $this->led; + } + + if ($this->priority !== null) { + $json['huawei_android_priority'] = $this->priority; + } + + if ($this->rootParams !== null) { + $json['huawei_android_root_params'] = $this->rootParams; + } + + if ($this->sound !== null) { + $json['huawei_android_sound'] = $this->sound; + } + + if ($this->vibration !== null) { + $json['huawei_android_vibration'] = $this->vibration ? 1 : 0; + } + + return $json; + } + + public function setBadges($badges) + { + $this->badges = $badges; + + return $this; + } + + public function setBanner($banner) + { + $this->banner = $banner; + + return $this; + } + + public function setCustomIcon($customIcon) + { + $this->customIcon = $customIcon; + + return $this; + } + + public function setGcmTtl($gcmTtl) + { + $this->gcmTtl = $gcmTtl; + + return $this; + } + + public function setHeader($header) + { + $this->header = $header; + + return $this; + } + + public function setIbc($ibc) + { + $this->ibc = $ibc; + + return $this; + } + + public function setIcon($icon) + { + $this->icon = $icon; + + return $this; + } + + public function setLed($led) + { + $this->led = $led; + + return $this; + } + + public function setPriority($priority) + { + $this->priority = $priority; + + return $this; + } + + public function setRootParams($rootParams) + { + $this->rootParams = $rootParams; + + return $this; + } + + public function setSound($sound) + { + $this->sound = $sound; + + return $this; + } + + public function setVibration($vibration) + { + $this->vibration = $vibration; + + return $this; + } +} diff --git a/src/main/php/Gomoob/Pushwoosh/Model/Notification/Notification.php b/src/main/php/Gomoob/Pushwoosh/Model/Notification/Notification.php index 152b6f7..753b68e 100644 --- a/src/main/php/Gomoob/Pushwoosh/Model/Notification/Notification.php +++ b/src/main/php/Gomoob/Pushwoosh/Model/Notification/Notification.php @@ -260,6 +260,11 @@ class Notification implements \JsonSerializable */ private $wP; + /** + * @var Huawei + */ + private $huawei; + /** * Utility function used to create a new notification. * @@ -647,6 +652,14 @@ public function getWP() { return $this->wP; } + + /** + * @return Huawei + */ + public function getHuawei() + { + return $this->huawei; + } /** * Creates a JSON representation of this request. @@ -707,7 +720,8 @@ public function jsonSerialize() $this->mac, $this->safari, $this->wNS, - $this->wP + $this->wP, + $this->huawei ); } @@ -1162,4 +1176,15 @@ public function setWP(WP $wP) return $this; } + + /** + * @param Huawei $huawei + * @return $this + */ + public function setHuawei(Huawei $huawei) + { + $this->huawei = $huawei; + + return $this; + } } diff --git a/src/main/php/Gomoob/Pushwoosh/Model/Notification/Platform.php b/src/main/php/Gomoob/Pushwoosh/Model/Notification/Platform.php index aed29b9..d6c6c11 100644 --- a/src/main/php/Gomoob/Pushwoosh/Model/Notification/Platform.php +++ b/src/main/php/Gomoob/Pushwoosh/Model/Notification/Platform.php @@ -60,6 +60,11 @@ class Platform */ const FIREFOX = 12; + /** + * @const string Huawei + */ + const HUAWEI = 17; + /** * The value of the platform, this can be equal to : * - 1 : iOS @@ -73,7 +78,7 @@ class Platform * - 10: Safari * - 11: Chrome * - 12: Firefox - * + * - 17: Huawei * @var int */ private $value; @@ -198,6 +203,11 @@ public static function firefox() return new Platform(self::FIREFOX); } + public static function huawei() + { + return new Platform(self::HUAWEI); + } + /** * Gets the value of the plateform, this can be equal to : * - 1 : iOS @@ -211,6 +221,7 @@ public static function firefox() * - 10: Safari * - 11: Chrome * - 12: Firefox + * - 17: Huawei * * @return int the value of the platform. */ diff --git a/src/test/php/Gomoob/Pushwoosh/Model/Notification/HuaweiTest.php b/src/test/php/Gomoob/Pushwoosh/Model/Notification/HuaweiTest.php new file mode 100644 index 0000000..dac94ef --- /dev/null +++ b/src/test/php/Gomoob/Pushwoosh/Model/Notification/HuaweiTest.php @@ -0,0 +1,129 @@ +assertNotNull(Huawei::create()); + } + + public function testGetSetBadges() + { + $huawei = new Huawei(); + $this->assertSame($huawei, $huawei->setBadges(5)); + $this->assertSame(5, $huawei->getBadges()); + } + + public function testGetSetBanner() + { + $huawei = new Huawei(); + $this->assertSame($huawei, $huawei->setBanner('http://example.com/banner.png')); + $this->assertSame('http://example.com/banner.png', $huawei->getBanner()); + } + + public function testGetSetCustomIcon() + { + $huawei = new Huawei(); + $this->assertSame($huawei, $huawei->setCustomIcon('http://example.com/image.png')); + $this->assertSame('http://example.com/image.png', $huawei->getCustomIcon()); + } + + public function testGetSetGcmTtl() + { + $huawei = new Huawei(); + $this->assertSame($huawei, $huawei->setGcmTtl(3600)); + $this->assertSame(3600, $huawei->getGcmTtl()); + } + + public function testGetSetHeader() + { + $huawei = new Huawei(); + $this->assertSame($huawei, $huawei->setHeader('Header')); + $this->assertSame('Header', $huawei->getHeader()); + } + + public function testGetSetIbc() + { + $huawei = new Huawei(); + $this->assertSame($huawei, $huawei->setIbc('#AA9966')); + $this->assertSame('#AA9966', $huawei->getIbc()); + } + + public function testGetSetIcon() + { + $huawei = new Huawei(); + $this->assertSame($huawei, $huawei->setIcon('icon')); + $this->assertSame('icon', $huawei->getIcon()); + } + + public function testGetSetLed() + { + $huawei = new Huawei(); + $this->assertSame($huawei, $huawei->setLed('#4455cc')); + $this->assertSame('#4455cc', $huawei->getLed()); + } + + public function testGetSetPriority() + { + $huawei = new Huawei(); + $this->assertSame($huawei, $huawei->setPriority(-1)); + $this->assertSame(-1, $huawei->getPriority()); + } + + public function testGetSetRootParams() + { + $huawei = new Huawei(); + $this->assertSame($huawei, $huawei->setRootParams(['key' => 'value'])); + $this->assertSame(['key' => 'value'], $huawei->getRootParams()); + } + + public function testGetSetSound() + { + $huawei = new Huawei(); + $this->assertSame($huawei, $huawei->setSound('push.mp3')); + $this->assertSame('push.mp3', $huawei->getSound()); + } + + public function testIsSetVibration() + { + $huawei = new Huawei(); + $this->assertSame($huawei, $huawei->setVibration(true)); + $this->assertTrue($huawei->isVibration()); + } + + public function testJsonSerialize() + { + $array = Huawei::create() + ->setBanner('http://example.com/banner.png') + ->setBadges(5) + ->setCustomIcon('http://example.com/image.png') + ->setGcmTtl(3600) + ->setHeader('Header') + ->setIbc('#AA9966') + ->setIcon('icon') + ->setLed('#4455cc') + ->setPriority(-1) + ->setRootParams(['key' => 'value']) + ->setSound('push.mp3') + ->setVibration(true) + ->jsonSerialize(); + + $this->assertCount(12, $array); + $this->assertSame('http://example.com/banner.png', $array['huawei_android_banner']); + $this->assertSame(5, $array['huawei_android_badges']); + $this->assertSame('http://example.com/image.png', $array['huawei_android_custom_icon']); + $this->assertSame(3600, $array['huawei_android_gcm_ttl']); + $this->assertSame('Header', $array['huawei_android_header']); + $this->assertSame('#AA9966', $array['huawei_android_ibc']); + $this->assertSame('icon', $array['huawei_android_icon']); + $this->assertSame('#4455cc', $array['huawei_android_led']); + $this->assertSame(-1, $array['huawei_android_priority']); + $this->assertSame(['key' => 'value'], $array['huawei_android_root_params']); + $this->assertSame('push.mp3', $array['huawei_android_sound']); + $this->assertSame(1, $array['huawei_android_vibration']); + } +} diff --git a/src/test/php/Gomoob/Pushwoosh/Model/Notification/NotificationTest.php b/src/test/php/Gomoob/Pushwoosh/Model/Notification/NotificationTest.php index 244e711..0e62d35 100644 --- a/src/test/php/Gomoob/Pushwoosh/Model/Notification/NotificationTest.php +++ b/src/test/php/Gomoob/Pushwoosh/Model/Notification/NotificationTest.php @@ -97,16 +97,18 @@ public function testGetSetPlatforms() $platform0 = Platform::amazon(); $platform1 = Platform::android(); $platform2 = Platform::blackBerry(); + $platform3 = Platform::huawei(); // Test for the 'addPlatform' method $notification = new Notification(); $this->assertNull($notification->getPlatforms()); - $this->assertSame($notification, $notification->setPlatforms([$platform0, $platform1, $platform2])); + $this->assertSame($notification, $notification->setPlatforms([$platform0, $platform1, $platform2, $platform3])); $platforms = $notification->getPlatforms(); - $this->assertCount(3, $platforms); + $this->assertCount(4, $platforms); $this->assertSame($platform0, $platforms[0]); $this->assertSame($platform1, $platforms[1]); $this->assertSame($platform2, $platforms[2]); + $this->assertSame($platform3, $platforms[3]); // Test for the 'setPlatforms' method $notification = new Notification(); @@ -114,11 +116,13 @@ public function testGetSetPlatforms() $this->assertSame($notification, $notification->addPlatform($platform0)); $this->assertSame($notification, $notification->addPlatform($platform1)); $this->assertSame($notification, $notification->addPlatform($platform2)); + $this->assertSame($notification, $notification->addPlatform($platform3)); $platforms = $notification->getPlatforms(); - $this->assertCount(3, $platforms); + $this->assertCount(4, $platforms); $this->assertSame($platform0, $platforms[0]); $this->assertSame($platform1, $platforms[1]); $this->assertSame($platform2, $platforms[2]); + $this->assertSame($platform3, $platforms[3]); } /** @@ -145,6 +149,15 @@ public function testGetSetAndroid() $this->assertSame($android, $notification->getAndroid()); } + public function testGetSetHuawei() + { + $notification = new Notification(); + $this->assertNull($notification->getAndroid()); + $huawei = new Huawei(); + $this->assertSame($notification, $notification->setHuawei($huawei)); + $this->assertSame($huawei, $notification->getHuawei()); + } + /** * Test method for the `getBlackBerry()` and `setBlackBerry($blackBerry)` functions. */ @@ -490,7 +503,8 @@ public function testJsonSerialize() Platform::windows8(), Platform::amazon(), Platform::safari(), - Platform::chrome() + Platform::chrome(), + Platform::huawei() ] ) ->setDevices( @@ -532,6 +546,21 @@ public function testJsonSerialize() ->setSound('push.mp3') ->setVibration(true) ) + ->setHuawei( + Huawei::create() + ->setBadges(5) + ->setBanner('http://example.com/banner.png') + ->setCustomIcon('http://example.com/image.png') + ->setGcmTtl(3600) + ->setHeader('Header') + ->setIbc('#AA9966') + ->setIcon('icon') + ->setLed('#4455cc') + ->setPriority(-1) + ->setRootParams(['key' => 'value']) + ->setSound('push.mp3') + ->setVibration(true) + ) ->setBlackBerry( BlackBerry::create() ->setHeader('header') @@ -590,7 +619,7 @@ public function testJsonSerialize() ->jsonSerialize(); // Test the generic properties - $this->assertCount(65, $array); + $this->assertCount(77, $array); $this->assertSame('now', $array['send_date']); $this->assertSame('America/New_York', $array['timezone']); $this->assertTrue($array['ignore_user_timezone']); @@ -607,7 +636,7 @@ public function testJsonSerialize() $this->assertSame(0, $array['minimize_link']); $this->assertCount(1, $array['data']); $this->assertSame('json data', $array['data']['custom']); - $this->assertCount(10, $array['platforms']); + $this->assertCount(11, $array['platforms']); $this->assertSame(1, $array['platforms'][0]); $this->assertSame(2, $array['platforms'][1]); $this->assertSame(3, $array['platforms'][2]); @@ -618,6 +647,7 @@ public function testJsonSerialize() $this->assertSame(9, $array['platforms'][7]); $this->assertSame(10, $array['platforms'][8]); $this->assertSame(11, $array['platforms'][9]); + $this->assertSame(17, $array['platforms'][10]); $this->assertCount(1, $array['devices']); $this->assertSame('dec301908b9ba8df85e57a58e40f96f523f4c2068674f5fe2ba25cdc250a2a41', $array['devices'][0]); $this->assertSame('FILTER_NAME', $array['filter']); @@ -660,6 +690,20 @@ public function testJsonSerialize() $this->assertSame('push.mp3', $array['android_sound']); $this->assertSame(1, $array['android_vibration']); + // Test Huawei parameters + $this->assertSame(5, $array['huawei_android_badges']); + $this->assertSame('http://example.com/banner.png', $array['huawei_android_banner']); + $this->assertSame('http://example.com/image.png', $array['huawei_android_custom_icon']); + $this->assertSame(3600, $array['huawei_android_gcm_ttl']); + $this->assertSame('Header', $array['huawei_android_header']); + $this->assertSame('#AA9966', $array['huawei_android_ibc']); + $this->assertSame('icon', $array['huawei_android_icon']); + $this->assertSame('#4455cc', $array['huawei_android_led']); + $this->assertSame(-1, $array['huawei_android_priority']); + $this->assertSame(['key' => 'value'], $array['huawei_android_root_params']); + $this->assertSame('push.mp3', $array['huawei_android_sound']); + $this->assertSame(1, $array['huawei_android_vibration']); + // Test BlackBerry parameters $this->assertSame('header', $array['blackberry_header']); diff --git a/src/test/php/Gomoob/Pushwoosh/Model/Notification/PlatformTest.php b/src/test/php/Gomoob/Pushwoosh/Model/Notification/PlatformTest.php index cfc64c7..0bc7825 100644 --- a/src/test/php/Gomoob/Pushwoosh/Model/Notification/PlatformTest.php +++ b/src/test/php/Gomoob/Pushwoosh/Model/Notification/PlatformTest.php @@ -105,4 +105,12 @@ public function testWindows8() { $this->assertSame(8, Platform::windows8()->getValue()); } + + /** + * Test method for the #android() function. + */ + public function testHuawei() + { + $this->assertSame(17, Platform::huawei()->getValue()); + } }