DeletedTest.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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_Feed
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2012 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/Feed/Writer/Deleted.php';
  23. /**
  24. * @category Zend
  25. * @package Zend_Exception
  26. * @subpackage UnitTests
  27. * @group Zend_Feed
  28. * @group Zend_Feed_Writer
  29. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. */
  32. class Zend_Feed_Writer_DeletedTest extends PHPUnit_Framework_TestCase
  33. {
  34. public function testSetsReference()
  35. {
  36. $entry = new Zend_Feed_Writer_Deleted;
  37. $entry->setReference('http://www.example.com/id');
  38. $this->assertEquals('http://www.example.com/id', $entry->getReference());
  39. }
  40. public function testSetReferenceThrowsExceptionOnInvalidParameter()
  41. {
  42. $entry = new Zend_Feed_Writer_Deleted;
  43. try {
  44. $entry->setReference('');
  45. $this->fail();
  46. } catch (Zend_Feed_Exception $e) {
  47. }
  48. }
  49. public function testGetReferenceReturnsNullIfNotSet()
  50. {
  51. $entry = new Zend_Feed_Writer_Deleted;
  52. $this->assertTrue(is_null($entry->getReference()));
  53. }
  54. public function testSetWhenDefaultsToCurrentTime()
  55. {
  56. $entry = new Zend_Feed_Writer_Deleted;
  57. $entry->setWhen();
  58. $dateNow = new Zend_Date;
  59. $this->assertTrue($dateNow->isLater($entry->getWhen()) || $dateNow->equals($entry->getWhen()));
  60. }
  61. public function testSetWhenUsesGivenUnixTimestamp()
  62. {
  63. $entry = new Zend_Feed_Writer_Deleted;
  64. $entry->setWhen(1234567890);
  65. $myDate = new Zend_Date('1234567890', Zend_Date::TIMESTAMP);
  66. $this->assertTrue($myDate->equals($entry->getWhen()));
  67. }
  68. /**
  69. * @group ZF-12070
  70. */
  71. public function testSetWhenUsesGivenUnixTimestampWhenItIsLessThanTenDigits()
  72. {
  73. $entry = new Zend_Feed_Writer_Deleted;
  74. $entry->setWhen(123456789);
  75. $myDate = new Zend_Date('123456789', Zend_Date::TIMESTAMP);
  76. $this->assertTrue($myDate->equals($entry->getWhen()));
  77. }
  78. public function testSetWhenUsesZendDateObject()
  79. {
  80. $entry = new Zend_Feed_Writer_Deleted;
  81. $entry->setWhen(new Zend_Date('1234567890', Zend_Date::TIMESTAMP));
  82. $myDate = new Zend_Date('1234567890', Zend_Date::TIMESTAMP);
  83. $this->assertTrue($myDate->equals($entry->getWhen()));
  84. }
  85. public function testSetWhenThrowsExceptionOnInvalidParameter()
  86. {
  87. $entry = new Zend_Feed_Writer_Deleted;
  88. try {
  89. $entry->setWhen('abc');
  90. $this->fail();
  91. } catch (Zend_Feed_Exception $e) {
  92. }
  93. }
  94. public function testGetWhenReturnsNullIfDateNotSet()
  95. {
  96. $entry = new Zend_Feed_Writer_Deleted;
  97. $this->assertTrue(is_null($entry->getWhen()));
  98. }
  99. public function testAddsByNameFromArray()
  100. {
  101. $entry = new Zend_Feed_Writer_Deleted;
  102. $entry->setBy(array('name'=>'Joe'));
  103. $this->assertEquals(array('name'=>'Joe'), $entry->getBy());
  104. }
  105. public function testAddsByEmailFromArray()
  106. {
  107. $entry = new Zend_Feed_Writer_Deleted;
  108. $entry->setBy(array('name'=>'Joe','email'=>'joe@example.com'));
  109. $this->assertEquals(array('name'=>'Joe', 'email' => 'joe@example.com'), $entry->getBy());
  110. }
  111. public function testAddsByUriFromArray()
  112. {
  113. $entry = new Zend_Feed_Writer_Deleted;
  114. $entry->setBy(array('name'=>'Joe','uri'=>'http://www.example.com'));
  115. $this->assertEquals(array('name'=>'Joe', 'uri' => 'http://www.example.com'), $entry->getBy());
  116. }
  117. public function testAddByThrowsExceptionOnInvalidNameFromArray()
  118. {
  119. $entry = new Zend_Feed_Writer_Deleted;
  120. try {
  121. $entry->setBy(array('name'=>''));
  122. $this->fail();
  123. } catch (Zend_Feed_Exception $e) {
  124. }
  125. }
  126. public function testAddByThrowsExceptionOnInvalidEmailFromArray()
  127. {
  128. $entry = new Zend_Feed_Writer_Deleted;
  129. try {
  130. $entry->setBy(array('name'=>'Joe','email'=>''));
  131. $this->fail();
  132. } catch (Zend_Feed_Exception $e) {
  133. }
  134. }
  135. public function testAddByThrowsExceptionOnInvalidUriFromArray()
  136. {
  137. $entry = new Zend_Feed_Writer_Deleted;
  138. try {
  139. $entry->setBy(array('name'=>'Joe','uri'=>'notauri'));
  140. $this->fail();
  141. } catch (Zend_Feed_Exception $e) {
  142. }
  143. }
  144. public function testAddByThrowsExceptionIfNameOmittedFromArray()
  145. {
  146. $entry = new Zend_Feed_Writer_Deleted;
  147. try {
  148. $entry->setBy(array('uri'=>'notauri'));
  149. $this->fail();
  150. } catch (Zend_Feed_Exception $e) {
  151. }
  152. }
  153. }