ChildrenIterationTest.php 4.1 KB

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