TileTest.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Mobile
  17. * @subpackage Push
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id $
  21. */
  22. require_once 'Zend/Mobile/Push/Message/Mpns/Tile.php';
  23. /**
  24. * @category Zend
  25. * @package Zend_Mobile
  26. * @subpackage Push
  27. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  28. * @license http://framework.zend.com/license/new-bsd New BSD License
  29. * @group Zend_Mobile
  30. * @group Zend_Mobile_Push
  31. * @group Zend_Mobile_Push_Mpns
  32. */
  33. class Zend_Mobile_Push_Message_Mpns_TileTest extends PHPUnit_Framework_TestCase
  34. {
  35. private $_msg;
  36. public function setUp()
  37. {
  38. $this->_msg = new Zend_Mobile_Push_Message_Mpns_Tile();
  39. }
  40. public function testSetToken()
  41. {
  42. $token = 'http://sn1.notify.live.net/throttledthirdparty/bogusdata';
  43. $this->_msg->setToken($token);
  44. $this->assertEquals($token, $this->_msg->getToken());
  45. }
  46. /**
  47. * @expectedException Zend_Mobile_Push_Message_Exception
  48. */
  49. public function testSetTokenNonStringThrowsException()
  50. {
  51. $token = array('foo' => 'bar');
  52. $this->_msg->setToken($token);
  53. }
  54. /**
  55. * @expectedException Zend_Mobile_Push_Message_Exception
  56. */
  57. public function testSetTokenInvalidUrlThrowsException()
  58. {
  59. $token = 'notaurl';
  60. $this->_msg->setToken($token);
  61. }
  62. public function testGetNotificationType()
  63. {
  64. $this->assertEquals(Zend_Mobile_Push_Message_Mpns::TYPE_TILE, $this->_msg->getNotificationType());
  65. }
  66. public function testGetDelayHasDefaultOfImmediate()
  67. {
  68. $this->assertEquals(Zend_Mobile_Push_Message_Mpns_Tile::DELAY_IMMEDIATE, $this->_msg->getDelay());
  69. }
  70. public function testSetBackgroundImage()
  71. {
  72. $image = 'foo.bar';
  73. $this->_msg->setBackgroundImage($image);
  74. $this->assertEquals($image, $this->_msg->getBackgroundImage());
  75. }
  76. /**
  77. * @expectedException Zend_Mobile_Push_Message_Exception
  78. */
  79. public function testSetBackgroundImageThrowsExceptionOnNonString()
  80. {
  81. $image = array('foo' => 'bar');
  82. $this->_msg->setBackgroundImage($image);
  83. }
  84. public function testSetCount()
  85. {
  86. $negCount = -1;
  87. $posCount = 1;
  88. $this->_msg->setCount($negCount);
  89. $this->assertEquals($negCount, $this->_msg->getCount());
  90. $this->_msg->setCount($posCount);
  91. $this->assertEquals($posCount, $this->_msg->getCount());
  92. }
  93. /**
  94. * @expectedException Zend_Mobile_Push_Message_Exception
  95. */
  96. public function testSetCountThrowsExceptionOnNonNumeric()
  97. {
  98. $count = 'five';
  99. $this->_msg->setCount($count);
  100. }
  101. public function testSetTitle()
  102. {
  103. $title = 'foo';
  104. $this->_msg->setTitle($title);
  105. $this->assertEquals($title, $this->_msg->getTitle());
  106. }
  107. /**
  108. * @expectedException Zend_Mobile_Push_Message_Exception
  109. */
  110. public function testSetTitleThrowsExceptionOnNonString()
  111. {
  112. $title = array('foo' => 'bar');
  113. $this->_msg->setTitle($title);
  114. }
  115. public function testSetBackBackgroundImage()
  116. {
  117. $image = 'foo.bar';
  118. $this->_msg->setBackBackgroundImage($image);
  119. $this->assertEquals($image, $this->_msg->getBackBackgroundImage());
  120. }
  121. /**
  122. * @expectedException Zend_Mobile_Push_Message_Exception
  123. */
  124. public function testSetBackBackgroundImageThrowsExceptionOnNonString()
  125. {
  126. $image = array('foo' => 'bar');
  127. $this->_msg->setBackBackgroundImage($image);
  128. }
  129. public function testSetBackTitle()
  130. {
  131. $title = 'foo';
  132. $this->_msg->setBackTitle($title);
  133. $this->assertEquals($title, $this->_msg->getBackTitle());
  134. }
  135. /**
  136. * @expectedException Zend_Mobile_Push_Message_Exception
  137. */
  138. public function testSetBackTitleThrowsExceptionOnNonString()
  139. {
  140. $title = array('foo' => 'bar');
  141. $this->_msg->setBackTitle($title);
  142. }
  143. public function testSetBackContent()
  144. {
  145. $content = 'foo';
  146. $this->_msg->setBackContent($content);
  147. $this->assertEquals($content, $this->_msg->getBackContent());
  148. }
  149. /**
  150. * @expectedException Zend_Mobile_Push_Message_Exception
  151. */
  152. public function testSetBackContentThrowsExceptionOnNonString()
  153. {
  154. $content = array('foo' => 'bar');
  155. $this->_msg->setBackContent($content);
  156. $this->assertEquals($content, $this->_msg->getBackContent());
  157. }
  158. public function testSetTileId()
  159. {
  160. $id = '?foo.bar';
  161. $this->_msg->setTileId($id);
  162. $this->assertEquals($id, $this->_msg->getTileId());
  163. }
  164. /**
  165. * @expectedException Zend_Mobile_Push_Message_Exception
  166. */
  167. public function testSetTileIdThrowsExceptionOnNonString()
  168. {
  169. $id = array('foo' => 'bar');
  170. $this->_msg->setTileId($id);
  171. }
  172. public function testSetDelay()
  173. {
  174. $this->_msg->setDelay(Zend_Mobile_Push_Message_Mpns_Tile::DELAY_450S);
  175. $this->assertEquals(Zend_Mobile_Push_Message_Mpns_Tile::DELAY_450S, $this->_msg->getDelay());
  176. $this->_msg->setDelay(Zend_Mobile_Push_Message_Mpns_Tile::DELAY_900S);
  177. $this->assertEquals(Zend_Mobile_Push_Message_Mpns_Tile::DELAY_900S, $this->_msg->getDelay());
  178. $this->_msg->setDelay(Zend_Mobile_Push_Message_Mpns_Tile::DELAY_IMMEDIATE);
  179. $this->assertEquals(Zend_Mobile_Push_Message_Mpns_Tile::DELAY_IMMEDIATE, $this->_msg->getDelay());
  180. }
  181. public function testValidate()
  182. {
  183. $this->assertFalse($this->_msg->validate());
  184. $this->_msg->setToken('http://sn1.notify.live.net/throttledthirdparty/bogusdata');
  185. $this->assertFalse($this->_msg->validate());
  186. $this->_msg->setBackgroundImage('foo.bar');
  187. $this->assertFalse($this->_msg->validate());
  188. $this->_msg->setTitle('foo');
  189. $this->assertTrue($this->_msg->validate());
  190. }
  191. public function testGetXmlPayload()
  192. {
  193. $title = 'foo';
  194. $backgroundImage = 'bar.jpg';
  195. $count = 5;
  196. $this->_msg->setToken('http://sn1.notify.live.net/throttledthirdparty/abcdef1234567890');
  197. $this->_msg->setTitle($title);
  198. $this->_msg->setBackgroundImage($backgroundImage);
  199. $this->_msg->setCount($count);
  200. $xml = new SimpleXMLElement($this->_msg->getXmlPayload(), 0, false, 'wp', true);
  201. $this->assertEquals($title, (string) $xml->Tile->Title);
  202. $this->assertEquals($backgroundImage, (string) $xml->Tile->BackgroundImage);
  203. $this->assertEquals($count, (int) $xml->Tile->Count);
  204. }
  205. }