OnlineTestCase.php 4.8 KB

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