PageRenderTime 51ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/Zend/Ldap/SearchTest.php

https://bitbucket.org/svenax/zendframework
PHP | 611 lines | 449 code | 62 blank | 100 comment | 0 complexity | da7206de20c4e5226004bfd0c5b7d6da MD5 | raw file
  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-2011 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-2011 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->assertType("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->assertType("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->assertType('Zend_Ldap_Collection_Iterator_Default', $items->getInnerIterator());
  401. }
  402. /**
  403. * @group ZF-8262
  404. */
  405. public function testCallingCurrentOnIteratorReturnsFirstElement()
  406. {
  407. $items = $this->_getLdap()->search('(objectClass=organizationalUnit)',
  408. TESTS_ZEND_LDAP_WRITEABLE_SUBTREE, Zend_Ldap::SEARCH_SCOPE_SUB);
  409. $this->assertEquals(TESTS_ZEND_LDAP_WRITEABLE_SUBTREE, $items->getInnerIterator()->key());
  410. $current = $items->getInnerIterator()->current();
  411. $this->assertType('array', $current);
  412. $this->assertEquals(TESTS_ZEND_LDAP_WRITEABLE_SUBTREE, $current['dn']);
  413. }
  414. /**
  415. * @group ZF-8262
  416. */
  417. public function testCallingCurrentOnCollectionReturnsFirstElement()
  418. {
  419. $items = $this->_getLdap()->search('(objectClass=organizationalUnit)',
  420. TESTS_ZEND_LDAP_WRITEABLE_SUBTREE, Zend_Ldap::SEARCH_SCOPE_SUB);
  421. $this->assertEquals(0, $items->key());
  422. $this->assertEquals(TESTS_ZEND_LDAP_WRITEABLE_SUBTREE, $items->dn());
  423. $current = $items->current();
  424. $this->assertType('array', $current);
  425. $this->assertEquals(TESTS_ZEND_LDAP_WRITEABLE_SUBTREE, $current['dn']);
  426. }
  427. /**
  428. * @group ZF-8262
  429. */
  430. public function testCallingCurrentOnEmptyIteratorReturnsNull()
  431. {
  432. $items = $this->_getLdap()->search('(objectClass=account)', TESTS_ZEND_LDAP_WRITEABLE_SUBTREE,
  433. Zend_Ldap::SEARCH_SCOPE_SUB);
  434. $this->assertNull($items->getInnerIterator()->key());
  435. $this->assertNull($items->getInnerIterator()->current());
  436. }
  437. /**
  438. * @group ZF-8262
  439. */
  440. public function testCallingCurrentOnEmptyCollectionReturnsNull()
  441. {
  442. $items = $this->_getLdap()->search('(objectClass=account)', TESTS_ZEND_LDAP_WRITEABLE_SUBTREE,
  443. Zend_Ldap::SEARCH_SCOPE_SUB);
  444. $this->assertNull($items->key());
  445. $this->assertNull($items->dn());
  446. $this->assertNull($items->current());
  447. }
  448. /**
  449. * @group ZF-8262
  450. */
  451. public function testResultIterationAfterCallingCurrent()
  452. {
  453. $items = $this->_getLdap()->search('(objectClass=organizationalUnit)',
  454. TESTS_ZEND_LDAP_WRITEABLE_SUBTREE, Zend_Ldap::SEARCH_SCOPE_SUB);
  455. $this->assertEquals(9, $items->count());
  456. $this->assertEquals(TESTS_ZEND_LDAP_WRITEABLE_SUBTREE, $items->getInnerIterator()->key());
  457. $current = $items->current();
  458. $this->assertType('array', $current);
  459. $this->assertEquals(TESTS_ZEND_LDAP_WRITEABLE_SUBTREE, $current['dn']);
  460. $i=0;
  461. foreach ($items as $key => $item)
  462. {
  463. $this->assertEquals($i, $key);
  464. $i++;
  465. }
  466. $this->assertEquals(9, $i);
  467. $j=0;
  468. foreach ($items as $item) { $j++; }
  469. $this->assertEquals($i, $j);
  470. }
  471. /**
  472. * @group ZF-8263
  473. */
  474. public function testAttributeNameTreatmentToLower()
  475. {
  476. $dn = $this->_createDn('ou=Node,');
  477. $list = $this->_getLdap()->search('objectClass=*', $dn, Zend_Ldap::SEARCH_SCOPE_BASE);
  478. $list->getInnerIterator()->setAttributeNameTreatment(Zend_Ldap_Collection_Iterator_Default::ATTRIBUTE_TO_LOWER);
  479. $this->assertArrayHasKey('postalcode', $list->current());
  480. }
  481. /**
  482. * @group ZF-8263
  483. */
  484. public function testAttributeNameTreatmentToUpper()
  485. {
  486. $dn = $this->_createDn('ou=Node,');
  487. $list = $this->_getLdap()->search('objectClass=*', $dn, Zend_Ldap::SEARCH_SCOPE_BASE);
  488. $list->getInnerIterator()->setAttributeNameTreatment(Zend_Ldap_Collection_Iterator_Default::ATTRIBUTE_TO_UPPER);
  489. $this->assertArrayHasKey('POSTALCODE', $list->current());
  490. }
  491. /**
  492. * @group ZF-8263
  493. */
  494. public function testAttributeNameTreatmentNative()
  495. {
  496. $dn = $this->_createDn('ou=Node,');
  497. $list = $this->_getLdap()->search('objectClass=*', $dn, Zend_Ldap::SEARCH_SCOPE_BASE);
  498. $list->getInnerIterator()->setAttributeNameTreatment(Zend_Ldap_Collection_Iterator_Default::ATTRIBUTE_NATIVE);
  499. $this->assertArrayHasKey('postalCode', $list->current());
  500. }
  501. /**
  502. * @group ZF-8263
  503. */
  504. public function testAttributeNameTreatmentCustomFunction()
  505. {
  506. $dn = $this->_createDn('ou=Node,');
  507. $list = $this->_getLdap()->search('objectClass=*', $dn, Zend_Ldap::SEARCH_SCOPE_BASE);
  508. $list->getInnerIterator()->setAttributeNameTreatment('Zend_Ldap_SearchTest_customNaming');
  509. $this->assertArrayHasKey('EDOCLATSOP', $list->current());
  510. }
  511. /**
  512. * @group ZF-8263
  513. */
  514. public function testAttributeNameTreatmentCustomStaticMethod()
  515. {
  516. $dn = $this->_createDn('ou=Node,');
  517. $list = $this->_getLdap()->search('objectClass=*', $dn, Zend_Ldap::SEARCH_SCOPE_BASE);
  518. $list->getInnerIterator()->setAttributeNameTreatment(array('Zend_Ldap_SearchTest_CustomNaming', 'name1'));
  519. $this->assertArrayHasKey('edoclatsop', $list->current());
  520. }
  521. /**
  522. * @group ZF-8263
  523. */
  524. public function testAttributeNameTreatmentCustomInstanceMethod()
  525. {
  526. $dn = $this->_createDn('ou=Node,');
  527. $list = $this->_getLdap()->search('objectClass=*', $dn, Zend_Ldap::SEARCH_SCOPE_BASE);
  528. $namer = new Zend_Ldap_SearchTest_CustomNaming();
  529. $list->getInnerIterator()->setAttributeNameTreatment(array($namer, 'name2'));
  530. $this->assertArrayHasKey('edoClatsop', $list->current());
  531. }
  532. }
  533. function Zend_Ldap_SearchTest_customNaming($attrib)
  534. {
  535. return strtoupper(strrev($attrib));
  536. }
  537. class Zend_Ldap_SearchTest_CustomNaming
  538. {
  539. public static function name1($attrib)
  540. {
  541. return strtolower(strrev($attrib));
  542. }
  543. public function name2($attrib)
  544. {
  545. return strrev($attrib);
  546. }
  547. }
  548. class Zend_Ldap_SearchTest_CollectionClassNotSubclassingZendLdapCollection
  549. { }