OfflineTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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_Auth
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2012 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. /**
  23. * @see Zend_Auth_Adapter_Ldap
  24. */
  25. require_once 'Zend/Auth/Adapter/Ldap.php';
  26. /**
  27. * @see Zend_Ldap
  28. */
  29. require_once 'Zend/Ldap.php';
  30. /**
  31. * @category Zend
  32. * @package Zend_Auth
  33. * @subpackage UnitTests
  34. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  35. * @license http://framework.zend.com/license/new-bsd New BSD License
  36. * @group Zend_Auth
  37. */
  38. class Zend_Auth_Adapter_Ldap_OfflineTest extends PHPUnit_Framework_TestCase
  39. {
  40. /**
  41. * Authentication adapter instance
  42. *
  43. * @var Zend_Auth_Adapter_Ldap
  44. */
  45. protected $_adapter = null;
  46. /**
  47. * Setup operations run prior to each test method:
  48. *
  49. * * Creates an instance of Zend_Auth_Adapter_Ldap
  50. *
  51. * @return void
  52. */
  53. public function setUp()
  54. {
  55. $this->_adapter = new Zend_Auth_Adapter_Ldap();
  56. }
  57. public function testGetSetLdap()
  58. {
  59. if (!extension_loaded('ldap')) {
  60. $this->markTestSkipped('LDAP is not enabled');
  61. }
  62. $this->_adapter->setLdap(new Zend_Ldap());
  63. $this->assertTrue($this->_adapter->getLdap() instanceof Zend_Ldap);
  64. }
  65. public function testUsernameIsNullIfNotSet()
  66. {
  67. $this->assertNull($this->_adapter->getUsername());
  68. }
  69. public function testPasswordIsNullIfNotSet()
  70. {
  71. $this->assertNull($this->_adapter->getPassword());
  72. }
  73. public function testSetAndGetUsername()
  74. {
  75. $usernameExpected = 'someUsername';
  76. $usernameActual = $this->_adapter->setUsername($usernameExpected)
  77. ->getUsername();
  78. $this->assertSame($usernameExpected, $usernameActual);
  79. }
  80. public function testSetAndGetPassword()
  81. {
  82. $passwordExpected = 'somePassword';
  83. $passwordActual = $this->_adapter->setPassword($passwordExpected)
  84. ->getPassword();
  85. $this->assertSame($passwordExpected, $passwordActual);
  86. }
  87. public function testSetIdentityProxiesToSetUsername()
  88. {
  89. $usernameExpected = 'someUsername';
  90. $usernameActual = $this->_adapter->setIdentity($usernameExpected)
  91. ->getUsername();
  92. $this->assertSame($usernameExpected, $usernameActual);
  93. }
  94. public function testSetCredentialProxiesToSetPassword()
  95. {
  96. $passwordExpected = 'somePassword';
  97. $passwordActual = $this->_adapter->setCredential($passwordExpected)
  98. ->getPassword();
  99. $this->assertSame($passwordExpected, $passwordActual);
  100. }
  101. }