<?php
namespace nur\ldap;

use PHPUnit\Framework\TestCase;

class ldapTest extends TestCase {
  function testPrepare_rename() {
    $rdn = "uid=ouid";
    $params = null;
    self::assertFalse(ldap::prepare_rename("uid=ouid,dc=osuffix", $rdn, $params));

    # renommage
    $rdn = "uid=nuid";
    $params = null;
    self::assertTrue(ldap::prepare_rename("uid=ouid,dc=osuffix", $rdn, $params));
    self::assertSame("uid=nuid", $rdn);
    self::assertSame([
      "new_parent" => "dc=osuffix",
      "delete_old_rdn" => true,
      "controls" => [],
    ], $params);

    # renommage + déplacement
    $rdn = "uid=nuid";
    $params = "dc=nsuffix";
    self::assertTrue(ldap::prepare_rename("uid=ouid,dc=osuffix", $rdn, $params));
    self::assertSame("uid=nuid", $rdn);
    self::assertSame([
      "new_parent" => "dc=nsuffix",
      "delete_old_rdn" => true,
      "controls" => [],
    ], $params);

    # déplacement uniquement
    $rdn = "";
    $params = "dc=nsuffix";
    self::assertTrue(ldap::prepare_rename("uid=ouid,dc=osuffix", $rdn, $params));
    self::assertSame("uid=ouid", $rdn);
    self::assertSame([
      "new_parent" => "dc=nsuffix",
      "delete_old_rdn" => true,
      "controls" => [],
    ], $params);

    # rdn complexe
    $rdn = "uid=nuid,ou=groups";
    $params = "dc=nsuffix,dc=tld";
    self::assertTrue(ldap::prepare_rename("uid=ouid,dc=osuffix", $rdn, $params));
    self::assertSame("uid=nuid", $rdn);
    self::assertSame([
      "new_parent" => "ou=groups,dc=nsuffix,dc=tld",
      "delete_old_rdn" => true,
      "controls" => [],
    ], $params);
  }
}