WhoTest.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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
  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/Extension/Who.php';
  22. require_once 'Zend/Gdata.php';
  23. /**
  24. * @package Zend_Gdata
  25. * @subpackage UnitTests
  26. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  27. * @license http://framework.zend.com/license/new-bsd New BSD License
  28. */
  29. class Zend_Gdata_WhoTest extends PHPUnit_Framework_TestCase
  30. {
  31. public function setUp() {
  32. $this->whoText = file_get_contents(
  33. 'Zend/Gdata/_files/WhoElementSample1.xml',
  34. true);
  35. $this->who = new Zend_Gdata_Extension_Who();
  36. }
  37. public function testEmptyWhoShouldHaveNoExtensionElements() {
  38. $this->assertTrue(is_array($this->who->extensionElements));
  39. $this->assertTrue(count($this->who->extensionElements) == 0);
  40. }
  41. public function testEmptyWhoShouldHaveNoExtensionAttributes() {
  42. $this->assertTrue(is_array($this->who->extensionAttributes));
  43. $this->assertTrue(count($this->who->extensionAttributes) == 0);
  44. }
  45. public function testSampleWhoShouldHaveNoExtensionElements() {
  46. $this->who->transferFromXML($this->whoText);
  47. $this->assertTrue(is_array($this->who->extensionElements));
  48. $this->assertTrue(count($this->who->extensionElements) == 0);
  49. }
  50. public function testSampleWhoShouldHaveNoExtensionAttributes() {
  51. $this->who->transferFromXML($this->whoText);
  52. $this->assertTrue(is_array($this->who->extensionAttributes));
  53. $this->assertTrue(count($this->who->extensionAttributes) == 0);
  54. }
  55. public function testNormalWhoShouldHaveNoExtensionElements() {
  56. $this->who->valueString = "Test Value String";
  57. $this->who->rel = "http://schemas.google.com/g/2005#event.speaker";
  58. $this->who->email = "testemail@somewhere.domain.invalid";
  59. $this->assertEquals("Test Value String", $this->who->valueString);
  60. $this->assertEquals("http://schemas.google.com/g/2005#event.speaker", $this->who->rel);
  61. $this->assertEquals("testemail@somewhere.domain.invalid", $this->who->email);
  62. $this->assertEquals(0, count($this->who->extensionElements));
  63. $newWho = new Zend_Gdata_Extension_Who();
  64. $newWho->transferFromXML($this->who->saveXML());
  65. $this->assertEquals(0, count($newWho->extensionElements));
  66. $newWho->extensionElements = array(
  67. new Zend_Gdata_App_Extension_Element('foo', 'atom', null, 'bar'));
  68. $this->assertEquals(1, count($newWho->extensionElements));
  69. $this->assertEquals("Test Value String", $newWho->valueString);
  70. $this->assertEquals("http://schemas.google.com/g/2005#event.speaker", $newWho->rel);
  71. $this->assertEquals("testemail@somewhere.domain.invalid", $newWho->email);
  72. /* try constructing using magic factory */
  73. $gdata = new Zend_Gdata();
  74. $newWho2 = $gdata->newWho();
  75. $newWho2->transferFromXML($newWho->saveXML());
  76. $this->assertEquals(1, count($newWho2->extensionElements));
  77. $this->assertEquals("Test Value String", $newWho2->valueString);
  78. $this->assertEquals("http://schemas.google.com/g/2005#event.speaker", $newWho2->rel);
  79. $this->assertEquals("testemail@somewhere.domain.invalid", $newWho2->email);
  80. }
  81. public function testEmptyWhoToAndFromStringShouldMatch() {
  82. $whoXml = $this->who->saveXML();
  83. $newWho = new Zend_Gdata_Extension_Who();
  84. $newWho->transferFromXML($whoXml);
  85. $newWhoXml = $newWho->saveXML();
  86. $this->assertTrue($whoXml == $newWhoXml);
  87. }
  88. public function testWhoWithValueToAndFromStringShouldMatch() {
  89. $this->who->valueString = "Test Value String";
  90. $this->who->rel = "http://schemas.google.com/g/2005#event.speaker";
  91. $this->who->email = "testemail@somewhere.domain.invalid";
  92. $whoXml = $this->who->saveXML();
  93. $newWho = new Zend_Gdata_Extension_Who();
  94. $newWho->transferFromXML($whoXml);
  95. $newWhoXml = $newWho->saveXML();
  96. $this->assertTrue($whoXml == $newWhoXml);
  97. $this->assertEquals("Test Value String", $this->who->valueString);
  98. $this->assertEquals("http://schemas.google.com/g/2005#event.speaker", $this->who->rel);
  99. $this->assertEquals("testemail@somewhere.domain.invalid", $this->who->email);
  100. }
  101. public function testExtensionAttributes() {
  102. $extensionAttributes = $this->who->extensionAttributes;
  103. $extensionAttributes['foo1'] = array('name'=>'foo1', 'value'=>'bar');
  104. $extensionAttributes['foo2'] = array('name'=>'foo2', 'value'=>'rab');
  105. $this->who->extensionAttributes = $extensionAttributes;
  106. $this->assertEquals('bar', $this->who->extensionAttributes['foo1']['value']);
  107. $this->assertEquals('rab', $this->who->extensionAttributes['foo2']['value']);
  108. $whoXml = $this->who->saveXML();
  109. $newWho = new Zend_Gdata_Extension_Who();
  110. $newWho->transferFromXML($whoXml);
  111. $this->assertEquals('bar', $newWho->extensionAttributes['foo1']['value']);
  112. $this->assertEquals('rab', $newWho->extensionAttributes['foo2']['value']);
  113. }
  114. public function testConvertFullWhoToAndFromString() {
  115. $this->who->transferFromXML($this->whoText);
  116. $this->assertEquals("Jo", $this->who->valueString);
  117. $this->assertEquals("http://schemas.google.com/g/2005#event.attendee", $this->who->rel);
  118. $this->assertEquals("jo@nowhere.invalid", $this->who->email);
  119. $this->assertTrue($this->who->attendeeStatus instanceof Zend_Gdata_Extension_AttendeeStatus);
  120. $this->assertEquals("http://schemas.google.com/g/2005#event.tentative", $this->who->attendeeStatus->value);
  121. $this->assertTrue($this->who->attendeeType instanceof Zend_Gdata_Extension_AttendeeType);
  122. $this->assertEquals("http://schemas.google.com/g/2005#event.required", $this->who->attendeeType->value);
  123. $this->assertTrue($this->who->entryLink instanceof Zend_Gdata_Extension_EntryLink);
  124. $this->assertEquals("http://gmail.com/jo/contacts/Jo", $this->who->entryLink->href);
  125. }
  126. }