AuthorTest.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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_Gdata_App
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2006 Zend Technologies USA Inc. (http://www.zend.com);
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. require_once 'Zend/Gdata/App/Extension/Author.php';
  22. require_once 'Zend/Gdata/App.php';
  23. /**
  24. * @package Zend_Gdata_App
  25. * @subpackage UnitTests
  26. */
  27. class Zend_Gdata_App_AuthorTest extends PHPUnit_Framework_TestCase
  28. {
  29. public function setUp() {
  30. $this->authorText = file_get_contents(
  31. 'Zend/Gdata/App/_files/AuthorElementSample1.xml',
  32. true);
  33. $this->author = new Zend_Gdata_App_Extension_Author();
  34. }
  35. public function testEmptyAuthorShouldHaveEmptyExtensionsList() {
  36. $this->assertTrue(is_array($this->author->extensionElements));
  37. $this->assertTrue(count($this->author->extensionElements) == 0);
  38. }
  39. public function testNormalAuthorShouldHaveNoExtensionElements() {
  40. $this->author->name = new Zend_Gdata_App_Extension_Name('Jeff Scudder');
  41. $this->assertEquals($this->author->name->text, 'Jeff Scudder');
  42. $this->assertEquals(count($this->author->extensionElements), 0);
  43. $newAuthor = new Zend_Gdata_App_Extension_Author();
  44. $newAuthor->transferFromXML($this->author->saveXML());
  45. $this->assertEquals(count($newAuthor->extensionElements), 0);
  46. $newAuthor->extensionElements = array(
  47. new Zend_Gdata_App_Extension_Element('foo', 'atom', null, 'bar'));
  48. $this->assertEquals(count($newAuthor->extensionElements), 1);
  49. $this->assertEquals($newAuthor->name->text, 'Jeff Scudder');
  50. /* try constructing using magic factory */
  51. $app = new Zend_Gdata_App();
  52. $newAuthor2 = $app->newAuthor();
  53. $newAuthor2->transferFromXML($newAuthor->saveXML());
  54. $this->assertEquals(count($newAuthor2->extensionElements), 1);
  55. $this->assertEquals($newAuthor2->name->text, 'Jeff Scudder');
  56. }
  57. public function testEmptyAuthorToAndFromStringShouldMatch() {
  58. $authorXml = $this->author->saveXML();
  59. $newAuthor = new Zend_Gdata_App_Extension_Author();
  60. $newAuthor->transferFromXML($authorXml);
  61. $newAuthorXml = $newAuthor->saveXML();
  62. $this->assertTrue($authorXml == $newAuthorXml);
  63. }
  64. public function testAuthorWithNameEmailToAndFromStringShouldMatch() {
  65. $this->author->name = new Zend_Gdata_App_Extension_Name('Jeff Scudder');
  66. $this->author->email = new Zend_Gdata_App_Extension_Email(
  67. 'api.jscudder@gmail.com');
  68. $this->author->uri = new Zend_Gdata_App_Extension_Uri(
  69. 'http://code.google.com/apis/gdata/');
  70. $authorXml = $this->author->saveXML();
  71. $newAuthor = new Zend_Gdata_App_Extension_Author();
  72. $newAuthor->transferFromXML($authorXml);
  73. $newAuthorXml = $newAuthor->saveXML();
  74. $this->assertTrue($authorXml == $newAuthorXml);
  75. $this->assertEquals('Jeff Scudder', $newAuthor->name->text);
  76. $this->assertEquals('api.jscudder@gmail.com', $newAuthor->email->text);
  77. $this->assertEquals('http://code.google.com/apis/gdata/', $newAuthor->uri->text);
  78. }
  79. public function testExtensionAttributes() {
  80. $extensionAttributes = $this->author->extensionAttributes;
  81. $extensionAttributes['foo1'] = array('name'=>'foo1', 'value'=>'bar');
  82. $extensionAttributes['foo2'] = array('name'=>'foo2', 'value'=>'rab');
  83. $this->author->extensionAttributes = $extensionAttributes;
  84. $this->assertEquals('bar', $this->author->extensionAttributes['foo1']['value']);
  85. $this->assertEquals('rab', $this->author->extensionAttributes['foo2']['value']);
  86. $authorXml = $this->author->saveXML();
  87. $newAuthor = new Zend_Gdata_App_Extension_Author();
  88. $newAuthor->transferFromXML($authorXml);
  89. //var_dump($this->author);
  90. //print $authorXml;
  91. $this->assertEquals('bar', $newAuthor->extensionAttributes['foo1']['value']);
  92. $this->assertEquals('rab', $newAuthor->extensionAttributes['foo2']['value']);
  93. }
  94. public function testConvertFullAuthorToAndFromString() {
  95. $this->author->transferFromXML($this->authorText);
  96. $this->assertEquals($this->author->name->text, 'John Doe');
  97. $this->assertEquals($this->author->email->text,
  98. 'johndoes@someemailadress.com');
  99. $this->assertEquals($this->author->uri->text, 'http://www.google.com');
  100. }
  101. }