ElementTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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-2009 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-2009 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. }