OfflineTest.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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_Ldap
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2009 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. * Test helper
  24. */
  25. require_once dirname(__FILE__) . '/../../TestHelper.php';
  26. /**
  27. * @see Zend_Ldap
  28. */
  29. require_once 'Zend/Ldap.php';
  30. /**
  31. * @see Zend_Ldap_Exception
  32. */
  33. require_once 'Zend/Ldap/Exception.php';
  34. /**
  35. * @category Zend
  36. * @package Zend_Ldap
  37. * @subpackage UnitTests
  38. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  39. * @license http://framework.zend.com/license/new-bsd New BSD License
  40. * @group Zend_Ldap
  41. */
  42. class Zend_Ldap_OfflineTest extends PHPUnit_Framework_TestCase
  43. {
  44. /**
  45. * Zend_Ldap instance
  46. *
  47. * @var Zend_Ldap
  48. */
  49. protected $_ldap = null;
  50. /**
  51. * Setup operations run prior to each test method:
  52. *
  53. * * Creates an instance of Zend_Ldap
  54. *
  55. * @return void
  56. */
  57. public function setUp()
  58. {
  59. $this->_ldap = new Zend_Ldap();
  60. }
  61. /**
  62. * @return void
  63. */
  64. public function testInvalidOptionResultsInException()
  65. {
  66. $optionName = 'invalid';
  67. try {
  68. $this->_ldap->setOptions(array($optionName => 'irrelevant'));
  69. $this->fail('Expected Zend_Ldap_Exception not thrown');
  70. } catch (Zend_Ldap_Exception $e) {
  71. $this->assertEquals("Unknown Zend_Ldap option: $optionName", $e->getMessage());
  72. }
  73. }
  74. public function testException()
  75. {
  76. $e = new Zend_Ldap_Exception(null, '', 0);
  77. $this->assertEquals('no exception message', $e->getMessage());
  78. $this->assertEquals(0, $e->getCode());
  79. $this->assertEquals(0, $e->getErrorCode());
  80. $e = new Zend_Ldap_Exception(null, '', 15);
  81. $this->assertEquals('0xf: no exception message', $e->getMessage());
  82. $this->assertEquals(15, $e->getCode());
  83. $this->assertEquals(15, $e->getErrorCode());
  84. }
  85. public function testOptionsGetter()
  86. {
  87. $options = array(
  88. 'host' => TESTS_ZEND_LDAP_HOST,
  89. 'username' => TESTS_ZEND_LDAP_USERNAME,
  90. 'password' => TESTS_ZEND_LDAP_PASSWORD,
  91. 'baseDn' => TESTS_ZEND_LDAP_BASE_DN,
  92. );
  93. $ldap = new Zend_Ldap($options);
  94. $this->assertEquals(array(
  95. 'host' => TESTS_ZEND_LDAP_HOST,
  96. 'port' => 0,
  97. 'useSsl' => false,
  98. 'username' => TESTS_ZEND_LDAP_USERNAME,
  99. 'password' => TESTS_ZEND_LDAP_PASSWORD,
  100. 'bindRequiresDn' => false,
  101. 'baseDn' => TESTS_ZEND_LDAP_BASE_DN,
  102. 'accountCanonicalForm' => null,
  103. 'accountDomainName' => null,
  104. 'accountDomainNameShort' => null,
  105. 'accountFilterFormat' => null,
  106. 'allowEmptyPassword' => false,
  107. 'useStartTls' => false,
  108. 'optReferrals' => false,
  109. 'tryUsernameSplit' => true
  110. ), $ldap->getOptions());
  111. }
  112. public function testConfigObject()
  113. {
  114. /**
  115. * @see Zend_Config
  116. */
  117. require_once 'Zend/Config.php';
  118. $config = new Zend_Config(array(
  119. 'host' => TESTS_ZEND_LDAP_HOST,
  120. 'username' => TESTS_ZEND_LDAP_USERNAME,
  121. 'password' => TESTS_ZEND_LDAP_PASSWORD,
  122. 'baseDn' => TESTS_ZEND_LDAP_BASE_DN,
  123. ));
  124. $ldap = new Zend_Ldap($config);
  125. $this->assertEquals(array(
  126. 'host' => TESTS_ZEND_LDAP_HOST,
  127. 'port' => 0,
  128. 'useSsl' => false,
  129. 'username' => TESTS_ZEND_LDAP_USERNAME,
  130. 'password' => TESTS_ZEND_LDAP_PASSWORD,
  131. 'bindRequiresDn' => false,
  132. 'baseDn' => TESTS_ZEND_LDAP_BASE_DN,
  133. 'accountCanonicalForm' => null,
  134. 'accountDomainName' => null,
  135. 'accountDomainNameShort' => null,
  136. 'accountFilterFormat' => null,
  137. 'allowEmptyPassword' => false,
  138. 'useStartTls' => false,
  139. 'optReferrals' => false,
  140. 'tryUsernameSplit' => true
  141. ), $ldap->getOptions());
  142. }
  143. }