custom fields constants
This commit is contained in:
parent
8ef708b43f
commit
f1ebe371d7
|
@ -5127,6 +5127,71 @@ OK (10 msec)</programlisting>
|
|||
</mediaobject>
|
||||
</screenshot>
|
||||
|
||||
<para><emphasis role="bold">Constant value</emphasis></para>
|
||||
|
||||
<para>This will set the attribute to a constant value. You can also
|
||||
specify wild cards to inject other attribute's values:</para>
|
||||
|
||||
<para>Wildcards</para>
|
||||
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<para>%attribute%: attribute value</para>
|
||||
</listitem>
|
||||
|
||||
<listitem>
|
||||
<para>@attribute@: first character of attribute</para>
|
||||
</listitem>
|
||||
|
||||
<listitem>
|
||||
<para>?attribute?: first character of attribute in lower case</para>
|
||||
</listitem>
|
||||
|
||||
<listitem>
|
||||
<para>!attribute!: first character of attribute in upper case</para>
|
||||
</listitem>
|
||||
|
||||
<listitem>
|
||||
<para>??attribute??: attribute in lower case</para>
|
||||
</listitem>
|
||||
|
||||
<listitem>
|
||||
<para>!!attribute!!: attribute in upper case</para>
|
||||
</listitem>
|
||||
|
||||
<listitem>
|
||||
<para>(attribute): space if attribute is set</para>
|
||||
</listitem>
|
||||
|
||||
<listitem>
|
||||
<para>§attribute|;§; attribute values separted by ";" (you can set
|
||||
other separators if you want)</para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
|
||||
<para>Examples for attributes gn="Steve", sn="Miller" and
|
||||
memberUid=("user1", "user2") (specified value -> resulting LDAP
|
||||
value):</para>
|
||||
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<para>"my constant" -> "my constant"</para>
|
||||
</listitem>
|
||||
|
||||
<listitem>
|
||||
<para>"%gn%" -> "Steve"</para>
|
||||
</listitem>
|
||||
|
||||
<listitem>
|
||||
<para>"%gn%(gn)%sn%" -> "Steve Miller" (would be "Miller" if gn is
|
||||
empty)</para>
|
||||
</listitem>
|
||||
|
||||
<listitem>
|
||||
<para>"§memberUid|, §" -> "user1, user2"</para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
|
||||
<para id="customFields_validation_expressions_admin"><emphasis
|
||||
role="bold">Validation expressions:</emphasis></para>
|
||||
|
||||
|
|
|
@ -0,0 +1,243 @@
|
|||
<?php
|
||||
/*
|
||||
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
|
||||
Copyright (C) 2017 Roland Gruber
|
||||
*/
|
||||
|
||||
if (is_readable('lam/lib/modules/customFields.inc')) {
|
||||
|
||||
include_once 'lam/lib/baseModule.inc';
|
||||
include_once 'lam/lib/modules.inc';
|
||||
include_once 'lam/lib/modules/customFields.inc';
|
||||
|
||||
/**
|
||||
* Checks the ppolicy expire job.
|
||||
*
|
||||
* @author Roland Gruber
|
||||
*
|
||||
*/
|
||||
class customFieldsConstantEntryTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
public function testReplaceWildcardsSpaces() {
|
||||
$originalMiddle = '123((uid))456';
|
||||
$originalStart = '((Uid))456';
|
||||
$originalEnd = '123((uid))';
|
||||
$originalMultiple = '123((uid))456((uid))789';
|
||||
$attributesSet = array('uid' => array('111'));
|
||||
$attributesNotSet = array('uid' => array(''));
|
||||
$attributesNotSet2 = array();
|
||||
|
||||
$this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalMiddle));
|
||||
$this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalMiddle));
|
||||
$this->assertEquals('123 456', customFieldsConstantEntry::replaceWildcards($attributesSet, $originalMiddle));
|
||||
|
||||
$this->assertEquals('456', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalStart));
|
||||
$this->assertEquals('456', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalStart));
|
||||
$this->assertEquals(' 456', customFieldsConstantEntry::replaceWildcards($attributesSet, $originalStart));
|
||||
|
||||
$this->assertEquals('123', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalEnd));
|
||||
$this->assertEquals('123', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalEnd));
|
||||
$this->assertEquals('123 ', customFieldsConstantEntry::replaceWildcards($attributesSet, $originalEnd));
|
||||
|
||||
$this->assertEquals('123456789', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalMultiple));
|
||||
$this->assertEquals('123456789', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalMultiple));
|
||||
$this->assertEquals('123 456 789', customFieldsConstantEntry::replaceWildcards($attributesSet, $originalMultiple));
|
||||
}
|
||||
|
||||
public function testReplaceWildcardsAttribute() {
|
||||
$originalMiddle = '123%uid%456';
|
||||
$originalStart = '%Uid%456';
|
||||
$originalEnd = '123%uid%';
|
||||
$originalMultiple = '123%uid%456%uid%789';
|
||||
$attributesSet = array('uid' => array('111'));
|
||||
$attributesNotSet = array('uid' => array(''));
|
||||
$attributesNotSet2 = array();
|
||||
|
||||
$this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalMiddle));
|
||||
$this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalMiddle));
|
||||
$this->assertEquals('123111456', customFieldsConstantEntry::replaceWildcards($attributesSet, $originalMiddle));
|
||||
|
||||
$this->assertEquals('456', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalStart));
|
||||
$this->assertEquals('456', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalStart));
|
||||
$this->assertEquals('111456', customFieldsConstantEntry::replaceWildcards($attributesSet, $originalStart));
|
||||
|
||||
$this->assertEquals('123', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalEnd));
|
||||
$this->assertEquals('123', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalEnd));
|
||||
$this->assertEquals('123111', customFieldsConstantEntry::replaceWildcards($attributesSet, $originalEnd));
|
||||
|
||||
$this->assertEquals('123456789', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalMultiple));
|
||||
$this->assertEquals('123456789', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalMultiple));
|
||||
$this->assertEquals('123111456111789', customFieldsConstantEntry::replaceWildcards($attributesSet, $originalMultiple));
|
||||
}
|
||||
|
||||
public function testReplaceWildcardsAttributeFirst() {
|
||||
$originalMiddle = '123@uid@456';
|
||||
$originalStart = '@Uid@456';
|
||||
$originalEnd = '123@uid@';
|
||||
$originalMultiple = '123@uid@456@uid@789';
|
||||
$attributesSet = array('uid' => array('aBc'));
|
||||
$attributesNotSet = array('uid' => array(''));
|
||||
$attributesNotSet2 = array();
|
||||
|
||||
$this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalMiddle));
|
||||
$this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalMiddle));
|
||||
$this->assertEquals('123a456', customFieldsConstantEntry::replaceWildcards($attributesSet, $originalMiddle));
|
||||
|
||||
$this->assertEquals('456', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalStart));
|
||||
$this->assertEquals('456', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalStart));
|
||||
$this->assertEquals('a456', customFieldsConstantEntry::replaceWildcards($attributesSet, $originalStart));
|
||||
|
||||
$this->assertEquals('123', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalEnd));
|
||||
$this->assertEquals('123', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalEnd));
|
||||
$this->assertEquals('123a', customFieldsConstantEntry::replaceWildcards($attributesSet, $originalEnd));
|
||||
|
||||
$this->assertEquals('123456789', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalMultiple));
|
||||
$this->assertEquals('123456789', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalMultiple));
|
||||
$this->assertEquals('123a456a789', customFieldsConstantEntry::replaceWildcards($attributesSet, $originalMultiple));
|
||||
}
|
||||
|
||||
public function testReplaceWildcardsAttributeFirstLower() {
|
||||
$originalMiddle = '123?uid?456';
|
||||
$originalStart = '?Uid?456';
|
||||
$originalEnd = '123?uid?';
|
||||
$originalMultiple = '123?uid?456?uid?789';
|
||||
$attributesSet = array('uid' => array('Abc'));
|
||||
$attributesNotSet = array('uid' => array(''));
|
||||
$attributesNotSet2 = array();
|
||||
|
||||
$this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalMiddle));
|
||||
$this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalMiddle));
|
||||
$this->assertEquals('123a456', customFieldsConstantEntry::replaceWildcards($attributesSet, $originalMiddle));
|
||||
|
||||
$this->assertEquals('456', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalStart));
|
||||
$this->assertEquals('456', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalStart));
|
||||
$this->assertEquals('a456', customFieldsConstantEntry::replaceWildcards($attributesSet, $originalStart));
|
||||
|
||||
$this->assertEquals('123', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalEnd));
|
||||
$this->assertEquals('123', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalEnd));
|
||||
$this->assertEquals('123a', customFieldsConstantEntry::replaceWildcards($attributesSet, $originalEnd));
|
||||
|
||||
$this->assertEquals('123456789', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalMultiple));
|
||||
$this->assertEquals('123456789', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalMultiple));
|
||||
$this->assertEquals('123a456a789', customFieldsConstantEntry::replaceWildcards($attributesSet, $originalMultiple));
|
||||
}
|
||||
|
||||
public function testReplaceWildcardsAttributeFirstUpper() {
|
||||
$originalMiddle = '123!uid!456';
|
||||
$originalStart = '!Uid!456';
|
||||
$originalEnd = '123!uid!';
|
||||
$originalMultiple = '123!uid!456!uid!789';
|
||||
$attributesSet = array('uid' => array('abc'));
|
||||
$attributesNotSet = array('uid' => array(''));
|
||||
$attributesNotSet2 = array();
|
||||
|
||||
$this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalMiddle));
|
||||
$this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalMiddle));
|
||||
$this->assertEquals('123A456', customFieldsConstantEntry::replaceWildcards($attributesSet, $originalMiddle));
|
||||
|
||||
$this->assertEquals('456', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalStart));
|
||||
$this->assertEquals('456', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalStart));
|
||||
$this->assertEquals('A456', customFieldsConstantEntry::replaceWildcards($attributesSet, $originalStart));
|
||||
|
||||
$this->assertEquals('123', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalEnd));
|
||||
$this->assertEquals('123', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalEnd));
|
||||
$this->assertEquals('123A', customFieldsConstantEntry::replaceWildcards($attributesSet, $originalEnd));
|
||||
|
||||
$this->assertEquals('123456789', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalMultiple));
|
||||
$this->assertEquals('123456789', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalMultiple));
|
||||
$this->assertEquals('123A456A789', customFieldsConstantEntry::replaceWildcards($attributesSet, $originalMultiple));
|
||||
}
|
||||
|
||||
public function testReplaceWildcardsAttributeLower() {
|
||||
$originalMiddle = '123??uid??456';
|
||||
$originalStart = '??Uid??456';
|
||||
$originalEnd = '123??uid??';
|
||||
$originalMultiple = '123??uid??456??uid??789';
|
||||
$attributesSet = array('uid' => array('Abc'));
|
||||
$attributesNotSet = array('uid' => array(''));
|
||||
$attributesNotSet2 = array();
|
||||
|
||||
$this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalMiddle));
|
||||
$this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalMiddle));
|
||||
$this->assertEquals('123abc456', customFieldsConstantEntry::replaceWildcards($attributesSet, $originalMiddle));
|
||||
|
||||
$this->assertEquals('456', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalStart));
|
||||
$this->assertEquals('456', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalStart));
|
||||
$this->assertEquals('abc456', customFieldsConstantEntry::replaceWildcards($attributesSet, $originalStart));
|
||||
|
||||
$this->assertEquals('123', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalEnd));
|
||||
$this->assertEquals('123', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalEnd));
|
||||
$this->assertEquals('123abc', customFieldsConstantEntry::replaceWildcards($attributesSet, $originalEnd));
|
||||
|
||||
$this->assertEquals('123456789', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalMultiple));
|
||||
$this->assertEquals('123456789', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalMultiple));
|
||||
$this->assertEquals('123abc456abc789', customFieldsConstantEntry::replaceWildcards($attributesSet, $originalMultiple));
|
||||
}
|
||||
|
||||
public function testReplaceWildcardsAttributeUpper() {
|
||||
$originalMiddle = '123!!uid!!456';
|
||||
$originalStart = '!!Uid!!456';
|
||||
$originalEnd = '123!!uid!!';
|
||||
$originalMultiple = '123!!uid!!456!!uid!!789';
|
||||
$attributesSet = array('uid' => array('abc'));
|
||||
$attributesNotSet = array('uid' => array(''));
|
||||
$attributesNotSet2 = array();
|
||||
|
||||
$this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalMiddle));
|
||||
$this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalMiddle));
|
||||
$this->assertEquals('123ABC456', customFieldsConstantEntry::replaceWildcards($attributesSet, $originalMiddle));
|
||||
|
||||
$this->assertEquals('456', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalStart));
|
||||
$this->assertEquals('456', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalStart));
|
||||
$this->assertEquals('ABC456', customFieldsConstantEntry::replaceWildcards($attributesSet, $originalStart));
|
||||
|
||||
$this->assertEquals('123', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalEnd));
|
||||
$this->assertEquals('123', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalEnd));
|
||||
$this->assertEquals('123ABC', customFieldsConstantEntry::replaceWildcards($attributesSet, $originalEnd));
|
||||
|
||||
$this->assertEquals('123456789', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalMultiple));
|
||||
$this->assertEquals('123456789', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalMultiple));
|
||||
$this->assertEquals('123ABC456ABC789', customFieldsConstantEntry::replaceWildcards($attributesSet, $originalMultiple));
|
||||
}
|
||||
|
||||
public function testReplaceWildcardsAttributeMulti() {
|
||||
$originalMiddle = '123§memberUid|, §456';
|
||||
$originalStart = '§MemberUid|, §456';
|
||||
$originalEnd = '123§memberUid|, §';
|
||||
$originalMultiple = '123§memberUid|, §456§memberUid|;§789';
|
||||
$attributesSet = array('memberUid' => array('abc', 'cde'));
|
||||
$attributesNotSet = array('memberUid' => array(''));
|
||||
$attributesNotSet2 = array();
|
||||
|
||||
$this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalMiddle));
|
||||
$this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalMiddle));
|
||||
$this->assertEquals('123abc, cde456', customFieldsConstantEntry::replaceWildcards($attributesSet, $originalMiddle));
|
||||
|
||||
$this->assertEquals('456', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalStart));
|
||||
$this->assertEquals('456', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalStart));
|
||||
$this->assertEquals('abc, cde456', customFieldsConstantEntry::replaceWildcards($attributesSet, $originalStart));
|
||||
|
||||
$this->assertEquals('123', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalEnd));
|
||||
$this->assertEquals('123', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalEnd));
|
||||
$this->assertEquals('123abc, cde', customFieldsConstantEntry::replaceWildcards($attributesSet, $originalEnd));
|
||||
|
||||
$this->assertEquals('123456789', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalMultiple));
|
||||
$this->assertEquals('123456789', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalMultiple));
|
||||
$this->assertEquals('123abc, cde456abc;cde789', customFieldsConstantEntry::replaceWildcards($attributesSet, $originalMultiple));
|
||||
}
|
||||
|
||||
public function testReplaceWildcardsMixed() {
|
||||
$attributes = array(
|
||||
'uid' => array('myuser'),
|
||||
'street' => array('some street'),
|
||||
'memberUid' => array('abc', 'cde')
|
||||
);
|
||||
|
||||
$this->assertEquals('myuser SOME STREET S abc- cde', customFieldsConstantEntry::replaceWildcards($attributes, '%uid% !!street!! !street! §memberuid|- §'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in New Issue