ToastTest.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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/Toast.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_ToastTest extends PHPUnit_Framework_TestCase
  34. {
  35. private $_msg;
  36. public function setUp()
  37. {
  38. $this->_msg = new Zend_Mobile_Push_Message_Mpns_Toast();
  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_TOAST, $this->_msg->getNotificationType());
  65. }
  66. public function testSetTitle()
  67. {
  68. $title = 'foo';
  69. $this->_msg->setTitle($title);
  70. $this->assertEquals($title, $this->_msg->getTitle());
  71. }
  72. /**
  73. * @expectedException Zend_Mobile_Push_Message_Exception
  74. */
  75. public function testSetTitleThrowsExceptionOnNonString()
  76. {
  77. $title = array('foo' => 'bar');
  78. $this->_msg->setTitle($title);
  79. }
  80. public function testSetMessage()
  81. {
  82. $msg = 'foo';
  83. $this->_msg->setMessage($msg);
  84. $this->assertEquals($msg, $this->_msg->getMessage());
  85. }
  86. /**
  87. * @expectedException Zend_Mobile_Push_Message_Exception
  88. */
  89. public function testSetMessageThrowsExceptionOnNonString()
  90. {
  91. $msg = array('foo' => 'bar');
  92. $this->_msg->setMessage($msg);
  93. }
  94. public function testSetParams()
  95. {
  96. $params = '?foo=bar';
  97. $this->_msg->setParams($params);
  98. $this->assertEquals($params, $this->_msg->getParams());
  99. }
  100. /**
  101. * @expectedException Zend_Mobile_Push_Message_Exception
  102. */
  103. public function testSetParamsThrowsExceptionOnNonString()
  104. {
  105. $params = array('foo' => 'bar');
  106. $this->_msg->setParams($params);
  107. }
  108. public function testGetDelayHasDefaultOfImmediate()
  109. {
  110. $this->assertEquals(Zend_Mobile_Push_Message_Mpns_Toast::DELAY_IMMEDIATE, $this->_msg->getDelay());
  111. }
  112. public function testSetDelay()
  113. {
  114. $this->_msg->setDelay(Zend_Mobile_Push_Message_Mpns_Toast::DELAY_450S);
  115. $this->assertEquals(Zend_Mobile_Push_Message_Mpns_Toast::DELAY_450S, $this->_msg->getDelay());
  116. $this->_msg->setDelay(Zend_Mobile_Push_Message_Mpns_Toast::DELAY_900S);
  117. $this->assertEquals(Zend_Mobile_Push_Message_Mpns_Toast::DELAY_900S, $this->_msg->getDelay());
  118. $this->_msg->setDelay(Zend_Mobile_Push_Message_Mpns_Toast::DELAY_IMMEDIATE);
  119. $this->assertEquals(Zend_Mobile_Push_Message_Mpns_Toast::DELAY_IMMEDIATE, $this->_msg->getDelay());
  120. }
  121. public function testValidate()
  122. {
  123. $this->assertFalse($this->_msg->validate());
  124. $this->_msg->setToken('http://sn1.notify.live.net/throttledthirdparty/bogusdata');
  125. $this->assertFalse($this->_msg->validate());
  126. $this->_msg->setTitle('foo');
  127. $this->assertFalse($this->_msg->validate());
  128. $this->_msg->setMessage('bar');
  129. $this->assertTrue($this->_msg->validate());
  130. }
  131. public function testGetXmlPayload()
  132. {
  133. $title = 'Foo';
  134. $message = 'Bar';
  135. $this->_msg->setToken('http://sn1.notify.live.net/throttledthirdparty/abcdef1234567890');
  136. $this->_msg->setTitle($title);
  137. $this->_msg->setMessage($message);
  138. $xml = new SimpleXMLElement($this->_msg->getXmlPayload(), 0, false, 'wp', true);
  139. $this->assertEquals($title, (string) $xml->Toast->Text1);
  140. $this->assertEquals($message, (string) $xml->Toast->Text2);
  141. }
  142. }