LoginTest.php 7.6 KB

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