OfflineCredentialTest.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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_Service_DeveloperGarden
  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. if (!defined('PHPUnit_MAIN_METHOD')) {
  23. define('PHPUnit_MAIN_METHOD', 'Zend_Service_DeveloperGarden_CredentialTest::main');
  24. }
  25. /**
  26. * @see Zend_Service_DeveloperGarden_Credential
  27. */
  28. require_once 'Zend/Service/DeveloperGarden/Credential.php';
  29. /**
  30. * Zend_Service_DeveloperGarden test case
  31. *
  32. * @category Zend
  33. * @package Zend_Service_DeveloperGarden
  34. * @subpackage UnitTests
  35. * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
  36. * @license http://framework.zend.com/license/new-bsd New BSD License
  37. * @version $Id$
  38. */
  39. class Zend_Service_DeveloperGarden_OfflineCredentialTest extends PHPUnit_Framework_TestCase
  40. {
  41. /**
  42. * @var Zend_Service_DeveloperGarden_OfflineCredential_Mock
  43. */
  44. protected $_service = null;
  45. public static function main()
  46. {
  47. $suite = new PHPUnit_Framework_TestSuite(__CLASS__);
  48. PHPUnit_TextUI_TestRunner::run($suite);
  49. }
  50. public function setUp()
  51. {
  52. if (!defined('TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_LOGIN')) {
  53. define('TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_LOGIN', 'Unknown');
  54. }
  55. if (!defined('TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_PASSWORD')) {
  56. define('TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_PASSWORD', 'Unknown');
  57. }
  58. $this->service = new Zend_Service_DeveloperGarden_OfflineCredential_Mock();
  59. }
  60. public function testUserName()
  61. {
  62. $this->assertNull($this->service->getUsername());
  63. $this->assertNotNull(
  64. $this->service->setUsername(TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_LOGIN)
  65. );
  66. $this->assertEquals(
  67. TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_LOGIN,
  68. $this->service->getUsername()
  69. );
  70. }
  71. /**
  72. * @expectedException Zend_Service_DeveloperGarden_Client_Exception
  73. */
  74. public function testInvalidUsername()
  75. {
  76. $this->service->setUsername(null);
  77. }
  78. /**
  79. * @expectedException Zend_Service_DeveloperGarden_Client_Exception
  80. */
  81. public function testInvalidUsernameType()
  82. {
  83. $this->service->setUsername(1000);
  84. }
  85. public function testUsernameWithRealmDefault()
  86. {
  87. $username = $this->service->getUsername();
  88. $realm = $this->service->getRealm();
  89. $str = "$username@$realm";
  90. $this->assertEquals($str, $this->service->getUsername(true));
  91. }
  92. public function testUsernameWithRealmCustomized()
  93. {
  94. $username = 'MyOwnUsername';
  95. $realm = 'framework.zend.com';
  96. $str = "$username@$realm";
  97. $this->assertNotNull(
  98. $this->service->setUsername($username)
  99. );
  100. $this->assertNotNull(
  101. $this->service->setRealm($realm)
  102. );
  103. $this->assertEquals($str, $this->service->getUsername(true));
  104. }
  105. public function testPassword()
  106. {
  107. $this->assertNull($this->service->getPassword());
  108. $this->assertNotNull(
  109. $this->service->setPassword(TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_LOGIN)
  110. );
  111. $this->assertEquals(
  112. TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_LOGIN,
  113. $this->service->getPassword()
  114. );
  115. }
  116. /**
  117. * @expectedException Zend_Service_DeveloperGarden_Client_Exception
  118. */
  119. public function testInvalidPassword()
  120. {
  121. $this->service->setPassword(null);
  122. }
  123. /**
  124. * @expectedException Zend_Service_DeveloperGarden_Client_Exception
  125. */
  126. public function testInvalidPasswordType()
  127. {
  128. $this->service->setPassword(1000);
  129. }
  130. public function testRealm()
  131. {
  132. $this->assertEquals('t-online.de', $this->service->getRealm());
  133. $this->assertNotNull($this->service->setRealm('framework.zend.com'));
  134. $this->assertEquals('framework.zend.com', $this->service->getRealm());
  135. }
  136. /**
  137. * @expectedException Zend_Service_DeveloperGarden_Client_Exception
  138. */
  139. public function testInvalidRealm()
  140. {
  141. $this->service->setRealm(null);
  142. }
  143. /**
  144. * @expectedException Zend_Service_DeveloperGarden_Client_Exception
  145. */
  146. public function testInvalidRealmType()
  147. {
  148. $this->service->setRealm(1000);
  149. }
  150. public function testSetGetUsername()
  151. {
  152. $this->assertNull($this->service->getUsername());
  153. $this->assertNotNull(
  154. $this->service->setUsername('MarcoKaiser')
  155. );
  156. $this->assertEquals('MarcoKaiser', $this->service->getUsername());
  157. }
  158. public function testSetGetPassword()
  159. {
  160. $this->assertNull($this->service->getPassword());
  161. $this->assertNotNull(
  162. $this->service->setPassword('S3cr37P4ssw0rd')
  163. );
  164. $this->assertEquals('S3cr37P4ssw0rd', $this->service->getPassword());
  165. }
  166. public function testConstructor()
  167. {
  168. $username = 'MyUser';
  169. $password = 'MyPassword';
  170. $realm = 'Zend.Com';
  171. $service = new Zend_Service_DeveloperGarden_OfflineCredential_Mock($username, $password, $realm);
  172. $this->assertEquals($username, $service->getUsername());
  173. $this->assertEquals($password, $service->getPassword());
  174. $this->assertEquals($realm, $service->getRealm());
  175. }
  176. }
  177. class Zend_Service_DeveloperGarden_OfflineCredential_Mock
  178. extends Zend_Service_DeveloperGarden_Credential
  179. {
  180. }
  181. if (PHPUnit_MAIN_METHOD == 'Zend_Service_DeveloperGarden_OfflineCredentialTest::main') {
  182. Zend_Service_DeveloperGarden_OfflineCredentialTest::main();
  183. }