NameTest.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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/Gapps/Extension/Name.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_Gapps_NameTest extends PHPUnit_Framework_TestCase
  30. {
  31. public function setUp() {
  32. $this->theNameText = file_get_contents(
  33. 'Zend/Gdata/Gapps/_files/NameElementSample1.xml',
  34. true);
  35. $this->theName = new Zend_Gdata_Gapps_Extension_Name();
  36. }
  37. public function testEmptyNameShouldHaveNoExtensionElements() {
  38. $this->assertTrue(is_array($this->theName->extensionElements));
  39. $this->assertTrue(count($this->theName->extensionElements) == 0);
  40. }
  41. public function testEmptyNameShouldHaveNoExtensionAttributes() {
  42. $this->assertTrue(is_array($this->theName->extensionAttributes));
  43. $this->assertTrue(count($this->theName->extensionAttributes) == 0);
  44. }
  45. public function testSampleNameShouldHaveNoExtensionElements() {
  46. $this->theName->transferFromXML($this->theNameText);
  47. $this->assertTrue(is_array($this->theName->extensionElements));
  48. $this->assertTrue(count($this->theName->extensionElements) == 0);
  49. }
  50. public function testSampleNameShouldHaveNoExtensionAttributes() {
  51. $this->theName->transferFromXML($this->theNameText);
  52. $this->assertTrue(is_array($this->theName->extensionAttributes));
  53. $this->assertTrue(count($this->theName->extensionAttributes) == 0);
  54. }
  55. public function testNormalNameShouldHaveNoExtensionElements() {
  56. $this->theName->givenName = "John";
  57. $this->theName->familyName = "Doe";
  58. $this->assertEquals("John", $this->theName->givenName);
  59. $this->assertEquals("Doe", $this->theName->familyName);
  60. $this->assertEquals(0, count($this->theName->extensionElements));
  61. $newName = new Zend_Gdata_Gapps_Extension_Name();
  62. $newName->transferFromXML($this->theName->saveXML());
  63. $this->assertEquals(0, count($newName->extensionElements));
  64. $newName->extensionElements = array(
  65. new Zend_Gdata_App_Extension_Element('foo', 'atom', null, 'bar'));
  66. $this->assertEquals(1, count($newName->extensionElements));
  67. $this->assertEquals("John", $newName->givenName);
  68. $this->assertEquals("Doe", $newName->familyName);
  69. /* try constructing using magic factory */
  70. $gdata = new Zend_Gdata_Gapps();
  71. $newName2 = $gdata->newName();
  72. $newName2->transferFromXML($newName->saveXML());
  73. $this->assertEquals(1, count($newName2->extensionElements));
  74. $this->assertEquals("John", $newName2->givenName);
  75. $this->assertEquals("Doe", $newName2->familyName);
  76. }
  77. public function testEmptyNameToAndFromStringShouldMatch() {
  78. $nameXml = $this->theName->saveXML();
  79. $newName = new Zend_Gdata_Gapps_Extension_Name();
  80. $newName->transferFromXML($nameXml);
  81. $newNameXml = $newName->saveXML();
  82. $this->assertTrue($nameXml == $newNameXml);
  83. }
  84. public function testNameWithValueToAndFromStringShouldMatch() {
  85. $this->theName->givenName = "John";
  86. $this->theName->familyName = "Doe";
  87. $nameXml = $this->theName->saveXML();
  88. $newName = new Zend_Gdata_Gapps_Extension_Name();
  89. $newName->transferFromXML($nameXml);
  90. $newNameXml = $newName->saveXML();
  91. $this->assertTrue($nameXml == $newNameXml);
  92. $this->assertEquals("John", $this->theName->givenName);
  93. $this->assertEquals("Doe", $this->theName->familyName);
  94. }
  95. public function testExtensionAttributes() {
  96. $extensionAttributes = $this->theName->extensionAttributes;
  97. $extensionAttributes['foo1'] = array('name'=>'foo1', 'value'=>'bar');
  98. $extensionAttributes['foo2'] = array('name'=>'foo2', 'value'=>'rab');
  99. $this->theName->extensionAttributes = $extensionAttributes;
  100. $this->assertEquals('bar', $this->theName->extensionAttributes['foo1']['value']);
  101. $this->assertEquals('rab', $this->theName->extensionAttributes['foo2']['value']);
  102. $nameXml = $this->theName->saveXML();
  103. $newName = new Zend_Gdata_Gapps_Extension_Name();
  104. $newName->transferFromXML($nameXml);
  105. $this->assertEquals('bar', $newName->extensionAttributes['foo1']['value']);
  106. $this->assertEquals('rab', $newName->extensionAttributes['foo2']['value']);
  107. }
  108. public function testConvertFullNameToAndFromString() {
  109. $this->theName->transferFromXML($this->theNameText);
  110. $this->assertEquals("Susan", $this->theName->givenName);
  111. $this->assertEquals("Jones", $this->theName->familyName);
  112. }
  113. }