ElementTest.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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-2008 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-2008 Zend Technologies USA Inc. (http://www.zend.com)
  35. * @license http://framework.zend.com/license/new-bsd New BSD License
  36. */
  37. class Zend_Feed_ElementTest extends PHPUnit_Framework_TestCase
  38. {
  39. public function testIsInitialized()
  40. {
  41. $e = new Zend_Feed_Entry_Atom();
  42. $e->author->name['last'] = 'hagenbuch';
  43. $e->author->name['first'] = 'chuck';
  44. $e->author->name->{'chuck:url'} = 'marina.horde.org';
  45. $e->author->title['foo'] = 'bar';
  46. if ($e->pants()) {
  47. $this->fail('<pants> does not exist, it should not have a true value');
  48. // This should not create an element in the actual tree.
  49. }
  50. if ($e->pants()) {
  51. $this->fail('<pants> should not have been created by testing for it');
  52. // This should not create an element in the actual tree.
  53. }
  54. $xml = $e->saveXml();
  55. $this->assertFalse(strpos($xml, 'pants'), '<pants> should not be in the xml output');
  56. $this->assertTrue(strpos($xml, 'marina.horde.org') !== false, 'the url attribute should be set');
  57. }
  58. public function testStrings()
  59. {
  60. $xml = "<entry>
  61. <title> Using C++ Intrinsic Functions for Pipelined Text Processing</title>
  62. <id>http://www.oreillynet.com/pub/wlg/8356</id>
  63. <link rel='alternate' href='http://www.oreillynet.com/pub/wlg/8356'/>
  64. <summary type='xhtml'>
  65. <div xmlns='http://www.w3.org/1999/xhtml'>
  66. 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.
  67. </div>
  68. </summary>
  69. <author><name>Rick Jelliffe</name></author>
  70. <updated>2005-11-07T08:15:57-08:00</updated>
  71. </entry>";
  72. $entry = new Zend_Feed_Entry_Atom('uri', $xml);
  73. $this->assertTrue($entry->summary instanceof Zend_Feed_Element, '__get access should return an Zend_Feed_Element instance');
  74. $this->assertFalse($entry->summary() instanceof Zend_Feed_Element, 'method access should not return an Zend_Feed_Element instance');
  75. $this->assertTrue(is_string($entry->summary()), 'method access should return a string');
  76. $this->assertFalse(is_string($entry->summary), '__get access should not return a string');
  77. }
  78. }