RootDseTest.php 7.5 KB

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