ElementTest.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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-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. /**
  23. * @see Zend_Feed_Entry_Atom
  24. */
  25. require_once 'Zend/Feed/Entry/Atom.php';
  26. /**
  27. * @category Zend
  28. * @package Zend_Feed
  29. * @subpackage UnitTests
  30. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. * @group Zend_Feed
  33. */
  34. class Zend_Feed_ElementTest extends PHPUnit_Framework_TestCase
  35. {
  36. public function testIsInitialized()
  37. {
  38. $e = new Zend_Feed_Entry_Atom();
  39. $e->author->name['last'] = 'hagenbuch';
  40. $e->author->name['first'] = 'chuck';
  41. $e->author->name->{'chuck:url'} = 'marina.horde.org';
  42. $e->author->title['foo'] = 'bar';
  43. if ($e->pants()) {
  44. $this->fail('<pants> does not exist, it should not have a true value');
  45. // This should not create an element in the actual tree.
  46. }
  47. if ($e->pants()) {
  48. $this->fail('<pants> should not have been created by testing for it');
  49. // This should not create an element in the actual tree.
  50. }
  51. $xml = $e->saveXml();
  52. $this->assertFalse(strpos($xml, 'pants'), '<pants> should not be in the xml output');
  53. $this->assertTrue(strpos($xml, 'marina.horde.org') !== false, 'the url attribute should be set');
  54. }
  55. public function testStrings()
  56. {
  57. $xml = "<entry>
  58. <title> Using C++ Intrinsic Functions for Pipelined Text Processing</title>
  59. <id>http://www.oreillynet.com/pub/wlg/8356</id>
  60. <link rel='alternate' href='http://www.oreillynet.com/pub/wlg/8356'/>
  61. <summary type='xhtml'>
  62. <div xmlns='http://www.w3.org/1999/xhtml'>
  63. A good C++ programming technique that has almost no published material available on the WWW relates to using the special pipeline instructions in modern CPUs for faster text processing. Here's example code using C++ intrinsic functions to give a fourfold speed increase for a UTF-8 to UTF-16 converter compared to the original C/C++ code.
  64. </div>
  65. </summary>
  66. <author><name>Rick Jelliffe</name></author>
  67. <updated>2005-11-07T08:15:57-08:00</updated>
  68. </entry>";
  69. $entry = new Zend_Feed_Entry_Atom('uri', $xml);
  70. $this->assertTrue($entry->summary instanceof Zend_Feed_Element, '__get access should return an Zend_Feed_Element instance');
  71. $this->assertFalse($entry->summary() instanceof Zend_Feed_Element, 'method access should not return an Zend_Feed_Element instance');
  72. $this->assertTrue(is_string($entry->summary()), 'method access should return a string');
  73. $this->assertFalse(is_string($entry->summary), '__get access should not return a string');
  74. }
  75. public function testSetNamespacedAttributes()
  76. {
  77. $value = 'value';
  78. $e = new Zend_Feed_Entry_Atom();
  79. $e->test['attr'] = $value;
  80. $e->test['namespace1:attr'] = $value;
  81. $e->test['namespace2:attr'] = $value;
  82. $this->assertEquals($value, $e->test['attr']);
  83. $this->assertEquals($value, $e->test['namespace1:attr']);
  84. $this->assertEquals($value, $e->test['namespace2:attr']);
  85. }
  86. public function testUnsetNamespacedAttributes()
  87. {
  88. $value = 'value';
  89. $e = new Zend_Feed_Entry_Atom();
  90. $e->test['attr'] = $value;
  91. $e->test['namespace1:attr'] = $value;
  92. $e->test['namespace2:attr'] = $value;
  93. $this->assertEquals($value, $e->test['attr']);
  94. $this->assertEquals($value, $e->test['namespace1:attr']);
  95. $this->assertEquals($value, $e->test['namespace2:attr']);
  96. unset($e->test['attr']);
  97. unset($e->test['namespace1:attr']);
  98. unset($e->test['namespace2:attr']);
  99. $this->assertEquals('', $e->test['attr']);
  100. $this->assertEquals('', $e->test['namespace1:attr']);
  101. $this->assertEquals('', $e->test['namespace1:attr']);
  102. }
  103. /**
  104. * @group ZF-2606
  105. */
  106. public function testValuesWithXmlSpecialChars()
  107. {
  108. $testAmp = '&';
  109. $testLt = '<';
  110. $testGt = '>';
  111. $e = new Zend_Feed_Entry_Atom();
  112. $e->testAmp = $testAmp;
  113. $e->{'namespace1:lt'} = $testLt;
  114. $e->{'namespace1:gt'} = $testGt;
  115. $this->assertEquals($testAmp, $e->testAmp());
  116. $this->assertEquals($testLt, $e->{'namespace1:lt'}());
  117. $this->assertEquals($testGt, $e->{'namespace1:gt'}());
  118. }
  119. /**
  120. * @group ZF-2606
  121. */
  122. public function testAttributesWithXmlSpecialChars()
  123. {
  124. $testAmp = '&';
  125. $testLt = '<';
  126. $testGt = '>';
  127. $testQuot = '"';
  128. $testSquot = "'";
  129. $e = new Zend_Feed_Entry_Atom();
  130. $e->test['amp'] = $testAmp;
  131. $e->test['namespace1:lt'] = $testLt;
  132. $e->test['namespace1:gt'] = $testGt;
  133. $e->test['namespace1:quot'] = $testQuot;
  134. $e->test['namespace1:squot'] = $testSquot;
  135. $this->assertEquals($testAmp, $e->test['amp']);
  136. $this->assertEquals($testLt, $e->test['namespace1:lt']);
  137. $this->assertEquals($testGt, $e->test['namespace1:gt']);
  138. $this->assertEquals($testQuot, $e->test['namespace1:quot']);
  139. $this->assertEquals($testSquot, $e->test['namespace1:squot']);
  140. }
  141. }