ChildrenIterationTest.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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_OnlineTestCase
  24. */
  25. require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'OnlineTestCase.php';
  26. /**
  27. * @see Zend_Ldap_Node
  28. */
  29. require_once 'Zend/Ldap/Node.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. * @group Zend_Ldap_Node
  38. */
  39. class Zend_Ldap_Node_ChildrenIterationTest extends Zend_Ldap_OnlineTestCase
  40. {
  41. protected function setUp()
  42. {
  43. parent::setUp();
  44. $this->_prepareLdapServer();
  45. }
  46. protected function tearDown()
  47. {
  48. $this->_cleanupLdapServer();
  49. parent::tearDown();
  50. }
  51. public function testSimpleIteration()
  52. {
  53. $node=$this->_getLdap()->getBaseNode();
  54. $children=$node->getChildren();
  55. $i=1;
  56. foreach ($children as $rdn => $n) {
  57. $dn=$n->getDn()->toString(Zend_Ldap_Dn::ATTR_CASEFOLD_LOWER);
  58. $rdn=Zend_Ldap_Dn::implodeRdn($n->getRdnArray(), Zend_Ldap_Dn::ATTR_CASEFOLD_LOWER);
  59. if ($i==1) {
  60. $this->assertEquals('ou=Node', $rdn);
  61. $this->assertEquals($this->_createDn('ou=Node,'), $dn);
  62. }
  63. else {
  64. $this->assertEquals('ou=Test' . ($i-1), $rdn);
  65. $this->assertEquals($this->_createDn('ou=Test' . ($i-1) . ','), $dn);
  66. }
  67. $i++;
  68. }
  69. $this->assertEquals(6, $i-1);
  70. }
  71. public function testSimpleRecursiveIteration()
  72. {
  73. $node=$this->_getLdap()->getBaseNode();
  74. $ri=new RecursiveIteratorIterator($node, RecursiveIteratorIterator::SELF_FIRST);
  75. $i=0;
  76. foreach ($ri as $rdn => $n) {
  77. $dn=$n->getDn()->toString(Zend_Ldap_Dn::ATTR_CASEFOLD_LOWER);
  78. $rdn=Zend_Ldap_Dn::implodeRdn($n->getRdnArray(), Zend_Ldap_Dn::ATTR_CASEFOLD_LOWER);
  79. if ($i==0) {
  80. $this->assertEquals(Zend_Ldap_Dn::fromString(TESTS_ZEND_LDAP_WRITEABLE_SUBTREE)
  81. ->toString(Zend_Ldap_Dn::ATTR_CASEFOLD_LOWER), $dn);
  82. }
  83. else if ($i==1) {
  84. $this->assertEquals('ou=Node', $rdn);
  85. $this->assertEquals($this->_createDn('ou=Node,'), $dn);
  86. }
  87. else {
  88. if ($i<4) {
  89. $j=$i-1;
  90. $base=$this->_createDn('ou=Node,');
  91. }
  92. else {
  93. $j=$i-3;
  94. $base=Zend_Ldap_Dn::fromString(TESTS_ZEND_LDAP_WRITEABLE_SUBTREE)
  95. ->toString(Zend_Ldap_Dn::ATTR_CASEFOLD_LOWER);
  96. }
  97. $this->assertEquals('ou=Test' . $j, $rdn);
  98. $this->assertEquals('ou=Test' . $j . ',' . $base, $dn);
  99. }
  100. $i++;
  101. }
  102. $this->assertEquals(9, $i);
  103. }
  104. /**
  105. * Test issue reported by Lance Hendrix on
  106. * http://framework.zend.com/wiki/display/ZFPROP/Zend_Ldap+-+Extended+support+-+Stefan+Gehrig?
  107. * focusedCommentId=13107431#comment-13107431
  108. */
  109. public function testCallingNextAfterIterationShouldNotThrowException()
  110. {
  111. $node = $this->_getLdap()->getBaseNode();
  112. $nodes = $node->searchChildren('(objectClass=*)');
  113. foreach ($nodes as $rdn => $n) {
  114. // do nothing - just iterate
  115. }
  116. $nodes->next();
  117. }
  118. }