LoginTest.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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/Login.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_LoginTest extends PHPUnit_Framework_TestCase
  30. {
  31. public function setUp() {
  32. $this->loginText = file_get_contents(
  33. 'Zend/Gdata/Gapps/_files/LoginElementSample1.xml',
  34. true);
  35. $this->login = new Zend_Gdata_Gapps_Extension_Login();
  36. }
  37. public function testEmptyLoginShouldHaveNoExtensionElements() {
  38. $this->assertTrue(is_array($this->login->extensionElements));
  39. $this->assertTrue(count($this->login->extensionElements) == 0);
  40. }
  41. public function testEmptyLoginShouldHaveNoExtensionAttributes() {
  42. $this->assertTrue(is_array($this->login->extensionAttributes));
  43. $this->assertTrue(count($this->login->extensionAttributes) == 0);
  44. }
  45. public function testSampleLoginShouldHaveNoExtensionElements() {
  46. $this->login->transferFromXML($this->loginText);
  47. $this->assertTrue(is_array($this->login->extensionElements));
  48. $this->assertTrue(count($this->login->extensionElements) == 0);
  49. }
  50. public function testSampleLoginShouldHaveNoExtensionAttributes() {
  51. $this->login->transferFromXML($this->loginText);
  52. $this->assertTrue(is_array($this->login->extensionAttributes));
  53. $this->assertTrue(count($this->login->extensionAttributes) == 0);
  54. }
  55. public function testNormalLoginShouldHaveNoExtensionElements() {
  56. $this->login->username = "johndoe";
  57. $this->login->password = "abcdefg1234567890";
  58. $this->login->hashFunctionName = "Foo";
  59. $this->login->suspended = true;
  60. $this->login->admin = true;
  61. $this->login->changePasswordAtNextLogin = true;
  62. $this->login->agreedToTerms = false;
  63. $this->assertEquals("johndoe", $this->login->username);
  64. $this->assertEquals("abcdefg1234567890", $this->login->password);
  65. $this->assertEquals("Foo", $this->login->hashFunctionName);
  66. $this->assertEquals(true, $this->login->suspended);
  67. $this->assertEquals(true, $this->login->admin);
  68. $this->assertEquals(true, $this->login->changePasswordAtNextLogin);
  69. $this->assertEquals(false, $this->login->agreedToTerms);
  70. $this->assertEquals(0, count($this->login->extensionElements));
  71. $newLogin = new Zend_Gdata_Gapps_Extension_Login();
  72. $newLogin->transferFromXML($this->login->saveXML());
  73. $this->assertEquals(0, count($newLogin->extensionElements));
  74. $newLogin->extensionElements = array(
  75. new Zend_Gdata_App_Extension_Element('foo', 'atom', null, 'bar'));
  76. $this->assertEquals(1, count($newLogin->extensionElements));
  77. $this->assertEquals("johndoe", $newLogin->username);
  78. $this->assertEquals("abcdefg1234567890", $newLogin->password);
  79. $this->assertEquals("Foo", $newLogin->hashFunctionName);
  80. $this->assertEquals(true, $newLogin->suspended);
  81. $this->assertEquals(true, $newLogin->admin);
  82. $this->assertEquals(true, $newLogin->changePasswordAtNextLogin);
  83. $this->assertEquals(false, $newLogin->agreedToTerms);
  84. /* try constructing using magic factory */
  85. $gdata = new Zend_Gdata_Gapps();
  86. $newLogin2 = $gdata->newLogin();
  87. $newLogin2->transferFromXML($newLogin->saveXML());
  88. $this->assertEquals(1, count($newLogin2->extensionElements));
  89. $this->assertEquals("johndoe", $newLogin2->username);
  90. $this->assertEquals("abcdefg1234567890", $newLogin2->password);
  91. $this->assertEquals("Foo", $newLogin2->hashFunctionName);
  92. $this->assertEquals(true, $newLogin2->suspended);
  93. $this->assertEquals(true, $newLogin2->admin);
  94. $this->assertEquals(true, $newLogin2->changePasswordAtNextLogin);
  95. $this->assertEquals(false, $newLogin2->agreedToTerms);
  96. }
  97. public function testEmptyLoginToAndFromStringShouldMatch() {
  98. $loginXml = $this->login->saveXML();
  99. $newLogin = new Zend_Gdata_Gapps_Extension_Login();
  100. $newLogin->transferFromXML($loginXml);
  101. $newLoginXml = $newLogin->saveXML();
  102. $this->assertTrue($loginXml == $newLoginXml);
  103. }
  104. public function testLoginWithValueToAndFromStringShouldMatch() {
  105. $this->login->username = "johndoe";
  106. $this->login->password = "abcdefg1234567890";
  107. $this->login->hashFunctionName = "Foo";
  108. $this->login->suspended = true;
  109. $this->login->admin = true;
  110. $this->login->changePasswordAtNextLogin = true;
  111. $this->login->agreedToTerms = false;
  112. $loginXml = $this->login->saveXML();
  113. $newLogin = new Zend_Gdata_Gapps_Extension_Login();
  114. $newLogin->transferFromXML($loginXml);
  115. $newLoginXml = $newLogin->saveXML();
  116. $this->assertTrue($loginXml == $newLoginXml);
  117. $this->assertEquals("johndoe", $this->login->username);
  118. $this->assertEquals("abcdefg1234567890", $this->login->password);
  119. $this->assertEquals("Foo", $this->login->hashFunctionName);
  120. $this->assertEquals(true, $this->login->suspended);
  121. $this->assertEquals(true, $this->login->admin);
  122. $this->assertEquals(true, $this->login->changePasswordAtNextLogin);
  123. $this->assertEquals(false, $this->login->agreedToTerms);
  124. }
  125. public function testExtensionAttributes() {
  126. $extensionAttributes = $this->login->extensionAttributes;
  127. $extensionAttributes['foo1'] = array('name'=>'foo1', 'value'=>'bar');
  128. $extensionAttributes['foo2'] = array('name'=>'foo2', 'value'=>'rab');
  129. $this->login->extensionAttributes = $extensionAttributes;
  130. $this->assertEquals('bar', $this->login->extensionAttributes['foo1']['value']);
  131. $this->assertEquals('rab', $this->login->extensionAttributes['foo2']['value']);
  132. $loginXml = $this->login->saveXML();
  133. $newLogin = new Zend_Gdata_Gapps_Extension_Login();
  134. $newLogin->transferFromXML($loginXml);
  135. $this->assertEquals('bar', $newLogin->extensionAttributes['foo1']['value']);
  136. $this->assertEquals('rab', $newLogin->extensionAttributes['foo2']['value']);
  137. }
  138. public function testConvertFullLoginToAndFromString() {
  139. $this->login->transferFromXML($this->loginText);
  140. $this->assertEquals("SusanJones-1321", $this->login->username);
  141. $this->assertEquals("123\$\$abc", $this->login->password);
  142. $this->assertEquals("SHA-1", $this->login->hashFunctionName);
  143. $this->assertEquals(false, $this->login->suspended);
  144. $this->assertEquals(false, $this->login->admin);
  145. $this->assertEquals(false, $this->login->changePasswordAtNextLogin);
  146. $this->assertEquals(true, $this->login->agreedToTerms);
  147. }
  148. }