2
0

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->assertType('boolean', $root->supportsSaslMechanism('GSSAPI'));
  48. $this->assertType('boolean', $root->supportsSaslMechanism(array('GSSAPI', 'DIGEST-MD5')));
  49. $this->assertType('boolean', $root->supportsVersion('3'));
  50. $this->assertType('boolean', $root->supportsVersion(3));
  51. $this->assertType('boolean', $root->supportsVersion(array('3', '2')));
  52. $this->assertType('boolean', $root->supportsVersion(array(3, 2)));
  53. switch ($root->getServerType()) {
  54. case Zend_Ldap_Node_RootDse::SERVER_TYPE_ACTIVEDIRECTORY:
  55. $this->assertType('boolean', $root->supportsControl('1.2.840.113556.1.4.319'));
  56. $this->assertType('boolean', $root->supportsControl(array('1.2.840.113556.1.4.319',
  57. '1.2.840.113556.1.4.473')));
  58. $this->assertType('boolean', $root->supportsCapability('1.3.6.1.4.1.4203.1.9.1.1'));
  59. $this->assertType('boolean', $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->assertType('boolean', $root->supportsPolicy('unknown'));
  62. $this->assertType('boolean', $root->supportsPolicy(array('unknown', 'unknown')));
  63. break;
  64. case Zend_Ldap_Node_RootDse::SERVER_TYPE_EDIRECTORY:
  65. $this->assertType('boolean', $root->supportsExtension('1.3.6.1.4.1.1466.20037'));
  66. $this->assertType('boolean', $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->assertType('boolean', $root->supportsControl('1.3.6.1.4.1.4203.1.9.1.1'));
  71. $this->assertType('boolean', $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->assertType('boolean', $root->supportsExtension('1.3.6.1.4.1.1466.20037'));
  74. $this->assertType('boolean', $root->supportsExtension(array('1.3.6.1.4.1.1466.20037',
  75. '1.3.6.1.4.1.4203.1.11.1')));
  76. $this->assertType('boolean', $root->supportsFeature('1.3.6.1.1.14'));
  77. $this->assertType('boolean', $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->assertType('array', $root->getNamingContexts());
  86. $this->assertType('string', $root->getSubschemaSubentry());
  87. switch ($root->getServerType()) {
  88. case Zend_Ldap_Node_RootDse::SERVER_TYPE_ACTIVEDIRECTORY:
  89. $this->assertType('string', $root->getConfigurationNamingContext());
  90. $this->assertType('string', $root->getCurrentTime());
  91. $this->assertType('string', $root->getDefaultNamingContext());
  92. $this->assertType('string', $root->getDnsHostName());
  93. $this->assertType('string', $root->getDomainControllerFunctionality());
  94. $this->assertType('string', $root->getDomainFunctionality());
  95. $this->assertType('string', $root->getDsServiceName());
  96. $this->assertType('string', $root->getForestFunctionality());
  97. $this->assertType('string', $root->getHighestCommittedUSN());
  98. $this->assertType('boolean', $root->getIsGlobalCatalogReady());
  99. $this->assertType('boolean', $root->getIsSynchronized());
  100. $this->assertType('string', $root->getLdapServiceName());
  101. $this->assertType('string', $root->getRootDomainNamingContext());
  102. $this->assertType('string', $root->getSchemaNamingContext());
  103. $this->assertType('string', $root->getServerName());
  104. break;
  105. case Zend_Ldap_Node_RootDse::SERVER_TYPE_EDIRECTORY:
  106. $this->assertType('string', $root->getVendorName());
  107. $this->assertType('string', $root->getVendorVersion());
  108. $this->assertType('string', $root->getDsaName());
  109. $this->assertType('string', $root->getStatisticsErrors());
  110. $this->assertType('string', $root->getStatisticsSecurityErrors());
  111. $this->assertType('string', $root->getStatisticsChainings());
  112. $this->assertType('string', $root->getStatisticsReferralsReturned());
  113. $this->assertType('string', $root->getStatisticsExtendedOps());
  114. $this->assertType('string', $root->getStatisticsAbandonOps());
  115. $this->assertType('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->assertType('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. }