OfflineTest.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  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-2014 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_TestCase
  24. */
  25. require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'TestCase.php';
  26. /**
  27. * 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-2014 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_OfflineTest extends Zend_Ldap_TestCase
  40. {
  41. protected function _assertLocalDateTimeString($timestamp, $value)
  42. {
  43. $this->assertEquals(date('YmdHis\Z', $timestamp), $value);
  44. }
  45. protected function _assertUtcDateTimeString($localTimestamp, $value)
  46. {
  47. $localOffset = date('Z', $localTimestamp);
  48. $utcTimestamp = $localTimestamp - $localOffset;
  49. $this->assertEquals(date('YmdHis', $utcTimestamp) . 'Z', $value);
  50. }
  51. public function testCreateFromArrayStringDn()
  52. {
  53. $data=$this->_createTestArrayData();
  54. $node=Zend_Ldap_Node::fromArray($data);
  55. $this->assertTrue($node instanceof Zend_Ldap_Node);
  56. $this->assertFalse($node->isAttached());
  57. $this->assertFalse($node->willBeDeleted());
  58. $this->assertFalse($node->willBeMoved());
  59. $this->assertTrue($node->isNew());
  60. }
  61. public function testCreateFromArrayObjectDn()
  62. {
  63. $data=$this->_createTestArrayData();
  64. $data['dn']=Zend_Ldap_Dn::fromString($data['dn']);
  65. $node=Zend_Ldap_Node::fromArray($data);
  66. $this->assertTrue($node instanceof Zend_Ldap_Node);
  67. $this->assertFalse($node->isAttached());
  68. }
  69. /**
  70. * @expectedException Zend_Ldap_Exception
  71. */
  72. public function testCreateFromArrayMissingDn()
  73. {
  74. $data=$this->_createTestArrayData();
  75. unset($data['dn']);
  76. $node=Zend_Ldap_Node::fromArray($data);
  77. }
  78. /**
  79. * @expectedException Zend_Ldap_Exception
  80. */
  81. public function testCreateFromArrayIllegalDn()
  82. {
  83. $data=$this->_createTestArrayData();
  84. $data['dn']=5;
  85. $node=Zend_Ldap_Node::fromArray($data);
  86. }
  87. /**
  88. * @expectedException Zend_Ldap_Exception
  89. */
  90. public function testCreateFromArrayMalformedDn()
  91. {
  92. $data=$this->_createTestArrayData();
  93. $data['dn']='name1,cn=name2,dc=example,dc=org';
  94. $node=Zend_Ldap_Node::fromArray($data);
  95. }
  96. public function testCreateFromArrayAndEnsureRdnValues()
  97. {
  98. $data=$this->_createTestArrayData();
  99. $data['dn']=Zend_Ldap_Dn::fromString($data['dn']);
  100. $node=Zend_Ldap_Node::fromArray($data);
  101. $this->assertTrue($node instanceof Zend_Ldap_Node);
  102. $this->assertFalse($node->isAttached());
  103. unset($data['dn']);
  104. $this->assertEquals($data, $node->getData());
  105. }
  106. public function testGetDnString()
  107. {
  108. $data=$this->_createTestArrayData();
  109. $node=Zend_Ldap_Node::fromArray($data);
  110. $this->assertEquals($data['dn'], $node->getDnString());
  111. }
  112. public function testGetDnArray()
  113. {
  114. $data=$this->_createTestArrayData();
  115. $node=Zend_Ldap_Node::fromArray($data);
  116. $exA=Zend_Ldap_Dn::explodeDn($data['dn']);
  117. $this->assertEquals($exA, $node->getDnArray());
  118. }
  119. public function testGetDnObject()
  120. {
  121. $data=$this->_createTestArrayData();
  122. $node=Zend_Ldap_Node::fromArray($data);
  123. $compareDn=Zend_Ldap_Dn::fromString('cn=name,dc=example,dc=org');
  124. $this->assertEquals($compareDn, $node->getDn());
  125. $this->assertNotSame($node->getDn(), $node->getDn());
  126. }
  127. public function testGetRdnString()
  128. {
  129. $node=$this->_createTestNode();
  130. $this->assertEquals('cn=name', $node->getRdnString());
  131. }
  132. public function testGetRdnArray()
  133. {
  134. $node=$this->_createTestNode();
  135. $this->assertEquals(array('cn' => 'name'), $node->getRdnArray());
  136. }
  137. public function testSerialize()
  138. {
  139. $node=$this->_createTestNode();
  140. $sdata=serialize($node);
  141. $newObject=unserialize($sdata);
  142. $this->assertEquals($node, $newObject);
  143. }
  144. public function testToString()
  145. {
  146. $node=$this->_createTestNode();
  147. $this->assertEquals('cn=name,dc=example,dc=org', $node->toString());
  148. $this->assertEquals('cn=name,dc=example,dc=org', (string)$node);
  149. }
  150. public function testToArray()
  151. {
  152. $node=$this->_createTestNode();
  153. $this->assertEquals(array(
  154. 'dn' => 'cn=name,dc=example,dc=org',
  155. 'cn' => array('name'),
  156. 'host' => array('a', 'b', 'c'),
  157. 'empty' => array(),
  158. 'boolean' => array(true, false),
  159. 'objectclass' => array('account', 'top'),
  160. ), $node->toArray());
  161. }
  162. public function testToJson()
  163. {
  164. $node=$this->_createTestNode();
  165. $this->assertEquals('{"dn":"cn=name,dc=example,dc=org",' .
  166. '"boolean":[true,false],' .
  167. '"cn":["name"],' .
  168. '"empty":[],' .
  169. '"host":["a","b","c"],' .
  170. '"objectclass":["account","top"]}', $node->toJson());
  171. }
  172. public function testGetData()
  173. {
  174. $data=$this->_createTestArrayData();
  175. $node=Zend_Ldap_Node::fromArray($data);
  176. ksort($data, SORT_STRING);
  177. unset($data['dn']);
  178. $this->assertEquals($data, $node->getData());
  179. }
  180. public function testGetObjectClass()
  181. {
  182. $node=$this->_createTestNode();
  183. $this->assertEquals(array('account', 'top'), $node->getObjectClass());
  184. }
  185. public function testModifyObjectClass()
  186. {
  187. $node=$this->_createTestNode();
  188. $this->assertEquals(array('account', 'top'), $node->getObjectClass());
  189. $node->setObjectClass('domain');
  190. $this->assertEquals(array('domain'), $node->getObjectClass());
  191. $node->setObjectClass(array('account', 'top'));
  192. $this->assertEquals(array('account', 'top'), $node->getObjectClass());
  193. $node->appendObjectClass('domain');
  194. $this->assertEquals(array('account', 'top', 'domain'), $node->getObjectClass());
  195. $node->setObjectClass('domain');
  196. $node->appendObjectClass(array('account', 'top'));
  197. $this->assertEquals(array('domain', 'account', 'top'), $node->getObjectClass());
  198. }
  199. public function testGetAttributes()
  200. {
  201. $node=$this->_createTestNode();
  202. $expected=array(
  203. 'boolean' => array(true, false),
  204. 'cn' => array('name'),
  205. 'empty' => array(),
  206. 'host' => array('a', 'b', 'c'),
  207. 'objectclass' => array('account', 'top'),
  208. );
  209. $this->assertEquals($expected, $node->getAttributes());
  210. $this->assertFalse($node->willBeDeleted());
  211. $this->assertFalse($node->willBeMoved());
  212. $this->assertFalse($node->isNew());
  213. $node->delete();
  214. $this->assertTrue($node->willBeDeleted());
  215. }
  216. public function testAppendToAttributeFirstTime()
  217. {
  218. $node=$this->_createTestNode();
  219. $node->appendToAttribute('host', 'newHost');
  220. $ts=mktime(12, 30, 30, 6, 25, 2008);
  221. $node->appendToDateTimeAttribute('objectClass', $ts);
  222. $this->assertEquals('newHost', $node->host[3]);
  223. $this->assertEquals($ts, $node->getDateTimeAttribute('objectClass', 2));
  224. }
  225. public function testExistsAttribute()
  226. {
  227. $node=$this->_createTestNode();
  228. $this->assertFalse($node->existsAttribute('nonExistant'));
  229. $this->assertFalse($node->existsAttribute('empty', false));
  230. $this->assertTrue($node->existsAttribute('empty', true));
  231. $node->newEmpty=null;
  232. $this->assertFalse($node->existsAttribute('newEmpty', false));
  233. $this->assertTrue($node->existsAttribute('newEmpty', true));
  234. $node->empty='string';
  235. $this->assertTrue($node->existsAttribute('empty', false));
  236. $this->assertTrue($node->existsAttribute('empty', true));
  237. $node->deleteAttribute('empty');
  238. $this->assertFalse($node->existsAttribute('empty', false));
  239. $this->assertTrue($node->existsAttribute('empty', true));
  240. }
  241. public function testGetSetAndDeleteMethods()
  242. {
  243. $timezone = date_default_timezone_get();
  244. date_default_timezone_set('GMT');
  245. $node=$this->_createTestNode();
  246. $node->setAttribute('key', 'value1');
  247. $this->assertEquals('value1', $node->getAttribute('key', 0));
  248. $node->appendToAttribute('key', 'value2');
  249. $this->assertEquals('value1', $node->getAttribute('key', 0));
  250. $this->assertEquals('value2', $node->getAttribute('key', 1));
  251. $this->assertTrue($node->existsAttribute('key', true));
  252. $this->assertTrue($node->existsAttribute('key', false));
  253. $node->deleteAttribute('key');
  254. $this->assertEquals(0, count($node->getAttribute('key')));
  255. $this->assertTrue($node->existsAttribute('key', true));
  256. $this->assertFalse($node->existsAttribute('key', false));
  257. $ts=mktime(12, 30, 30, 6, 25, 2008);
  258. $node->setDateTimeAttribute('key', $ts, false);
  259. $this->_assertLocalDateTimeString($ts, $node->getAttribute('key', 0));
  260. $this->assertEquals($ts, $node->getDateTimeAttribute('key', 0));
  261. $node->appendToDateTimeAttribute('key', $ts, true);
  262. $this->_assertLocalDateTimeString($ts, $node->getAttribute('key', 0));
  263. $this->assertEquals($ts, $node->getDateTimeAttribute('key', 0));
  264. $this->_assertUtcDateTimeString($ts, $node->getAttribute('key', 1));
  265. $this->assertEquals($ts, $node->getDateTimeAttribute('key', 1));
  266. $this->assertTrue($node->existsAttribute('key', true));
  267. $this->assertTrue($node->existsAttribute('key', false));
  268. $node->deleteAttribute('key');
  269. $this->assertEquals(0, count($node->getAttribute('key')));
  270. $this->assertTrue($node->existsAttribute('key', true));
  271. $this->assertFalse($node->existsAttribute('key', false));
  272. $node->setPasswordAttribute('pa$$w0rd', Zend_Ldap_Attribute::PASSWORD_HASH_MD5);
  273. $this->assertEquals('{MD5}bJuLJ96h3bhF+WqiVnxnVA==', $node->getAttribute('userPassword', 0));
  274. $this->assertTrue($node->existsAttribute('userPassword', true));
  275. $this->assertTrue($node->existsAttribute('userPassword', false));
  276. $node->deleteAttribute('userPassword');
  277. $this->assertEquals(0, count($node->getAttribute('userPassword')));
  278. $this->assertTrue($node->existsAttribute('userPassword', true));
  279. $this->assertFalse($node->existsAttribute('userPassword', false));
  280. date_default_timezone_set($timezone);
  281. }
  282. public function testOverloading()
  283. {
  284. $node=$this->_createTestNode();
  285. $node->key='value1';
  286. $this->assertEquals('value1', $node->key[0]);
  287. $this->assertTrue(isset($node->key));
  288. unset($node->key);
  289. $this->assertEquals(0, count($node->key));
  290. $this->assertFalse(isset($node->key));
  291. }
  292. /**
  293. * @expectedException Zend_Ldap_Exception
  294. */
  295. public function testIllegalAttributeAccessRdnAttributeSet()
  296. {
  297. $node=$this->_createTestNode();
  298. $node->cn='test';
  299. }
  300. /**
  301. * @expectedException Zend_Ldap_Exception
  302. */
  303. public function testIllegalAttributeAccessDnSet()
  304. {
  305. $node=$this->_createTestNode();
  306. $node->dn='test';
  307. }
  308. public function testAttributeAccessDnGet()
  309. {
  310. $node=$this->_createTestNode();
  311. $this->assertTrue(is_string($node->dn));
  312. $this->assertEquals($node->getDn()->toString(), $node->dn);
  313. }
  314. public function testArrayAccess()
  315. {
  316. $node=$this->_createTestNode();
  317. $node['key']='value1';
  318. $this->assertEquals('value1', $node['key'][0]);
  319. $this->assertTrue(isset($node['key']));
  320. unset($node['key']);
  321. $this->assertEquals(0, count($node['key']));
  322. $this->assertFalse(isset($node['key']));
  323. }
  324. public function testCreateEmptyNode()
  325. {
  326. $dn='cn=name,dc=example,dc=org';
  327. $objectClass=array('account', 'test', 'inetOrgPerson');
  328. $node=Zend_Ldap_Node::create($dn, $objectClass);
  329. $this->assertEquals($dn, $node->getDnString());
  330. $this->assertEquals('cn=name', $node->getRdnString());
  331. $this->assertEquals('name', $node->cn[0]);
  332. $this->assertEquals($objectClass, $node->objectClass);
  333. $this->assertFalse($node->willBeDeleted());
  334. $this->assertFalse($node->willBeMoved());
  335. $this->assertTrue($node->isNew());
  336. $node->delete();
  337. $this->assertTrue($node->willBeDeleted());
  338. }
  339. public function testGetChangedData()
  340. {
  341. $node=$this->_createTestNode();
  342. $node->host=array('d');
  343. $node->empty='not Empty';
  344. unset($node->objectClass);
  345. $changedData=$node->getChangedData();
  346. $this->assertEquals(array('d'), $changedData['host']);
  347. $this->assertEquals(array('not Empty'), $changedData['empty']);
  348. $this->assertEquals(array(), $changedData['objectclass']);
  349. }
  350. public function testDeleteUnusedAttribute()
  351. {
  352. $node=$this->_createTestNode();
  353. $node->deleteAttribute('nonexistant');
  354. $changedData=$node->getChangedData();
  355. $this->assertArrayNotHasKey('nonexistant', $changedData);
  356. }
  357. public function testRenameNodeString()
  358. {
  359. $data=$this->_createTestArrayData();
  360. $node=Zend_Ldap_Node::fromArray($data);
  361. $newDnString='cn=test+ou=Lab+uid=tester,cn=name,dc=example,dc=org';
  362. $node->setDn($newDnString);
  363. $this->assertEquals($data['dn'], $node->getCurrentDn()->toString());
  364. $this->assertEquals($newDnString, $node->getDn()->toString());
  365. $this->assertEquals(array('test'), $node->cn);
  366. $this->assertEquals(array('tester'), $node->uid);
  367. $this->assertEquals(array('Lab'), $node->ou);
  368. $this->assertFalse($node->willBeDeleted());
  369. $this->assertFalse($node->willBeMoved());
  370. $this->assertTrue($node->isNew());
  371. }
  372. public function testRenameNodeArray()
  373. {
  374. $data=$this->_createTestArrayData();
  375. $node=Zend_Ldap_Node::fromArray($data);
  376. $newDnArray=array(
  377. array('uid' => 'tester'),
  378. array('dc' => 'example'),
  379. array('dc' => 'org'));
  380. $node->setDn($newDnArray);
  381. $this->assertEquals($data['dn'], $node->getCurrentDn()->toString());
  382. $this->assertEquals($newDnArray, $node->getDn()->toArray());
  383. $this->assertEquals(array('name'), $node->cn);
  384. }
  385. public function testRenameNodeDnObject()
  386. {
  387. $data=$this->_createTestArrayData();
  388. $node=Zend_Ldap_Node::fromArray($data);
  389. $newDn=Zend_Ldap_Dn::fromString('cn=test+ou=Lab+uid=tester,cn=name,dc=example,dc=org');
  390. $node->setDn($newDn);
  391. $this->assertEquals($data['dn'], $node->getCurrentDn()->toString());
  392. $this->assertEquals($newDn, $node->getDn());
  393. $this->assertEquals(array('test'), $node->cn);
  394. $this->assertEquals(array('tester'), $node->uid);
  395. $this->assertEquals(array('Lab'), $node->ou);
  396. }
  397. public function testRenameNodeFromDataSource()
  398. {
  399. $node=$this->_createTestNode();
  400. $newDnString='cn=test+ou=Lab+uid=tester,cn=name,dc=example,dc=org';
  401. $node->rename($newDnString);
  402. $this->assertFalse($node->willBeDeleted());
  403. $this->assertTrue($node->willBeMoved());
  404. $this->assertFalse($node->isNew());
  405. }
  406. public function testDnObjectCloning()
  407. {
  408. $node1=$this->_createTestNode();
  409. $dn1=Zend_Ldap_Dn::fromString('cn=name2,dc=example,dc=org');
  410. $node1->setDn($dn1);
  411. $dn1->prepend(array('cn' => 'name'));
  412. $this->assertNotEquals($dn1->toString(), $node1->getDn()->toString());
  413. $dn2=Zend_Ldap_Dn::fromString('cn=name2,dc=example,dc=org');
  414. $node2=Zend_Ldap_Node::create($dn2);
  415. $dn2->prepend(array('cn' => 'name'));
  416. $this->assertNotEquals($dn2->toString(), $node2->getDn()->toString());
  417. $dn3=Zend_Ldap_Dn::fromString('cn=name2,dc=example,dc=org');
  418. $node3=Zend_Ldap_Node::fromArray(array(
  419. 'dn' => $dn3,
  420. 'ou' => 'Test'), false);
  421. $dn3->prepend(array('cn' => 'name'));
  422. $this->assertNotEquals($dn3->toString(), $node3->getDn()->toString());
  423. }
  424. public function testGetChanges()
  425. {
  426. $node=$this->_createTestNode();
  427. $node->host=array('d');
  428. $node->empty='not Empty';
  429. unset($node->boolean);
  430. $changes=$node->getChanges();
  431. $this->assertEquals(array(
  432. 'add' => array(
  433. 'empty' => array('not Empty')
  434. ),
  435. 'delete' => array(
  436. 'boolean' => array()
  437. ),
  438. 'replace' => array(
  439. 'host' => array('d')
  440. )
  441. ), $changes);
  442. $node=Zend_Ldap_Node::create('uid=test,dc=example,dc=org', array('account'));
  443. $node->host='host';
  444. unset($node->cn);
  445. unset($node['sn']);
  446. $node['givenName']='givenName';
  447. $node->appendToAttribute('objectClass', 'domain');
  448. $this->assertEquals(array(
  449. 'uid' => array('test'),
  450. 'objectclass' => array('account', 'domain'),
  451. 'host' => array('host'),
  452. 'givenname' => array('givenName')
  453. ), $node->getChangedData());
  454. $this->assertEquals(array(
  455. 'add' => array(
  456. 'uid' => array('test'),
  457. 'objectclass' => array('account', 'domain'),
  458. 'host' => array('host'),
  459. 'givenname' => array('givenName'),
  460. ),
  461. 'delete' => array(),
  462. 'replace' => array()
  463. ), $node->getChanges());
  464. }
  465. public function testHasValue()
  466. {
  467. $node=$this->_createTestNode();
  468. $this->assertTrue($node->attributeHasValue('cn', 'name'));
  469. $this->assertFalse($node->attributeHasValue('cn', 'noname'));
  470. $this->assertTrue($node->attributeHasValue('boolean', true));
  471. $this->assertTrue($node->attributeHasValue('boolean', false));
  472. $this->assertTrue($node->attributeHasValue('host', array('a', 'b')));
  473. $this->assertTrue($node->attributeHasValue('host', array('a', 'b', 'c')));
  474. $this->assertFalse($node->attributeHasValue('host', array('a', 'b', 'c', 'd')));
  475. $this->assertTrue($node->attributeHasValue('boolean', array(true, false)));
  476. }
  477. public function testRemoveDuplicates()
  478. {
  479. $node=$this->_createTestNode();
  480. $node->strings1= array('value1', 'value2', 'value2', 'value3');
  481. $node->strings2= array('value1', 'value2', 'value3', 'value4');
  482. $node->boolean1= array(true, true, true, true);
  483. $node->boolean2= array(true, false, true, false);
  484. $expected=array(
  485. 'cn' => array('name'),
  486. 'host' => array('a', 'b', 'c'),
  487. 'empty' => array(),
  488. 'boolean' => array('TRUE', 'FALSE'),
  489. 'objectclass' => array('account', 'top'),
  490. 'strings1' => array('value1', 'value2', 'value3'),
  491. 'strings2' => array('value1', 'value2', 'value3', 'value4'),
  492. 'boolean1' => array('TRUE'),
  493. 'boolean2' => array('TRUE', 'FALSE'),
  494. );
  495. $node->removeDuplicatesFromAttribute('strings1');
  496. $node->removeDuplicatesFromAttribute('strings2');
  497. $node->removeDuplicatesFromAttribute('boolean1');
  498. $node->removeDuplicatesFromAttribute('boolean2');
  499. $this->assertEquals($expected, $node->getData(false));
  500. }
  501. public function testRemoveFromAttributeSimple()
  502. {
  503. $node=$this->_createTestNode();
  504. $node->test=array('value1', 'value2', 'value3', 'value3');
  505. $node->removeFromAttribute('test', 'value2');
  506. $this->assertEquals(array('value1', 'value3', 'value3'), $node->test);
  507. }
  508. public function testRemoveFromAttributeArray()
  509. {
  510. $node=$this->_createTestNode();
  511. $node->test=array('value1', 'value2', 'value3', 'value3');
  512. $node->removeFromAttribute('test', array('value1', 'value2'));
  513. $this->assertEquals(array('value3', 'value3'), $node->test);
  514. }
  515. public function testRemoveFromAttributeMultipleSimple()
  516. {
  517. $node=$this->_createTestNode();
  518. $node->test=array('value1', 'value2', 'value3', 'value3');
  519. $node->removeFromAttribute('test', 'value3');
  520. $this->assertEquals(array('value1', 'value2'), $node->test);
  521. }
  522. public function testRemoveFromAttributeMultipleArray()
  523. {
  524. $node=$this->_createTestNode();
  525. $node->test=array('value1', 'value2', 'value3', 'value3');
  526. $node->removeFromAttribute('test', array('value1', 'value3'));
  527. $this->assertEquals(array('value2'), $node->test);
  528. }
  529. /**
  530. * ZF-11611
  531. */
  532. public function testRdnAttributesHandleMultiValuedAttribute()
  533. {
  534. $data = array(
  535. 'dn' => 'cn=funkygroup,ou=Groupes,dc=domain,dc=local',
  536. 'objectClass' => array(
  537. 'groupOfNames',
  538. 'top',
  539. ),
  540. 'cn' => array(
  541. 'The Funkygroup',
  542. 'funkygroup',
  543. ),
  544. 'member' => 'uid=john-doe,ou=Users,dc=domain,dc=local',
  545. );
  546. $node = Zend_Ldap_Node::fromArray($data, true);
  547. $changedData = $node->getChangedData();
  548. $this->assertTrue(empty($changedData));
  549. }
  550. /**
  551. * ZF-11611
  552. */
  553. public function testRdnAttributesHandleMultiValuedAttribute2()
  554. {
  555. $data = array(
  556. 'dn' => 'cn=funkygroup,ou=Groupes,dc=domain,dc=local',
  557. 'objectClass' => array(
  558. 'groupOfNames',
  559. 'top',
  560. ),
  561. 'member' => 'uid=john-doe,ou=Users,dc=domain,dc=local',
  562. );
  563. $node = Zend_Ldap_Node::fromArray($data, true);
  564. $cn = $node->getAttribute('cn');
  565. $this->assertEquals(array(
  566. 0 => 'funkygroup'
  567. ), $cn);
  568. }
  569. /**
  570. * ZF-11611
  571. */
  572. public function testRdnAttributesHandleMultiValuedAttribute3()
  573. {
  574. $data = array(
  575. 'dn' => 'cn=funkygroup,ou=Groupes,dc=domain,dc=local',
  576. 'objectClass' => array(
  577. 'groupOfNames',
  578. 'top',
  579. ),
  580. 'cn' => array(
  581. 0 => 'The Funkygroup'
  582. ),
  583. 'member' => 'uid=john-doe,ou=Users,dc=domain,dc=local',
  584. );
  585. $node = Zend_Ldap_Node::fromArray($data, true);
  586. $cn = $node->getAttribute('cn');
  587. $this->assertEquals(array(
  588. 0 => 'The Funkygroup',
  589. 1 => 'funkygroup',
  590. ), $cn);
  591. }
  592. }