RootDseTest.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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-2012 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_OnlineTestCase
  24. */
  25. require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'OnlineTestCase.php';
  26. /**
  27. * @category Zend
  28. * @package Zend_Ldap
  29. * @subpackage UnitTests
  30. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. * @group Zend_Ldap
  33. * @group Zend_Ldap_Node
  34. */
  35. class Zend_Ldap_Node_RootDseTest extends Zend_Ldap_OnlineTestCase
  36. {
  37. public function testLoadRootDseNode()
  38. {
  39. $root1=$this->_getLdap()->getRootDse();
  40. $root2=$this->_getLdap()->getRootDse();
  41. $this->assertEquals($root1, $root2);
  42. $this->assertSame($root1, $root2);
  43. }
  44. public function testSupportCheckMethods()
  45. {
  46. $root=$this->_getLdap()->getRootDse();
  47. $this->assertTrue(is_bool($root->supportsSaslMechanism('GSSAPI')));
  48. $this->assertTrue(is_bool($root->supportsSaslMechanism(array('GSSAPI', 'DIGEST-MD5'))));
  49. $this->assertTrue(is_bool($root->supportsVersion('3')));
  50. $this->assertTrue(is_bool($root->supportsVersion(3)));
  51. $this->assertTrue(is_bool($root->supportsVersion(array('3', '2'))));
  52. $this->assertTrue(is_bool($root->supportsVersion(array(3, 2))));
  53. switch ($root->getServerType()) {
  54. case Zend_Ldap_Node_RootDse::SERVER_TYPE_ACTIVEDIRECTORY:
  55. $this->assertTrue(is_bool($root->supportsControl('1.2.840.113556.1.4.319')));
  56. $this->assertTrue(is_bool($root->supportsControl(array('1.2.840.113556.1.4.319',
  57. '1.2.840.113556.1.4.473'))));
  58. $this->assertTrue(is_bool($root->supportsCapability('1.3.6.1.4.1.4203.1.9.1.1')));
  59. $this->assertTrue(is_bool($root->supportsCapability(array('1.3.6.1.4.1.4203.1.9.1.1',
  60. '2.16.840.1.113730.3.4.18'))));
  61. $this->assertTrue(is_bool($root->supportsPolicy('unknown')));
  62. $this->assertTrue(is_bool($root->supportsPolicy(array('unknown', 'unknown'))));
  63. break;
  64. case Zend_Ldap_Node_RootDse::SERVER_TYPE_EDIRECTORY:
  65. $this->assertTrue(is_bool($root->supportsExtension('1.3.6.1.4.1.1466.20037')));
  66. $this->assertTrue(is_bool($root->supportsExtension(array('1.3.6.1.4.1.1466.20037',
  67. '1.3.6.1.4.1.4203.1.11.1'))));
  68. break;
  69. case Zend_Ldap_Node_RootDse::SERVER_TYPE_OPENLDAP:
  70. $this->assertTrue(is_bool($root->supportsControl('1.3.6.1.4.1.4203.1.9.1.1')));
  71. $this->assertTrue(is_bool($root->supportsControl(array('1.3.6.1.4.1.4203.1.9.1.1',
  72. '2.16.840.1.113730.3.4.18'))));
  73. $this->assertTrue(is_bool($root->supportsExtension('1.3.6.1.4.1.1466.20037')));
  74. $this->assertTrue(is_bool($root->supportsExtension(array('1.3.6.1.4.1.1466.20037',
  75. '1.3.6.1.4.1.4203.1.11.1'))));
  76. $this->assertTrue(is_bool($root->supportsFeature('1.3.6.1.1.14')));
  77. $this->assertTrue(is_bool($root->supportsFeature(array('1.3.6.1.1.14',
  78. '1.3.6.1.4.1.4203.1.5.1'))));
  79. break;
  80. }
  81. }
  82. public function testGetters()
  83. {
  84. $root=$this->_getLdap()->getRootDse();
  85. $this->assertTrue(is_array($root->getNamingContexts()));
  86. $this->assertTrue(is_array($root->getSubschemaSubentry()));
  87. switch ($root->getServerType()) {
  88. case Zend_Ldap_Node_RootDse::SERVER_TYPE_ACTIVEDIRECTORY:
  89. $this->assertTrue(is_string($root->getConfigurationNamingContext()));
  90. $this->assertTrue(is_string($root->getCurrentTime()));
  91. $this->assertTrue(is_string($root->getDefaultNamingContext()));
  92. $this->assertTrue(is_string($root->getDnsHostName()));
  93. $this->assertTrue(is_string($root->getDomainControllerFunctionality()));
  94. $this->assertTrue(is_string($root->getDomainFunctionality()));
  95. $this->assertTrue(is_string($root->getDsServiceName()));
  96. $this->assertTrue(is_string($root->getForestFunctionality()));
  97. $this->assertTrue(is_string($root->getHighestCommittedUSN()));
  98. $this->assertTrue(is_bool($root->getIsGlobalCatalogReady()));
  99. $this->assertTrue(is_bool($root->getIsSynchronized()));
  100. $this->assertTrue(is_string($root->getLdapServiceName()));
  101. $this->assertTrue(is_string($root->getRootDomainNamingContext()));
  102. $this->assertTrue(is_string($root->getSchemaNamingContext()));
  103. $this->assertTrue(is_string($root->getServerName()));
  104. break;
  105. case Zend_Ldap_Node_RootDse::SERVER_TYPE_EDIRECTORY:
  106. $this->assertTrue(is_string($root->getVendorName()));
  107. $this->assertTrue(is_string($root->getVendorVersion()));
  108. $this->assertTrue(is_string($root->getDsaName()));
  109. $this->assertTrue(is_string($root->getStatisticsErrors()));
  110. $this->assertTrue(is_string($root->getStatisticsSecurityErrors()));
  111. $this->assertTrue(is_string($root->getStatisticsChainings()));
  112. $this->assertTrue(is_string($root->getStatisticsReferralsReturned()));
  113. $this->assertTrue(is_string($root->getStatisticsExtendedOps()));
  114. $this->assertTrue(is_string($root->getStatisticsAbandonOps()));
  115. $this->assertTrue(is_string($root->getStatisticsWholeSubtreeSearchOps()));
  116. break;
  117. case Zend_Ldap_Node_RootDse::SERVER_TYPE_OPENLDAP:
  118. $this->_assertNullOrString($root->getConfigContext());
  119. $this->_assertNullOrString($root->getMonitorContext());
  120. break;
  121. }
  122. }
  123. protected function _assertNullOrString($value)
  124. {
  125. if ($value===null) {
  126. $this->assertNull($value);
  127. } else {
  128. $this->assertTrue(is_string($value));
  129. }
  130. }
  131. /**
  132. * @expectedException BadMethodCallException
  133. */
  134. public function testSetterWillThrowException()
  135. {
  136. $root=$this->_getLdap()->getRootDse();
  137. $root->objectClass='illegal';
  138. }
  139. /**
  140. * @expectedException BadMethodCallException
  141. */
  142. public function testOffsetSetWillThrowException()
  143. {
  144. $root=$this->_getLdap()->getRootDse();
  145. $root['objectClass']='illegal';
  146. }
  147. /**
  148. * @expectedException BadMethodCallException
  149. */
  150. public function testUnsetterWillThrowException()
  151. {
  152. $root=$this->_getLdap()->getRootDse();
  153. unset($root->objectClass);
  154. }
  155. /**
  156. * @expectedException BadMethodCallException
  157. */
  158. public function testOffsetUnsetWillThrowException()
  159. {
  160. $root=$this->_getLdap()->getRootDse();
  161. unset($root['objectClass']);
  162. }
  163. }