ElementTest.php 5.9 KB

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