AuthorTest.php 5.1 KB

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