|
13 | 13 |
|
14 | 14 | use Symfony\Component\Ldap\Adapter\ExtLdap\Adapter;
|
15 | 15 | use Symfony\Component\Ldap\Adapter\ExtLdap\Collection;
|
| 16 | +use Symfony\Component\Ldap\Adapter\ExtLdap\UpdateOperation; |
16 | 17 | use Symfony\Component\Ldap\Entry;
|
| 18 | +use Symfony\Component\Ldap\Exception\UpdateOperationException; |
17 | 19 | use Symfony\Component\Ldap\Exception\LdapException;
|
18 | 20 | use Symfony\Component\Ldap\Exception\NotBoundException;
|
19 | 21 |
|
@@ -238,4 +240,105 @@ public function testLdapAddAttributeValuesError()
|
238 | 240 |
|
239 | 241 | $entryManager->addAttributeValues($entry, 'mail', $entry->getAttribute('mail'));
|
240 | 242 | }
|
| 243 | + |
| 244 | + public function testLdapApplyOperationsRemoveAllWithArrayError() |
| 245 | + { |
| 246 | + $entryManager = $this->adapter->getEntryManager(); |
| 247 | + |
| 248 | + $result = $this->executeSearchQuery(1); |
| 249 | + $entry = $result[0]; |
| 250 | + |
| 251 | + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(UpdateOperationException::class); |
| 252 | + |
| 253 | + $entryManager->applyOperations($entry->getDn(), array(new UpdateOperation(LDAP_MODIFY_BATCH_REMOVE_ALL, 'mail', array()))); |
| 254 | + } |
| 255 | + |
| 256 | + public function testLdapApplyOperationsWithWrongConstantError() |
| 257 | + { |
| 258 | + $entryManager = $this->adapter->getEntryManager(); |
| 259 | + |
| 260 | + $result = $this->executeSearchQuery(1); |
| 261 | + $entry = $result[0]; |
| 262 | + |
| 263 | + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(UpdateOperationException::class); |
| 264 | + |
| 265 | + $entryManager->applyOperations($entry->getDn(), array(new UpdateOperation(512, 'mail', array()))); |
| 266 | + } |
| 267 | + |
| 268 | + public function testApplyOperationsAddRemoveAttributeValues() |
| 269 | + { |
| 270 | + $entryManager = $this->adapter->getEntryManager(); |
| 271 | + |
| 272 | + $result = $this->executeSearchQuery(1); |
| 273 | + $entry = $result[0]; |
| 274 | + |
| 275 | + $entryManager->applyOperations($entry->getDn(), array( |
| 276 | + new UpdateOperation(LDAP_MODIFY_BATCH_ADD, 'mail', array('fabpot@example.org', 'fabpot2@example.org')), |
| 277 | + new UpdateOperation(LDAP_MODIFY_BATCH_ADD, 'mail', array('fabpot3@example.org', 'fabpot4@example.org')), |
| 278 | + )); |
| 279 | + |
| 280 | + $result = $this->executeSearchQuery(1); |
| 281 | + $newEntry = $result[0]; |
| 282 | + |
| 283 | + $this->assertCount(6, $newEntry->getAttribute('mail')); |
| 284 | + |
| 285 | + $entryManager->applyOperations($entry->getDn(), array( |
| 286 | + new UpdateOperation(LDAP_MODIFY_BATCH_REMOVE, 'mail', array('fabpot@example.org', 'fabpot2@example.org')), |
| 287 | + new UpdateOperation(LDAP_MODIFY_BATCH_REMOVE, 'mail', array('fabpot3@example.org', 'fabpot4@example.org')), |
| 288 | + )); |
| 289 | + |
| 290 | + $result = $this->executeSearchQuery(1); |
| 291 | + $newNewEntry = $result[0]; |
| 292 | + |
| 293 | + $this->assertCount(2, $newNewEntry->getAttribute('mail')); |
| 294 | + } |
| 295 | + |
| 296 | + public function testUpdateOperationsWithIterator() |
| 297 | + { |
| 298 | + $iteratorAdd = new \ArrayIterator(array( |
| 299 | + new UpdateOperation(LDAP_MODIFY_BATCH_ADD, 'mail', array('fabpot@example.org', 'fabpot2@example.org')), |
| 300 | + new UpdateOperation(LDAP_MODIFY_BATCH_ADD, 'mail', array('fabpot3@example.org', 'fabpot4@example.org')), |
| 301 | + )); |
| 302 | + |
| 303 | + $iteratorRemove = new \ArrayIterator(array( |
| 304 | + new UpdateOperation(LDAP_MODIFY_BATCH_REMOVE, 'mail', array('fabpot@example.org', 'fabpot2@example.org')), |
| 305 | + new UpdateOperation(LDAP_MODIFY_BATCH_REMOVE, 'mail', array('fabpot3@example.org', 'fabpot4@example.org')), |
| 306 | + )); |
| 307 | + |
| 308 | + $entryManager = $this->adapter->getEntryManager(); |
| 309 | + |
| 310 | + $result = $this->executeSearchQuery(1); |
| 311 | + $entry = $result[0]; |
| 312 | + |
| 313 | + $entryManager->applyOperations($entry->getDn(), $iteratorAdd); |
| 314 | + |
| 315 | + $result = $this->executeSearchQuery(1); |
| 316 | + $newEntry = $result[0]; |
| 317 | + |
| 318 | + $this->assertCount(6, $newEntry->getAttribute('mail')); |
| 319 | + |
| 320 | + $entryManager->applyOperations($entry->getDn(), $iteratorRemove); |
| 321 | + |
| 322 | + $result = $this->executeSearchQuery(1); |
| 323 | + $newNewEntry = $result[0]; |
| 324 | + |
| 325 | + $this->assertCount(2, $newNewEntry->getAttribute('mail')); |
| 326 | + } |
| 327 | + |
| 328 | + public function testUpdateOperationsThrowsExceptionWhenAddedDuplicatedValue() |
| 329 | + { |
| 330 | + $duplicateIterator = new \ArrayIterator(array( |
| 331 | + new UpdateOperation(LDAP_MODIFY_BATCH_ADD, 'mail', array('fabpot@example.org')), |
| 332 | + new UpdateOperation(LDAP_MODIFY_BATCH_ADD, 'mail', array('fabpot@example.org')), |
| 333 | + )); |
| 334 | + |
| 335 | + $entryManager = $this->adapter->getEntryManager(); |
| 336 | + |
| 337 | + $result = $this->executeSearchQuery(1); |
| 338 | + $entry = $result[0]; |
| 339 | + |
| 340 | + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(UpdateOperationException::class); |
| 341 | + |
| 342 | + $entryManager->applyOperations($entry->getDn(), $duplicateIterator); |
| 343 | + } |
241 | 344 | }
|
0 commit comments