OnlineTestCase.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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-2008 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /**
  22. * Zend_Ldap_TestCase
  23. */
  24. require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'TestCase.php';
  25. /**
  26. * @see Zend_Ldap
  27. */
  28. require_once 'Zend/Ldap.php';
  29. /**
  30. * @category Zend
  31. * @package Zend_Ldap
  32. * @subpackage UnitTests
  33. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  34. * @license http://framework.zend.com/license/new-bsd New BSD License
  35. */
  36. abstract class Zend_Ldap_OnlineTestCase extends Zend_Ldap_TestCase
  37. {
  38. /**
  39. * @var Zend_Ldap
  40. */
  41. private $_ldap;
  42. /**
  43. * @var array
  44. */
  45. private $_nodes;
  46. /**
  47. * @return Zend_Ldap
  48. */
  49. protected function _getLdap()
  50. {
  51. return $this->_ldap;
  52. }
  53. protected function setUp()
  54. {
  55. if (!TESTS_ZEND_LDAP_ONLINE_ENABLED) {
  56. $this->markTestSkipped("Test skipped due to test configuration");
  57. return;
  58. }
  59. $options = array(
  60. 'host' => TESTS_ZEND_LDAP_HOST,
  61. 'username' => TESTS_ZEND_LDAP_USERNAME,
  62. 'password' => TESTS_ZEND_LDAP_PASSWORD,
  63. 'baseDn' => TESTS_ZEND_LDAP_WRITEABLE_SUBTREE,
  64. );
  65. if (defined('TESTS_ZEND_LDAP_PORT') && TESTS_ZEND_LDAP_PORT != 389)
  66. $options['port'] = TESTS_ZEND_LDAP_PORT;
  67. if (defined('TESTS_ZEND_LDAP_USE_START_TLS'))
  68. $options['useStartTls'] = TESTS_ZEND_LDAP_USE_START_TLS;
  69. if (defined('TESTS_ZEND_LDAP_USE_SSL'))
  70. $options['useSsl'] = TESTS_ZEND_LDAP_USE_SSL;
  71. if (defined('TESTS_ZEND_LDAP_BIND_REQUIRES_DN'))
  72. $options['bindRequiresDn'] = TESTS_ZEND_LDAP_BIND_REQUIRES_DN;
  73. if (defined('TESTS_ZEND_LDAP_ACCOUNT_FILTER_FORMAT'))
  74. $options['accountFilterFormat'] = TESTS_ZEND_LDAP_ACCOUNT_FILTER_FORMAT;
  75. if (defined('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME'))
  76. $options['accountDomainName'] = TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME;
  77. if (defined('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME_SHORT'))
  78. $options['accountDomainNameShort'] = TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME_SHORT;
  79. $this->_ldap=new Zend_Ldap($options);
  80. $this->_ldap->bind();
  81. }
  82. protected function tearDown()
  83. {
  84. if ($this->_ldap!==null) {
  85. $this->_ldap->disconnect();
  86. $this->_ldap=null;
  87. }
  88. }
  89. protected function _createDn($dn)
  90. {
  91. if (substr($dn, -1)!==',') {
  92. $dn.=',';
  93. }
  94. $dn = $dn . TESTS_ZEND_LDAP_WRITEABLE_SUBTREE;
  95. return Zend_Ldap_Dn::fromString($dn)->toString(Zend_Ldap_Dn::ATTR_CASEFOLD_LOWER);
  96. }
  97. protected function _prepareLdapServer()
  98. {
  99. $this->_nodes=array(
  100. $this->_createDn('ou=Node,') =>
  101. array("objectClass" => "organizationalUnit", "ou" => "Node"),
  102. $this->_createDn('ou=Test1,ou=Node,') =>
  103. array("objectClass" => "organizationalUnit", "ou" => "Test1"),
  104. $this->_createDn('ou=Test2,ou=Node,') =>
  105. array("objectClass" => "organizationalUnit", "ou" => "Test2"),
  106. $this->_createDn('ou=Test1,') =>
  107. array("objectClass" => "organizationalUnit", "ou" => "Test1", "l" => "e"),
  108. $this->_createDn('ou=Test2,') =>
  109. array("objectClass" => "organizationalUnit", "ou" => "Test2", "l" => "d"),
  110. $this->_createDn('ou=Test3,') =>
  111. array("objectClass" => "organizationalUnit", "ou" => "Test3", "l" => "c"),
  112. $this->_createDn('ou=Test4,') =>
  113. array("objectClass" => "organizationalUnit", "ou" => "Test4", "l" => "b"),
  114. $this->_createDn('ou=Test5,') =>
  115. array("objectClass" => "organizationalUnit", "ou" => "Test5", "l" => "a"),
  116. );
  117. $ldap=$this->_ldap->getResource();
  118. foreach ($this->_nodes as $dn => $entry) {
  119. ldap_add($ldap, $dn, $entry);
  120. }
  121. }
  122. protected function _cleanupLdapServer()
  123. {
  124. $ldap=$this->_ldap->getResource();
  125. foreach (array_reverse($this->_nodes) as $dn => $entry) {
  126. ldap_delete($ldap, $dn);
  127. }
  128. }
  129. }