コード例 #1
0
 /**
  * Test method for the <tt>toJSON()</tt> function.
  */
 public function testToJSON()
 {
     $array = Notification::create()->setSendDate('now')->setIgnoreUserTimezone(true)->setContent(array('en' => 'English', 'ru' => 'Русский', 'de' => 'Deutsch'))->setPageId(39)->setLink('http://google.com')->setMinimizeLink(MinimizeLink::none())->setData(array('custom' => 'json data'))->setPlatforms(array(Platform::iOS(), Platform::blackBerry(), Platform::android(), Platform::nokia(), Platform::windowsPhone7(), Platform::maxOSX(), Platform::windows8(), Platform::amazon(), Platform::safari()))->setDevices(array('dec301908b9ba8df85e57a58e40f96f523f4c2068674f5fe2ba25cdc250a2a41'))->setFilter('FILTER_NAME')->setConditions(array(IntCondition::create('intTag')->gte(10), StringCondition::create('stringTag')->eq('stringValue'), ListCondition::create('listTag')->in(array('value0', 'value1', 'value2'))))->setADM(ADM::create()->setBanner('http://example.com/banner.png')->setCustomIcon('http://example.com/image.png')->setHeader('Header')->setIcon('icon')->setRootParams(array('key' => 'value'))->setSound('push.mp3')->setTtl(3600))->setAndroid(Android::create()->setBanner('http://example.com/banner.png')->setCustomIcon('http://example.com/image.png')->setGcmTtl(3600)->setHeader('Header')->setIcon('icon')->setRootParams(array('key' => 'value'))->setSound('push.mp3'))->setBlackBerry(BlackBerry::create()->setHeader('header'))->setIOS(IOS::create()->setApnsTrimContent(true)->setBadges(5)->setRootParams(array('aps' => array('content-available' => '1')))->setSound('sound file.wav')->setTtl(3600)->setTrimContent(true))->setMac(Mac::create()->setBadges(3)->setRootParams(array('content-available' => '1'))->setSound('sound.caf')->setTtl(3600))->setSafari(Safari::create()->setAction('Click here')->setTitle('Title')->setTtl(3600)->setUrlArgs(array('firstArgument', 'secondArgument')))->setWNS(WNS::create()->setContent(array('en' => 'ENENENEN', 'de' => 'DEDEDEDE'))->setTag('myTag')->setType('Badge'))->setWP(WP::create()->setBackbackground('/Resources/Green.jpg')->setBackcontent('back content')->setBackground('/Resources/Red.jpg')->setBacktitle('back title')->setCount(3)->setType('Tile'))->toJSON();
     // Test the generic properties
     $this->assertCount(49, $array);
     $this->assertEquals('now', $array['send_date']);
     $this->assertTrue($array['ignore_user_timezone']);
     $this->assertCount(3, $array['content']);
     $this->assertEquals('English', $array['content']['en']);
     $this->assertEquals('Русский', $array['content']['ru']);
     $this->assertEquals('Deutsch', $array['content']['de']);
     $this->assertEquals(39, $array['page_id']);
     $this->assertEquals('http://google.com', $array['link']);
     $this->assertEquals(0, $array['minimize_link']);
     $this->assertCount(1, $array['data']);
     $this->assertEquals('json data', $array['data']['custom']);
     $this->assertCount(9, $array['platforms']);
     $this->assertEquals(1, $array['platforms'][0]);
     $this->assertEquals(2, $array['platforms'][1]);
     $this->assertEquals(3, $array['platforms'][2]);
     $this->assertEquals(4, $array['platforms'][3]);
     $this->assertEquals(5, $array['platforms'][4]);
     $this->assertEquals(7, $array['platforms'][5]);
     $this->assertEquals(8, $array['platforms'][6]);
     $this->assertEquals(9, $array['platforms'][7]);
     $this->assertEquals(10, $array['platforms'][8]);
     $this->assertCount(1, $array['devices']);
     $this->assertEquals('dec301908b9ba8df85e57a58e40f96f523f4c2068674f5fe2ba25cdc250a2a41', $array['devices'][0]);
     $this->assertEquals('FILTER_NAME', $array['filter']);
     $this->assertCount(3, $array['conditions']);
     $this->assertEquals('intTag', $array['conditions'][0][0]);
     $this->assertEquals('GTE', $array['conditions'][0][1]);
     $this->assertEquals(10, $array['conditions'][0][2]);
     $this->assertEquals('stringTag', $array['conditions'][1][0]);
     $this->assertEquals('EQ', $array['conditions'][1][1]);
     $this->assertEquals('stringValue', $array['conditions'][1][2]);
     $this->assertEquals('listTag', $array['conditions'][2][0]);
     $this->assertEquals('IN', $array['conditions'][2][1]);
     $this->assertCount(3, $array['conditions'][2][2]);
     $this->assertEquals('value0', $array['conditions'][2][2][0]);
     $this->assertEquals('value1', $array['conditions'][2][2][1]);
     $this->assertEquals('value2', $array['conditions'][2][2][2]);
     // Test the ADM parameters
     $this->assertEquals('http://example.com/banner.png', $array['adm_banner']);
     $this->assertEquals('http://example.com/image.png', $array['adm_custom_icon']);
     $this->assertEquals('Header', $array['adm_header']);
     $this->assertEquals('icon', $array['adm_icon']);
     $this->assertEquals(array('key' => 'value'), $array['adm_root_params']);
     $this->assertEquals('push.mp3', $array['adm_sound']);
     $this->assertEquals(3600, $array['adm_ttl']);
     // Test Android parameters
     $this->assertEquals('http://example.com/banner.png', $array['android_banner']);
     $this->assertEquals('http://example.com/image.png', $array['android_custom_icon']);
     $this->assertEquals(3600, $array['android_gcm_ttl']);
     $this->assertEquals('Header', $array['android_header']);
     $this->assertEquals('icon', $array['android_icon']);
     $this->assertEquals(array('key' => 'value'), $array['android_root_params']);
     $this->assertEquals('push.mp3', $array['android_sound']);
     // Test BlackBerry parameters
     $this->assertEquals('header', $array['blackberry_header']);
     // Test IOS parameters
     $this->assertEquals(1, $array['apns_trim_content']);
     $this->assertEquals(5, $array['ios_badges']);
     $this->assertEquals(array('aps' => array('content-available' => '1')), $array['ios_root_params']);
     $this->assertEquals('sound file.wav', $array['ios_sound']);
     $this->assertEquals(3600, $array['ios_ttl']);
     $this->assertEquals(1, $array['ios_trim_content']);
     // Test Mac parameters
     $this->assertEquals(3, $array['mac_badges']);
     $this->assertEquals(array('content-available' => '1'), $array['mac_root_params']);
     $this->assertEquals('sound.caf', $array['mac_sound']);
     $this->assertEquals(3600, $array['mac_ttl']);
     // Test Safari parameters
     $this->assertEquals('Click here', $array['safari_action']);
     $this->assertEquals('Title', $array['safari_title']);
     $this->assertEquals(3600, $array['safari_ttl']);
     $this->assertEquals(array('firstArgument', 'secondArgument'), $array['safari_url_args']);
     // Test WNS parameters
     $this->assertEquals(array('en' => 'ENENENEN', 'de' => 'DEDEDEDE'), $array['wns_content']);
     $this->assertEquals('myTag', $array['wns_tag']);
     $this->assertEquals('Badge', $array['wns_type']);
     // Test WP parameters
     $this->assertEquals('/Resources/Green.jpg', $array['wp_backbackground']);
     $this->assertEquals('back content', $array['wp_backcontent']);
     $this->assertEquals('/Resources/Red.jpg', $array['wp_background']);
     $this->assertEquals('back title', $array['wp_backtitle']);
     $this->assertEquals(3, $array['wp_count']);
     $this->assertEquals('Tile', $array['wp_type']);
 }
コード例 #2
0
 /**
  * Setter for deviceType
  *
  * @param Platform $deviceType
  * @return self
  */
 public function setDeviceType(Platform $deviceType)
 {
     $this->deviceType = $deviceType->getValue();
     return $this;
 }