SearchTest.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  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(__FILE__) . DIRECTORY_SEPARATOR . 'OnlineTestCase.php';
  26. /**
  27. * @see Zend_Ldap_Dn
  28. */
  29. require_once 'Zend/Ldap/Dn.php';
  30. /**
  31. * @see Zend_Ldap_Filter
  32. */
  33. require_once 'Zend/Ldap/Filter.php';
  34. /**
  35. * @category Zend
  36. * @package Zend_Ldap
  37. * @subpackage UnitTests
  38. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  39. * @license http://framework.zend.com/license/new-bsd New BSD License
  40. * @group Zend_Ldap
  41. */
  42. class Zend_Ldap_SearchTest extends Zend_Ldap_OnlineTestCase
  43. {
  44. protected function setUp()
  45. {
  46. parent::setUp();
  47. $this->_prepareLdapServer();
  48. }
  49. protected function tearDown()
  50. {
  51. $this->_cleanupLdapServer();
  52. parent::tearDown();
  53. }
  54. public function testGetSingleEntry()
  55. {
  56. $dn=$this->_createDn('ou=Test1,');
  57. $entry=$this->_getLdap()->getEntry($dn);
  58. $this->assertEquals($dn, $entry["dn"]);
  59. $this->assertArrayHasKey('ou', $entry);
  60. $this->assertContains('Test1', $entry['ou']);
  61. $this->assertEquals(1, count($entry['ou']));
  62. }
  63. public function testGetSingleIllegalEntry()
  64. {
  65. $dn=$this->_createDn('ou=Test99,');
  66. $entry=$this->_getLdap()->getEntry($dn);
  67. $this->assertNull($entry);
  68. }
  69. /**
  70. * @expectedException Zend_Ldap_Exception
  71. */
  72. public function testGetSingleIllegalEntryWithException()
  73. {
  74. $dn=$this->_createDn('ou=Test99,');
  75. $entry=$this->_getLdap()->getEntry($dn, array(), true);
  76. }
  77. public function testCountBase()
  78. {
  79. $dn=$this->_createDn('ou=Node,');
  80. $count=$this->_getLdap()->count('(objectClass=*)', $dn, Zend_Ldap::SEARCH_SCOPE_BASE);
  81. $this->assertEquals(1, $count);
  82. }
  83. public function testCountOne()
  84. {
  85. $dn1=$this->_createDn('ou=Node,');
  86. $count1=$this->_getLdap()->count('(objectClass=*)', $dn1, Zend_Ldap::SEARCH_SCOPE_ONE);
  87. $this->assertEquals(2, $count1);
  88. $dn2=TESTS_ZEND_LDAP_WRITEABLE_SUBTREE;
  89. $count2=$this->_getLdap()->count('(objectClass=*)', $dn2, Zend_Ldap::SEARCH_SCOPE_ONE);
  90. $this->assertEquals(6, $count2);
  91. }
  92. public function testCountSub()
  93. {
  94. $dn1=$this->_createDn('ou=Node,');
  95. $count1=$this->_getLdap()->count('(objectClass=*)', $dn1, Zend_Ldap::SEARCH_SCOPE_SUB);
  96. $this->assertEquals(3, $count1);
  97. $dn2=TESTS_ZEND_LDAP_WRITEABLE_SUBTREE;
  98. $count2=$this->_getLdap()->count('(objectClass=*)', $dn2, Zend_Ldap::SEARCH_SCOPE_SUB);
  99. $this->assertEquals(9, $count2);
  100. }
  101. public function testResultIteration()
  102. {
  103. $items=$this->_getLdap()->search('(objectClass=organizationalUnit)',
  104. TESTS_ZEND_LDAP_WRITEABLE_SUBTREE, Zend_Ldap::SEARCH_SCOPE_SUB);
  105. $this->assertEquals(9, $items->count());
  106. $this->assertEquals(9, count($items));
  107. $i=0;
  108. foreach ($items as $key => $item)
  109. {
  110. $this->assertEquals($i, $key);
  111. $i++;
  112. }
  113. $this->assertEquals(9, $i);
  114. $j=0;
  115. foreach ($items as $item) { $j++; }
  116. $this->assertEquals($i, $j);
  117. }
  118. public function testSearchNoResult()
  119. {
  120. $items=$this->_getLdap()->search('(objectClass=account)', TESTS_ZEND_LDAP_WRITEABLE_SUBTREE,
  121. Zend_Ldap::SEARCH_SCOPE_SUB);
  122. $this->assertEquals(0, $items->count());
  123. }
  124. public function testSearchEntriesShortcut()
  125. {
  126. $entries=$this->_getLdap()->searchEntries('(objectClass=organizationalUnit)',
  127. TESTS_ZEND_LDAP_WRITEABLE_SUBTREE, Zend_Ldap::SEARCH_SCOPE_SUB);
  128. $this->assertTrue(is_array($entries));
  129. $this->assertEquals(9, count($entries));
  130. }
  131. /**
  132. * @expectedException Zend_Ldap_Exception
  133. */
  134. public function testIllegalSearch()
  135. {
  136. $dn=$this->_createDn('ou=Node2,');
  137. $items=$this->_getLdap()->search('(objectClass=account)', $dn, Zend_Ldap::SEARCH_SCOPE_SUB);
  138. }
  139. public function testSearchNothingGetFirst()
  140. {
  141. $entries=$this->_getLdap()->search('(objectClass=account)', TESTS_ZEND_LDAP_WRITEABLE_SUBTREE,
  142. Zend_Ldap::SEARCH_SCOPE_SUB);
  143. $this->assertEquals(0, $entries->count());
  144. $this->assertNull($entries->getFirst());
  145. }
  146. public function testSorting()
  147. {
  148. $lSorted=array('a', 'b', 'c', 'd', 'e');
  149. $items=$this->_getLdap()->search('(l=*)', TESTS_ZEND_LDAP_WRITEABLE_SUBTREE,
  150. Zend_Ldap::SEARCH_SCOPE_SUB, array(), 'l');
  151. $this->assertEquals(5, $items->count());
  152. foreach ($items as $key => $item)
  153. {
  154. $this->assertEquals($lSorted[$key], $item['l'][0]);
  155. }
  156. }
  157. public function testCountChildren()
  158. {
  159. $dn1=$this->_createDn('ou=Node,');
  160. $count1=$this->_getLdap()->countChildren($dn1);
  161. $this->assertEquals(2, $count1);
  162. $dn2=TESTS_ZEND_LDAP_WRITEABLE_SUBTREE;
  163. $count2=$this->_getLdap()->countChildren($dn2);
  164. $this->assertEquals(6, $count2);
  165. }
  166. public function testExistsDn()
  167. {
  168. $dn1=$this->_createDn('ou=Test2,');
  169. $dn2=$this->_createDn('ou=Test99,');
  170. $this->assertTrue($this->_getLdap()->exists($dn1));
  171. $this->assertFalse($this->_getLdap()->exists($dn2));
  172. }
  173. public function testSearchWithDnObjectAndFilterObject()
  174. {
  175. $dn=Zend_Ldap_Dn::fromString(TESTS_ZEND_LDAP_WRITEABLE_SUBTREE);
  176. $filter=Zend_Ldap_Filter::equals('objectClass', 'organizationalUnit');
  177. $items=$this->_getLdap()->search($filter, $dn, Zend_Ldap::SEARCH_SCOPE_SUB);
  178. $this->assertEquals(9, $items->count());
  179. }
  180. public function testCountSubWithDnObjectAndFilterObject()
  181. {
  182. $dn1=Zend_Ldap_Dn::fromString($this->_createDn('ou=Node,'));
  183. $filter=Zend_Ldap_Filter::any('objectClass');
  184. $count1=$this->_getLdap()->count($filter, $dn1, Zend_Ldap::SEARCH_SCOPE_SUB);
  185. $this->assertEquals(3, $count1);
  186. $dn2=Zend_Ldap_Dn::fromString(TESTS_ZEND_LDAP_WRITEABLE_SUBTREE);
  187. $count2=$this->_getLdap()->count($filter, $dn2, Zend_Ldap::SEARCH_SCOPE_SUB);
  188. $this->assertEquals(9, $count2);
  189. }
  190. public function testCountChildrenWithDnObject()
  191. {
  192. $dn1=Zend_Ldap_Dn::fromString($this->_createDn('ou=Node,'));
  193. $count1=$this->_getLdap()->countChildren($dn1);
  194. $this->assertEquals(2, $count1);
  195. $dn2=Zend_Ldap_Dn::fromString(TESTS_ZEND_LDAP_WRITEABLE_SUBTREE);
  196. $count2=$this->_getLdap()->countChildren($dn2);
  197. $this->assertEquals(6, $count2);
  198. }
  199. public function testExistsDnWithDnObject()
  200. {
  201. $dn1=Zend_Ldap_Dn::fromString($this->_createDn('ou=Test2,'));
  202. $dn2=Zend_Ldap_Dn::fromString($this->_createDn('ou=Test99,'));
  203. $this->assertTrue($this->_getLdap()->exists($dn1));
  204. $this->assertFalse($this->_getLdap()->exists($dn2));
  205. }
  206. public function testSearchEntriesShortcutWithDnObjectAndFilterObject()
  207. {
  208. $dn=Zend_Ldap_Dn::fromString(TESTS_ZEND_LDAP_WRITEABLE_SUBTREE);
  209. $filter=Zend_Ldap_Filter::equals('objectClass', 'organizationalUnit');
  210. $entries=$this->_getLdap()->searchEntries($filter, $dn, Zend_Ldap::SEARCH_SCOPE_SUB);
  211. $this->assertTrue(is_array($entries));
  212. $this->assertEquals(9, count($entries));
  213. }
  214. public function testGetSingleEntryWithDnObject()
  215. {
  216. $dn=Zend_Ldap_Dn::fromString($this->_createDn('ou=Test1,'));
  217. $entry=$this->_getLdap()->getEntry($dn);
  218. $this->assertEquals($dn->toString(), $entry["dn"]);
  219. }
  220. public function testMultipleResultIteration()
  221. {
  222. $items=$this->_getLdap()->search('(objectClass=organizationalUnit)',
  223. TESTS_ZEND_LDAP_WRITEABLE_SUBTREE, Zend_Ldap::SEARCH_SCOPE_SUB);
  224. $isCount = 9;
  225. $this->assertEquals($isCount, $items->count());
  226. $i=0;
  227. foreach ($items as $key => $item)
  228. {
  229. $this->assertEquals($i, $key);
  230. $i++;
  231. }
  232. $this->assertEquals($isCount, $i);
  233. $i=0;
  234. foreach ($items as $key => $item)
  235. {
  236. $this->assertEquals($i, $key);
  237. $i++;
  238. }
  239. $this->assertEquals($isCount, $i);
  240. $items->close();
  241. $i=0;
  242. foreach ($items as $key => $item)
  243. {
  244. $this->assertEquals($i, $key);
  245. $i++;
  246. }
  247. $this->assertEquals($isCount, $i);
  248. $i=0;
  249. foreach ($items as $key => $item)
  250. {
  251. $this->assertEquals($i, $key);
  252. $i++;
  253. }
  254. $this->assertEquals($isCount, $i);
  255. }
  256. /**
  257. * Test issue reported by Lance Hendrix on
  258. * http://framework.zend.com/wiki/display/ZFPROP/Zend_Ldap+-+Extended+support+-+Stefan+Gehrig?
  259. * focusedCommentId=13107431#comment-13107431
  260. */
  261. public function testCallingNextAfterIterationShouldNotThrowException()
  262. {
  263. $items = $this->_getLdap()->search('(objectClass=organizationalUnit)',
  264. TESTS_ZEND_LDAP_WRITEABLE_SUBTREE, Zend_Ldap::SEARCH_SCOPE_SUB);
  265. foreach ($items as $key => $item) {
  266. // do nothing - just iterate
  267. }
  268. $items->next();
  269. }
  270. public function testUnknownCollectionClassThrowsException()
  271. {
  272. try {
  273. $items=$this->_getLdap()->search('(objectClass=organizationalUnit)',
  274. TESTS_ZEND_LDAP_WRITEABLE_SUBTREE, Zend_Ldap::SEARCH_SCOPE_SUB, array(), null,
  275. 'This_Class_Does_Not_Exist');
  276. $this->fail('Expected exception not thrown');
  277. } catch (Zend_Ldap_Exception $zle) {
  278. $this->assertContains("Class 'This_Class_Does_Not_Exist' can not be found",
  279. $zle->getMessage());
  280. }
  281. }
  282. public function testCollectionClassNotSubclassingZendLdapCollectionThrowsException()
  283. {
  284. try {
  285. $items=$this->_getLdap()->search('(objectClass=organizationalUnit)',
  286. TESTS_ZEND_LDAP_WRITEABLE_SUBTREE, Zend_Ldap::SEARCH_SCOPE_SUB, array(), null,
  287. 'Zend_Ldap_SearchTest_CollectionClassNotSubclassingZendLdapCollection');
  288. $this->fail('Expected exception not thrown');
  289. } catch (Zend_Ldap_Exception $zle) {
  290. $this->assertContains(
  291. "Class 'Zend_Ldap_SearchTest_CollectionClassNotSubclassingZendLdapCollection' must subclass 'Zend_Ldap_Collection'",
  292. $zle->getMessage());
  293. }
  294. }
  295. /**
  296. * @group ZF-8233
  297. */
  298. public function testSearchWithOptionsArray()
  299. {
  300. $items=$this->_getLdap()->search(array(
  301. 'filter' => '(objectClass=organizationalUnit)',
  302. 'baseDn' => TESTS_ZEND_LDAP_WRITEABLE_SUBTREE,
  303. 'scope' => Zend_Ldap::SEARCH_SCOPE_SUB
  304. ));
  305. $this->assertEquals(9, $items->count());
  306. }
  307. /**
  308. * @group ZF-8233
  309. */
  310. public function testSearchEntriesShortcutWithOptionsArray()
  311. {
  312. $items=$this->_getLdap()->searchEntries(array(
  313. 'filter' => '(objectClass=organizationalUnit)',
  314. 'baseDn' => TESTS_ZEND_LDAP_WRITEABLE_SUBTREE,
  315. 'scope' => Zend_Ldap::SEARCH_SCOPE_SUB
  316. ));
  317. $this->assertEquals(9, count($items));
  318. }
  319. /**
  320. * @group ZF-8233
  321. */
  322. public function testReverseSortingWithSearchEntriesShortcut()
  323. {
  324. $lSorted = array('e', 'd', 'c', 'b', 'a');
  325. $items = $this->_getLdap()->searchEntries('(l=*)', TESTS_ZEND_LDAP_WRITEABLE_SUBTREE,
  326. Zend_Ldap::SEARCH_SCOPE_SUB, array(), 'l', true);
  327. foreach ($items as $key => $item) {
  328. $this->assertEquals($lSorted[$key], $item['l'][0]);
  329. }
  330. }
  331. /**
  332. * @group ZF-8233
  333. */
  334. public function testReverseSortingWithSearchEntriesShortcutWithOptionsArray()
  335. {
  336. $lSorted = array('e', 'd', 'c', 'b', 'a');
  337. $items = $this->_getLdap()->searchEntries(array(
  338. 'filter' => '(l=*)',
  339. 'baseDn' => TESTS_ZEND_LDAP_WRITEABLE_SUBTREE,
  340. 'scope' => Zend_Ldap::SEARCH_SCOPE_SUB,
  341. 'sort' => 'l',
  342. 'reverseSort' => true
  343. ));
  344. foreach ($items as $key => $item) {
  345. $this->assertEquals($lSorted[$key], $item['l'][0]);
  346. }
  347. }
  348. public function testSearchNothingIteration()
  349. {
  350. $entries = $this->_getLdap()->search('(objectClass=account)',
  351. TESTS_ZEND_LDAP_WRITEABLE_SUBTREE, Zend_Ldap::SEARCH_SCOPE_SUB,
  352. array(), 'uid');
  353. $this->assertEquals(0, $entries->count());
  354. $i = 0;
  355. foreach ($entries as $key => $item) {
  356. $i++;
  357. }
  358. $this->assertEquals(0, $i);
  359. }
  360. public function testSearchNothingToArray()
  361. {
  362. $entries = $this->_getLdap()->search('(objectClass=account)',
  363. TESTS_ZEND_LDAP_WRITEABLE_SUBTREE, Zend_Ldap::SEARCH_SCOPE_SUB,
  364. array(), 'uid');
  365. $entries = $entries->toArray();
  366. $this->assertEquals(0, count($entries));
  367. $i = 0;
  368. foreach ($entries as $key => $item) {
  369. $i++;
  370. }
  371. $this->assertEquals(0, $i);
  372. }
  373. /**
  374. * @group ZF-8259
  375. */
  376. public function testUserIsAutomaticallyBoundOnOperationInDisconnectedState()
  377. {
  378. $ldap = $this->_getLdap();
  379. $ldap->disconnect();
  380. $dn = $this->_createDn('ou=Test1,');
  381. $entry = $ldap->getEntry($dn);
  382. $this->assertEquals($dn, $entry['dn']);
  383. }
  384. /**
  385. * @group ZF-8259
  386. */
  387. public function testUserIsAutomaticallyBoundOnOperationInUnboundState()
  388. {
  389. $ldap = $this->_getLdap();
  390. $ldap->disconnect();
  391. $ldap->connect();
  392. $dn = $this->_createDn('ou=Test1,');
  393. $entry = $ldap->getEntry($dn);
  394. $this->assertEquals($dn, $entry['dn']);
  395. }
  396. public function testInnerIteratorIsOfRequiredType()
  397. {
  398. $items = $this->_getLdap()->search('(objectClass=organizationalUnit)',
  399. TESTS_ZEND_LDAP_WRITEABLE_SUBTREE, Zend_Ldap::SEARCH_SCOPE_SUB);
  400. $this->assertTrue(
  401. $items->getInnerIterator() instanceof Zend_Ldap_Collection_Iterator_Default
  402. );
  403. }
  404. /**
  405. * @group ZF-8262
  406. */
  407. public function testCallingCurrentOnIteratorReturnsFirstElement()
  408. {
  409. $items = $this->_getLdap()->search('(objectClass=organizationalUnit)',
  410. TESTS_ZEND_LDAP_WRITEABLE_SUBTREE, Zend_Ldap::SEARCH_SCOPE_SUB);
  411. $this->assertEquals(TESTS_ZEND_LDAP_WRITEABLE_SUBTREE, $items->getInnerIterator()->key());
  412. $current = $items->getInnerIterator()->current();
  413. $this->assertTrue(is_array($current));
  414. $this->assertEquals(TESTS_ZEND_LDAP_WRITEABLE_SUBTREE, $current['dn']);
  415. }
  416. /**
  417. * @group ZF-8262
  418. */
  419. public function testCallingCurrentOnCollectionReturnsFirstElement()
  420. {
  421. $items = $this->_getLdap()->search('(objectClass=organizationalUnit)',
  422. TESTS_ZEND_LDAP_WRITEABLE_SUBTREE, Zend_Ldap::SEARCH_SCOPE_SUB);
  423. $this->assertEquals(0, $items->key());
  424. $this->assertEquals(TESTS_ZEND_LDAP_WRITEABLE_SUBTREE, $items->dn());
  425. $current = $items->current();
  426. $this->assertTrue(is_array($current));
  427. $this->assertEquals(TESTS_ZEND_LDAP_WRITEABLE_SUBTREE, $current['dn']);
  428. }
  429. /**
  430. * @group ZF-8262
  431. */
  432. public function testCallingCurrentOnEmptyIteratorReturnsNull()
  433. {
  434. $items = $this->_getLdap()->search('(objectClass=account)', TESTS_ZEND_LDAP_WRITEABLE_SUBTREE,
  435. Zend_Ldap::SEARCH_SCOPE_SUB);
  436. $this->assertNull($items->getInnerIterator()->key());
  437. $this->assertNull($items->getInnerIterator()->current());
  438. }
  439. /**
  440. * @group ZF-8262
  441. */
  442. public function testCallingCurrentOnEmptyCollectionReturnsNull()
  443. {
  444. $items = $this->_getLdap()->search('(objectClass=account)', TESTS_ZEND_LDAP_WRITEABLE_SUBTREE,
  445. Zend_Ldap::SEARCH_SCOPE_SUB);
  446. $this->assertNull($items->key());
  447. $this->assertNull($items->dn());
  448. $this->assertNull($items->current());
  449. }
  450. /**
  451. * @group ZF-8262
  452. */
  453. public function testResultIterationAfterCallingCurrent()
  454. {
  455. $items = $this->_getLdap()->search('(objectClass=organizationalUnit)',
  456. TESTS_ZEND_LDAP_WRITEABLE_SUBTREE, Zend_Ldap::SEARCH_SCOPE_SUB);
  457. $this->assertEquals(9, $items->count());
  458. $this->assertEquals(TESTS_ZEND_LDAP_WRITEABLE_SUBTREE, $items->getInnerIterator()->key());
  459. $current = $items->current();
  460. $this->assertTrue(is_array($current));
  461. $this->assertEquals(TESTS_ZEND_LDAP_WRITEABLE_SUBTREE, $current['dn']);
  462. $i=0;
  463. foreach ($items as $key => $item)
  464. {
  465. $this->assertEquals($i, $key);
  466. $i++;
  467. }
  468. $this->assertEquals(9, $i);
  469. $j=0;
  470. foreach ($items as $item) { $j++; }
  471. $this->assertEquals($i, $j);
  472. }
  473. /**
  474. * @group ZF-8263
  475. */
  476. public function testAttributeNameTreatmentToLower()
  477. {
  478. $dn = $this->_createDn('ou=Node,');
  479. $list = $this->_getLdap()->search('objectClass=*', $dn, Zend_Ldap::SEARCH_SCOPE_BASE);
  480. $list->getInnerIterator()->setAttributeNameTreatment(Zend_Ldap_Collection_Iterator_Default::ATTRIBUTE_TO_LOWER);
  481. $this->assertArrayHasKey('postalcode', $list->current());
  482. }
  483. /**
  484. * @group ZF-8263
  485. */
  486. public function testAttributeNameTreatmentToUpper()
  487. {
  488. $dn = $this->_createDn('ou=Node,');
  489. $list = $this->_getLdap()->search('objectClass=*', $dn, Zend_Ldap::SEARCH_SCOPE_BASE);
  490. $list->getInnerIterator()->setAttributeNameTreatment(Zend_Ldap_Collection_Iterator_Default::ATTRIBUTE_TO_UPPER);
  491. $this->assertArrayHasKey('POSTALCODE', $list->current());
  492. }
  493. /**
  494. * @group ZF-8263
  495. */
  496. public function testAttributeNameTreatmentNative()
  497. {
  498. $dn = $this->_createDn('ou=Node,');
  499. $list = $this->_getLdap()->search('objectClass=*', $dn, Zend_Ldap::SEARCH_SCOPE_BASE);
  500. $list->getInnerIterator()->setAttributeNameTreatment(Zend_Ldap_Collection_Iterator_Default::ATTRIBUTE_NATIVE);
  501. $this->assertArrayHasKey('postalCode', $list->current());
  502. }
  503. /**
  504. * @group ZF-8263
  505. */
  506. public function testAttributeNameTreatmentCustomFunction()
  507. {
  508. $dn = $this->_createDn('ou=Node,');
  509. $list = $this->_getLdap()->search('objectClass=*', $dn, Zend_Ldap::SEARCH_SCOPE_BASE);
  510. $list->getInnerIterator()->setAttributeNameTreatment('Zend_Ldap_SearchTest_customNaming');
  511. $this->assertArrayHasKey('EDOCLATSOP', $list->current());
  512. }
  513. /**
  514. * @group ZF-8263
  515. */
  516. public function testAttributeNameTreatmentCustomStaticMethod()
  517. {
  518. $dn = $this->_createDn('ou=Node,');
  519. $list = $this->_getLdap()->search('objectClass=*', $dn, Zend_Ldap::SEARCH_SCOPE_BASE);
  520. $list->getInnerIterator()->setAttributeNameTreatment(array('Zend_Ldap_SearchTest_CustomNaming', 'name1'));
  521. $this->assertArrayHasKey('edoclatsop', $list->current());
  522. }
  523. /**
  524. * @group ZF-8263
  525. */
  526. public function testAttributeNameTreatmentCustomInstanceMethod()
  527. {
  528. $dn = $this->_createDn('ou=Node,');
  529. $list = $this->_getLdap()->search('objectClass=*', $dn, Zend_Ldap::SEARCH_SCOPE_BASE);
  530. $namer = new Zend_Ldap_SearchTest_CustomNaming();
  531. $list->getInnerIterator()->setAttributeNameTreatment(array($namer, 'name2'));
  532. $this->assertArrayHasKey('edoClatsop', $list->current());
  533. }
  534. }
  535. function Zend_Ldap_SearchTest_customNaming($attrib)
  536. {
  537. return strtoupper(strrev($attrib));
  538. }
  539. class Zend_Ldap_SearchTest_CustomNaming
  540. {
  541. public static function name1($attrib)
  542. {
  543. return strtolower(strrev($attrib));
  544. }
  545. public function name2($attrib)
  546. {
  547. return strrev($attrib);
  548. }
  549. }
  550. class Zend_Ldap_SearchTest_CollectionClassNotSubclassingZendLdapCollection
  551. { }