OfflineTest.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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-2010 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-2010 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. if (!extension_loaded('ldap')) {
  60. $this->markTestSkipped('LDAP is not enabled');
  61. }
  62. $this->_ldap = new Zend_Ldap();
  63. }
  64. /**
  65. * @return void
  66. */
  67. public function testInvalidOptionResultsInException()
  68. {
  69. $optionName = 'invalid';
  70. try {
  71. $this->_ldap->setOptions(array($optionName => 'irrelevant'));
  72. $this->fail('Expected Zend_Ldap_Exception not thrown');
  73. } catch (Zend_Ldap_Exception $e) {
  74. $this->assertEquals("Unknown Zend_Ldap option: $optionName", $e->getMessage());
  75. }
  76. }
  77. public function testException()
  78. {
  79. $e = new Zend_Ldap_Exception(null, '', 0);
  80. $this->assertEquals('no exception message', $e->getMessage());
  81. $this->assertEquals(0, $e->getCode());
  82. $this->assertEquals(0, $e->getErrorCode());
  83. $e = new Zend_Ldap_Exception(null, '', 15);
  84. $this->assertEquals('0xf: no exception message', $e->getMessage());
  85. $this->assertEquals(15, $e->getCode());
  86. $this->assertEquals(15, $e->getErrorCode());
  87. }
  88. public function testOptionsGetter()
  89. {
  90. $options = array(
  91. 'host' => TESTS_ZEND_LDAP_HOST,
  92. 'username' => TESTS_ZEND_LDAP_USERNAME,
  93. 'password' => TESTS_ZEND_LDAP_PASSWORD,
  94. 'baseDn' => TESTS_ZEND_LDAP_BASE_DN,
  95. );
  96. $ldap = new Zend_Ldap($options);
  97. $this->assertEquals(array(
  98. 'host' => TESTS_ZEND_LDAP_HOST,
  99. 'port' => 0,
  100. 'useSsl' => false,
  101. 'username' => TESTS_ZEND_LDAP_USERNAME,
  102. 'password' => TESTS_ZEND_LDAP_PASSWORD,
  103. 'bindRequiresDn' => false,
  104. 'baseDn' => TESTS_ZEND_LDAP_BASE_DN,
  105. 'accountCanonicalForm' => null,
  106. 'accountDomainName' => null,
  107. 'accountDomainNameShort' => null,
  108. 'accountFilterFormat' => null,
  109. 'allowEmptyPassword' => false,
  110. 'useStartTls' => false,
  111. 'optReferrals' => false,
  112. 'tryUsernameSplit' => true
  113. ), $ldap->getOptions());
  114. }
  115. public function testConfigObject()
  116. {
  117. /**
  118. * @see Zend_Config
  119. */
  120. require_once 'Zend/Config.php';
  121. $config = new Zend_Config(array(
  122. 'host' => TESTS_ZEND_LDAP_HOST,
  123. 'username' => TESTS_ZEND_LDAP_USERNAME,
  124. 'password' => TESTS_ZEND_LDAP_PASSWORD,
  125. 'baseDn' => TESTS_ZEND_LDAP_BASE_DN,
  126. ));
  127. $ldap = new Zend_Ldap($config);
  128. $this->assertEquals(array(
  129. 'host' => TESTS_ZEND_LDAP_HOST,
  130. 'port' => 0,
  131. 'useSsl' => false,
  132. 'username' => TESTS_ZEND_LDAP_USERNAME,
  133. 'password' => TESTS_ZEND_LDAP_PASSWORD,
  134. 'bindRequiresDn' => false,
  135. 'baseDn' => TESTS_ZEND_LDAP_BASE_DN,
  136. 'accountCanonicalForm' => null,
  137. 'accountDomainName' => null,
  138. 'accountDomainNameShort' => null,
  139. 'accountFilterFormat' => null,
  140. 'allowEmptyPassword' => false,
  141. 'useStartTls' => false,
  142. 'optReferrals' => false,
  143. 'tryUsernameSplit' => true
  144. ), $ldap->getOptions());
  145. }
  146. }