OfflineTest.php 4.9 KB

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