Add tests on Schema entries and fix related bugs

This commit is contained in:
Benjamin Renard 2023-03-25 01:21:38 +01:00
parent 191a119606
commit fc6823d529
8 changed files with 783 additions and 5 deletions

View file

@ -24,6 +24,8 @@ use EesyLDAP\Schema;
* @property-read bool $collective
* @property-read string|null $usage
* @property-read bool $no_user_modification
* @property-read array<string,string> $property_aliases
* @property-read array<string,string> $map_syntax_to_subtypes
*/
class Attribute extends SchemaEntry {
@ -67,6 +69,8 @@ class Attribute extends SchemaEntry {
*/
protected static $computed_properties = array(
'names',
'property_aliases',
'map_syntax_to_subtypes',
'multiple',
);

View file

@ -55,11 +55,11 @@ class BooleanAttribute extends \EesyLDAP\Schema\Attribute {
* Convert PHP value to LDAP values
* @param mixed $value
* @param bool $one_value Convert one value value of the attribute (optional, default: false)
* @return ( $one_value is True ? string : array<int,string> )
* @return ( $one_value is True ? string|null : array<int,string> )
*/
public function php2ldap($value, $one_value=false) {
if (is_null($value))
return array();
return $one_value?null:array();
if ($one_value)
return $value?self :: TRUE_VALUE:self :: FALSE_VALUE;
$value = is_array($value)?$value:array($value);

View file

@ -17,6 +17,7 @@ namespace EesyLDAP\Schema;
* @property-read string|null $type
* @property-read array<string> $must
* @property-read array<string> $may
* @property-read array<string,string> $property_aliases
*/
class ObjectClass extends SchemaEntry {
@ -52,6 +53,7 @@ class ObjectClass extends SchemaEntry {
*/
protected static $computed_properties = array(
'names',
'property_aliases',
'type',
);

View file

@ -7,6 +7,7 @@ namespace EesyLDAP\Schema;
* @property-read string $oid
* @property-read string $name
* @property-read array<string> $names
* @property-read array<string,string> $property_aliases
*/
class SchemaEntry {
@ -31,6 +32,7 @@ class SchemaEntry {
*/
protected static $computed_properties = array(
'names',
'property_aliases',
);
/**
@ -175,7 +177,7 @@ class SchemaEntry {
$key = static :: $property_aliases[$key];
if (
!array_key_exists($key, static :: $default_properties)
&& !!array_key_exists($key, static :: $computed_properties)
&& !in_array($key, static :: $computed_properties)
)
throw new \EesyLDAP\InvalidPropertyException(
"Invalid property '$key' requested on '".get_called_class()."'"
@ -191,13 +193,15 @@ class SchemaEntry {
isset($this -> data['name']) && $this -> data['name']?
$this -> data['name']:array($this -> oid)
);
case 'property_aliases':
return static :: $property_aliases;
}
$default = static :: $default_properties[$key];
$default = isset(static :: $default_properties[$key])?static :: $default_properties[$key]:null;
if (!array_key_exists($key, $this -> data))
return $default;
if (is_bool($default))
return boolval($this->data[$key]);
if (is_array($default) && !is_array($default))
if (is_array($default) && !is_array($this->data[$key]))
return is_null($this->data[$key])?array():array($this->data[$key]);
return $this->data[$key];
}

View file

@ -0,0 +1,176 @@
<?php
declare(strict_types=1);
use \Mockery\Adapter\Phpunit\MockeryTestCase;
use EesyLDAP\Schema\Attribute\BooleanAttribute;
/**
* @covers \EesyLDAP\Schema\Attribute\BooleanAttribute
*/
final class BooleanAttributeTest extends MockeryTestCase {
/**
* @covers \EesyLDAP\Schema\Attribute\BooleanAttribute::__construct
* @covers \EesyLDAP\Schema\Attribute\BooleanAttribute::ldap2php
* @covers \EesyLDAP\Schema\Attribute::ldap2php
* @covers \EesyLDAP\Schema\Attribute::__get
* @covers \EesyLDAP\Schema\SchemaEntry::__get
*/
public function testLdap2PhpSingleValue() {
$data = array (
'oid' => '1.3.6.1.4.1.10650.3.987512.2.1.0',
'name' => array(
'slEnabled',
),
'equality' => 'booleanMatch',
'syntax' => '1.3.6.1.4.1.1466.115.121.1.7',
'single-value' => 1,
);
$attr = new BooleanAttribute($data);
$this -> assertTrue($attr->ldap2php(array('TRUE')));
$this -> assertFalse($attr->ldap2php(array('FALSE')));
}
/**
* @covers \EesyLDAP\Schema\Attribute\BooleanAttribute::__construct
* @covers \EesyLDAP\Schema\Attribute\BooleanAttribute::ldap2php
* @covers \EesyLDAP\Schema\Attribute::ldap2php
* @covers \EesyLDAP\Schema\Attribute::__get
* @covers \EesyLDAP\Schema\SchemaEntry::__get
*/
public function testLdap2PhpBadValue() {
$data = array (
'oid' => '1.3.6.1.4.1.10650.3.987512.2.1.0',
'name' => array(
'slEnabled',
),
'equality' => 'booleanMatch',
'syntax' => '1.3.6.1.4.1.1466.115.121.1.7',
'single-value' => 1,
);
$attr = new BooleanAttribute($data);
$this -> assertNull($attr->ldap2php(array('???')));
}
/**
* @covers \EesyLDAP\Schema\Attribute\BooleanAttribute::__construct
* @covers \EesyLDAP\Schema\Attribute\BooleanAttribute::ldap2php
* @covers \EesyLDAP\Schema\Attribute::ldap2php
* @covers \EesyLDAP\Schema\Attribute::__get
* @covers \EesyLDAP\Schema\SchemaEntry::__get
*/
public function testLdap2PhpMultiple() {
$data = array (
'oid' => '1.3.6.1.4.1.10650.3.987512.2.1.0',
'name' => array(
'slEnabled',
),
'equality' => 'booleanMatch',
'syntax' => '1.3.6.1.4.1.1466.115.121.1.7',
);
$attr = new BooleanAttribute($data);
$this -> assertEquals(array(true, false), $attr->ldap2php(array('TRUE', 'FALSE')));
}
/**
* @covers \EesyLDAP\Schema\Attribute\BooleanAttribute::__construct
* @covers \EesyLDAP\Schema\Attribute\BooleanAttribute::ldap2php
* @covers \EesyLDAP\Schema\Attribute::ldap2php
* @covers \EesyLDAP\Schema\Attribute::__get
* @covers \EesyLDAP\Schema\SchemaEntry::__get
*/
public function testLdap2PhpNoValueSingle() {
$data = array (
'oid' => '1.3.6.1.4.1.10650.3.987512.2.1.0',
'name' => array(
'slEnabled',
),
'equality' => 'booleanMatch',
'syntax' => '1.3.6.1.4.1.1466.115.121.1.7',
'single-value' => 1,
);
$attr = new BooleanAttribute($data);
$this -> assertEquals(null, $attr->ldap2php(array()));
}
/**
* @covers \EesyLDAP\Schema\Attribute\BooleanAttribute::__construct
* @covers \EesyLDAP\Schema\Attribute\BooleanAttribute::ldap2php
* @covers \EesyLDAP\Schema\Attribute::ldap2php
* @covers \EesyLDAP\Schema\Attribute::__get
* @covers \EesyLDAP\Schema\SchemaEntry::__get
*/
public function testLdap2PhpNoValueMultiple() {
$data = array (
'oid' => '1.3.6.1.4.1.10650.3.987512.2.1.0',
'name' => array(
'slEnabled',
),
'equality' => 'booleanMatch',
'syntax' => '1.3.6.1.4.1.1466.115.121.1.7',
);
$attr = new BooleanAttribute($data);
$this -> assertEquals(array(), $attr->ldap2php(array()));
}
/**
* @covers \EesyLDAP\Schema\Attribute\BooleanAttribute::__construct
* @covers \EesyLDAP\Schema\Attribute\BooleanAttribute::php2ldap
* @covers \EesyLDAP\Schema\Attribute::php2ldap
* @covers \EesyLDAP\Schema\Attribute::__get
* @covers \EesyLDAP\Schema\SchemaEntry::__get
*/
public function testPhp2LdapNotArray() {
$data = array (
'oid' => '1.3.6.1.4.1.10650.3.987512.2.1.0',
'name' => array(
'slEnabled',
),
'equality' => 'booleanMatch',
'syntax' => '1.3.6.1.4.1.1466.115.121.1.7',
);
$attr = new BooleanAttribute($data);
$this -> assertEquals(array('TRUE'), $attr->php2ldap(true));
$this -> assertEquals(array('FALSE'), $attr->php2ldap(false));
}
/**
* @covers \EesyLDAP\Schema\Attribute::__construct
* @covers \EesyLDAP\Schema\Attribute\BooleanAttribute::php2ldap
* @covers \EesyLDAP\Schema\SchemaEntry::__get
*/
public function testPhp2LdapOneValue() {
$data = array (
'oid' => '1.3.6.1.4.1.10650.3.987512.2.1.0',
'name' => array(
'slEnabled',
),
'equality' => 'booleanMatch',
'syntax' => '1.3.6.1.4.1.1466.115.121.1.7',
);
$attr = new BooleanAttribute($data);
$this -> assertEquals('TRUE', $attr->php2ldap(true, true));
$this -> assertEquals('FALSE', $attr->php2ldap(false, true));
}
/**
* @covers \EesyLDAP\Schema\Attribute::__construct
* @covers \EesyLDAP\Schema\Attribute\BooleanAttribute::php2ldap
* @covers \EesyLDAP\Schema\SchemaEntry::__get
*/
public function testPhp2LdapNull() {
$data = array (
'oid' => '1.3.6.1.4.1.10650.3.987512.2.1.0',
'name' => array(
'slEnabled',
),
'equality' => 'booleanMatch',
'syntax' => '1.3.6.1.4.1.1466.115.121.1.7',
);
$attr = new BooleanAttribute($data);
$this -> assertEquals(array(), $attr->php2ldap(null));
$this -> assertNull($attr->php2ldap(null, true));
}
}

View file

@ -0,0 +1,173 @@
<?php
declare(strict_types=1);
use \Mockery\Adapter\Phpunit\MockeryTestCase;
use EesyLDAP\Schema\Attribute;
use EesyLDAP\Schema\Attribute\BooleanAttribute;
/**
* @covers \EesyLDAP\Schema\Attribute
*/
final class AttributeTest extends MockeryTestCase {
/**
* @covers \EesyLDAP\Schema\Attribute::__construct
* @covers \EesyLDAP\Schema\Attribute::__get
* @covers \EesyLDAP\Schema\SchemaEntry::__get
*/
public function testGetMultiple() {
$data = array (
'oid' => '1.3.6.1.4.1.1466.109.114.1',
'name' => array(
'test',
),
'single-value' => 1,
);
$attr = new Attribute($data);
$this -> assertFalse($attr->__get('multiple'));
}
/**
* @covers \EesyLDAP\Schema\Attribute::__construct
* @covers \EesyLDAP\Schema\Attribute::ldap2php
* @covers \EesyLDAP\Schema\SchemaEntry::__get
*/
public function testLdap2PhpSingleValue() {
$values = array('test');
$data = array (
'oid' => '1.3.6.1.4.1.1466.109.114.1',
'name' => array(
'test',
),
'single-value' => 1,
);
$attr = new Attribute($data);
$this -> assertEquals($values[0], $attr->ldap2php($values));
}
/**
* @covers \EesyLDAP\Schema\Attribute::__construct
* @covers \EesyLDAP\Schema\Attribute::ldap2php
* @covers \EesyLDAP\Schema\SchemaEntry::__get
*/
public function testLdap2PhpMultiple() {
$values = array('test');
$data = array (
'oid' => '1.3.6.1.4.1.1466.109.114.1',
'name' => array(
'test',
),
);
$attr = new Attribute($data);
$this -> assertEquals($values, $attr->ldap2php($values));
}
/**
* @covers \EesyLDAP\Schema\Attribute::__construct
* @covers \EesyLDAP\Schema\Attribute::ldap2php
* @covers \EesyLDAP\Schema\SchemaEntry::__get
*/
public function testLdap2PhpNoValueSingle() {
$data = array (
'oid' => '1.3.6.1.4.1.1466.109.114.1',
'name' => array(
'test',
),
'single-value' => 1,
);
$attr = new Attribute($data);
$this -> assertEquals(null, $attr->ldap2php(array()));
}
/**
* @covers \EesyLDAP\Schema\Attribute::__construct
* @covers \EesyLDAP\Schema\Attribute::ldap2php
* @covers \EesyLDAP\Schema\SchemaEntry::__get
*/
public function testLdap2PhpNoValueMultiple() {
$data = array (
'oid' => '1.3.6.1.4.1.1466.109.114.1',
'name' => array(
'test',
),
);
$attr = new Attribute($data);
$this -> assertEquals(array(), $attr->ldap2php(array()));
}
/**
* @covers \EesyLDAP\Schema\Attribute::__construct
* @covers \EesyLDAP\Schema\Attribute::ldap2php
* @covers \EesyLDAP\Schema\SchemaEntry::__get
*/
public function testPhp2LdapNotArray() {
$data = array (
'oid' => '1.3.6.1.4.1.1466.109.114.1',
'name' => array(
'test',
),
);
$attr = new Attribute($data);
$this -> assertEquals(array('test'), $attr->php2ldap('test'));
}
/**
* @covers \EesyLDAP\Schema\Attribute::__construct
* @covers \EesyLDAP\Schema\Attribute::ldap2php
* @covers \EesyLDAP\Schema\SchemaEntry::__get
*/
public function testPhp2LdapOneValue() {
$data = array (
'oid' => '1.3.6.1.4.1.1466.109.114.1',
'name' => array(
'test',
),
);
$attr = new Attribute($data);
$this -> assertEquals('1', $attr->php2ldap(1, true));
}
/**
* @covers \EesyLDAP\Schema\Attribute::__construct
* @covers \EesyLDAP\Schema\Attribute::ldap2php
* @covers \EesyLDAP\Schema\SchemaEntry::__get
*/
public function testPhp2LdapNull() {
$data = array (
'oid' => '1.3.6.1.4.1.1466.109.114.1',
'name' => array(
'test',
),
);
$attr = new Attribute($data);
$this -> assertEquals(array(), $attr->php2ldap(null));
$this -> assertNull($attr->php2ldap(null, true));
}
/**
* @covers \EesyLDAP\Schema\Attribute::parse
* @covers \EesyLDAP\Schema\SchemaEntry::_parse
* @covers \EesyLDAP\Schema\SchemaEntry::__construct
* @covers \EesyLDAP\Schema\SchemaEntry::_tokenize
*/
public function testParse() {
$value = "( 2.5.18.4 NAME 'modifiersName' DESC 'RFC4512: name of last modifier' EQUALITY ".
"distinguishedNameMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 SINGLE-VALUE ".
"NO-USER-MODIFICATION USAGE directoryOperation )";
$this -> assertInstanceOf(Attribute::class, Attribute::parse($value));
}
/**
* @covers \EesyLDAP\Schema\Attribute::parse
* @covers \EesyLDAP\Schema\SchemaEntry::_parse
* @covers \EesyLDAP\Schema\SchemaEntry::__construct
* @covers \EesyLDAP\Schema\SchemaEntry::_tokenize
*/
public function testParseBoolean() {
$value = "( 1.3.6.1.4.1.10650.3.987512.2.1.0 NAME 'slEnabled' DESC 'SimpleLDAP enable state' ".
"EQUALITY booleanMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 SINGLE-VALUE )";
$this -> assertInstanceOf(BooleanAttribute::class, Attribute::parse($value));
}
}

View file

@ -0,0 +1,100 @@
<?php
declare(strict_types=1);
use \Mockery\Adapter\Phpunit\MockeryTestCase;
use EesyLDAP\Schema\ObjectClass;
/**
* @covers \EesyLDAP\Schema\ObjectClass
*/
final class ObjectClassTest extends MockeryTestCase {
/**
* @covers \EesyLDAP\Schema\ObjectClass::__construct
* @covers \EesyLDAP\Schema\ObjectClass::__get
* @covers \EesyLDAP\Schema\SchemaEntry::__get
*/
public function testGetTypeStructural() {
$data = array (
'oid' => '1.3.6.1.4.1.1466.109.114.1',
'name' => array(
'test',
),
'structural' => 1,
);
$entry = new ObjectClass($data);
$this -> assertEquals('structural', $entry->__get('type'));
}
/**
* @covers \EesyLDAP\Schema\ObjectClass::__construct
* @covers \EesyLDAP\Schema\ObjectClass::__get
* @covers \EesyLDAP\Schema\SchemaEntry::__get
*/
public function testGetTypeAbstract() {
$data = array (
'oid' => '1.3.6.1.4.1.1466.109.114.1',
'name' => array(
'test',
),
'abstract' => 1,
);
$entry = new ObjectClass($data);
$this -> assertEquals('abstract', $entry->__get('type'));
}
/**
* @covers \EesyLDAP\Schema\ObjectClass::__construct
* @covers \EesyLDAP\Schema\ObjectClass::__get
* @covers \EesyLDAP\Schema\SchemaEntry::__get
*/
public function testGetTypeAuxilary() {
$data = array (
'oid' => '1.3.6.1.4.1.1466.109.114.1',
'name' => array(
'test',
),
'auxiliary' => 1,
);
$entry = new ObjectClass($data);
$this -> assertEquals('auxiliary', $entry->__get('type'));
}
/**
* @covers \EesyLDAP\Schema\ObjectClass::__construct
* @covers \EesyLDAP\Schema\ObjectClass::__get
* @covers \EesyLDAP\Schema\SchemaEntry::__get
*/
public function testGetTypeInvalid() {
$data = array (
'oid' => '1.3.6.1.4.1.1466.109.114.1',
'name' => array(
'test',
),
);
$entry = new ObjectClass($data);
$this -> assertNull($entry->__get('type'));
}
/**
* @covers \EesyLDAP\Schema\ObjectClass::__construct
* @covers \EesyLDAP\Schema\ObjectClass::__get
* @covers \EesyLDAP\Schema\SchemaEntry::__get
*/
public function testHasAttribute() {
$data = array (
'oid' => '1.3.6.1.4.1.1466.109.114.1',
'name' => array(
'test',
),
'must' => array('uid'),
'may' => array('cn'),
);
$entry = new ObjectClass($data);
$this -> assertTrue($entry->has_attribute('uid'));
$this -> assertTrue($entry->has_attribute('cn'));
$this -> assertFalse($entry->has_attribute('o'));
}
}

View file

@ -0,0 +1,319 @@
<?php
declare(strict_types=1);
use \Mockery\Adapter\Phpunit\MockeryTestCase;
use EesyLDAP\InvalidPropertyException;
use EesyLDAP\Schema\Attribute;
use EesyLDAP\Schema\ObjectClass;
use EesyLDAP\Schema\SchemaEntry;
/**
* @covers \EesyLDAP\Schema\SchemaEntry
*/
final class SchemaEntryTest extends MockeryTestCase {
/**
* @covers \EesyLDAP\Schema\SchemaEntry::_parse
*/
public function testConstruct() {
$data = array (
'oid' => '1.3.6.1.4.1.1466.109.114.1',
'name' => array(
'caseExactIA5Match',
),
'syntax' => '1.3.6.1.4.1.1466.115.121.1.26',
);
$entry = new SchemaEntry($data);
$reflection = new ReflectionClass($entry);
$data_property = $reflection->getProperty('data');
$data_property->setAccessible(true);
$this -> assertEquals($data, $data_property->getValue($entry));
}
/**
* @covers \EesyLDAP\Schema\SchemaEntry::_parse
*/
public function testRawParseAttribute() {
$value = "( 2.5.18.4 NAME 'modifiersName' DESC 'RFC4512: name of last modifier' EQUALITY ".
"distinguishedNameMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 SINGLE-VALUE ".
"NO-USER-MODIFICATION USAGE directoryOperation )";
$expected = array (
'oid' => '2.5.18.4',
'name' => array(
'modifiersName',
),
'desc' => 'RFC4512: name of last modifier',
'equality' => 'distinguishedNameMatch',
'syntax' => '1.3.6.1.4.1.1466.115.121.1.12',
'single-value' => 1,
'no-user-modification' => 1,
'usage' => 'directoryOperation',
);
$this -> assertEquals($expected, SchemaEntry::_parse($value));
}
/**
* @covers \EesyLDAP\Schema\SchemaEntry::_parse
*/
public function testRawParseAttributeWithMaxLength() {
$value = "( 1.3.6.1.1.1.1.19 NAME 'ipHostNumber' DESC 'IP address' EQUALITY caseIgnoreIA5Match ".
"SYNTAX 1.3.6.1.4.1.1466.115.121.1.26{128} )";
$expected = array (
'oid' => '1.3.6.1.1.1.1.19',
'name' => array(
'ipHostNumber',
),
'desc' => 'IP address',
'equality' => 'caseIgnoreIA5Match',
'syntax' => '1.3.6.1.4.1.1466.115.121.1.26{128}',
'max_length' => 128,
);
$this -> assertEquals($expected, SchemaEntry::_parse($value));
}
/**
* @covers \EesyLDAP\Schema\SchemaEntry::_parse
*/
public function testRawParseMatchingRule() {
$value = "( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )";
$expected = array (
'oid' => '1.3.6.1.4.1.1466.109.114.1',
'name' => array(
'caseExactIA5Match',
),
'syntax' => '1.3.6.1.4.1.1466.115.121.1.26',
);
$this -> assertEquals($expected, SchemaEntry::_parse($value));
}
/**
* @covers \EesyLDAP\Schema\SchemaEntry::_parse
*/
public function testRawParseMatchingRuleUse() {
$value = "( 2.5.13.38 NAME 'certificateListExactMatch' APPLIES ( authorityRevocationList $ ".
"certificateRevocationList $ deltaRevocationList ) )";
$expected = array (
'oid' => '2.5.13.38',
'name' => array(
'certificateListExactMatch',
),
'applies' => array(
'authorityRevocationList',
'certificateRevocationList',
'deltaRevocationList',
),
);
$this -> assertEquals($expected, SchemaEntry::_parse($value));
}
/**
* @covers \EesyLDAP\Schema\SchemaEntry::_parse
*/
public function testRawParseObjectClass() {
$value = "( 0.9.2342.19200300.100.4.5 NAME 'account' SUP top STRUCTURAL MUST userid MAY ".
"( description $ seeAlso $ localityName $ organizationName $ organizationalUnitName $ host ) )";
$expected = array (
'oid' => '0.9.2342.19200300.100.4.5',
'name' => array(
'account',
),
'sup' => array(
'top',
),
'structural' => 1,
'must' => array(
'userid',
),
'may' => array(
'description',
'seeAlso',
'localityName',
'organizationName',
'organizationalUnitName',
'host',
),
);
$this -> assertEquals($expected, SchemaEntry::_parse($value));
}
/**
* @covers \EesyLDAP\Schema\SchemaEntry::_parse
*/
public function testRawParseSyntax() {
$value = "( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' X-BINARY-TRANSFER-REQUIRED 'TRUE' ".
"X-NOT-HUMAN-READABLE 'TRUE' )";
$expected = array (
'oid' => '1.3.6.1.4.1.1466.115.121.1.8',
'desc' => 'Certificate',
'x-binary-transfer-required' => 'TRUE',
'x-not-human-readable' => 'TRUE',
);
$this -> assertEquals($expected, SchemaEntry::_parse($value));
}
/**
* @covers \EesyLDAP\Schema\SchemaEntry::parse
*/
public function testParseEntry() {
$value = "( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' X-BINARY-TRANSFER-REQUIRED 'TRUE' ".
"X-NOT-HUMAN-READABLE 'TRUE' )";
$entry = SchemaEntry::parse($value);
$this -> assertInstanceOf(SchemaEntry::class, $entry);
}
/**
* @covers \EesyLDAP\Schema\SchemaEntry::__get
* @covers \EesyLDAP\Schema\Attribute::__get
*/
public function testGetProperties() {
$data = array (
'oid' => '2.5.4.46',
'sup' => 'top',
'desc' => 'RFC2256: DN qualifier',
'equality' => 'caseIgnoreMatch',
'ordering' => 'caseIgnoreOrderingMatch',
'substr' => 'caseIgnoreSubstringsMatch',
'syntax' => '1.3.6.1.4.1.1466.115.121.1.44',
'single-value' => 1,
'no-user-modification' => 1,
'usage' => 'directoryOperation',
);
$entry = new Attribute($data);
foreach($data as $key => $value)
$this -> assertEquals($value, $entry->__get($key));
}
/**
* @covers \EesyLDAP\Schema\SchemaEntry::__get
* @covers \EesyLDAP\Schema\Attribute::__get
*/
public function testGetPropertyAlias() {
$data = array (
'oid' => '2.5.4.46',
'sup' => 'top',
'desc' => 'RFC2256: DN qualifier',
'equality' => 'caseIgnoreMatch',
'ordering' => 'caseIgnoreOrderingMatch',
'substr' => 'caseIgnoreSubstringsMatch',
'syntax' => '1.3.6.1.4.1.1466.115.121.1.44',
'single-value' => 1,
'no-user-modification' => 1,
'usage' => 'directoryOperation',
);
$entry = new Attribute($data);
foreach($entry->property_aliases as $alias => $key)
$this -> assertEquals($data[$key], $entry->__get($alias));
}
/**
* @covers \EesyLDAP\Schema\SchemaEntry::__get
*/
public function testGetInvalidProperty() {
$data = array (
'oid' => '1.3.6.1.4.1.1466.115.121.1.8',
'desc' => 'Certificate',
'x-binary-transfer-required' => 'TRUE',
'x-not-human-readable' => 'TRUE',
);
$entry = new SchemaEntry($data);
$this->expectException(InvalidPropertyException::class);
$entry->__get('undefined');
}
/**
* @covers \EesyLDAP\Schema\SchemaEntry::__get
*/
public function testGetName() {
$data = array (
'oid' => '1.3.6.1.4.1.1466.115.121.1.8',
'desc' => 'Certificate',
'x-binary-transfer-required' => 'TRUE',
'x-not-human-readable' => 'TRUE',
);
$entry = new SchemaEntry($data);
$this->assertEquals($data['oid'], $entry->__get('name'));
}
/**
* @covers \EesyLDAP\Schema\SchemaEntry::__get
*/
public function testGetNames() {
$data = array (
'oid' => '1.3.6.1.4.1.1466.115.121.1.8',
'name' => array('test'),
);
$entry = new SchemaEntry($data);
$this->assertEquals($data['name'], $entry->__get('names'));
}
/**
* @covers \EesyLDAP\Schema\SchemaEntry::__get
* @covers \EesyLDAP\Schema\Attribute::__get
*/
public function testGetPropertyDefault() {
$data = array (
'oid' => '1.3.6.1.4.1.1466.115.121.1.8',
'name' => array('test'),
);
$entry = new Attribute($data);
$this->assertEquals(false, $entry->__get('collective'));
}
/**
* @covers \EesyLDAP\Schema\SchemaEntry::__get
* @covers \EesyLDAP\Schema\ObjectClass::__get
*/
public function testGetPropertyCastAsArray() {
$data = array (
'may' => 'test',
);
$entry = new ObjectClass($data);
$this->assertEquals(array($data['may']), $entry->__get('may'));
}
/**
* @covers \EesyLDAP\Schema\SchemaEntry::__toString
*/
public function testToString() {
$data = array (
'name' => array('test'),
);
$entry = new SchemaEntry($data);
$this->assertEquals('EesyLDAP\Schema\SchemaEntry<test>', $entry->__toString());
}
/**
* @covers \EesyLDAP\Schema\SchemaEntry::is_me
*/
public function testIsMeByOID() {
$data = array (
'oid' => '1.2.3.4',
);
$entry = new SchemaEntry($data);
$this->assertTrue($entry->is_me($data['oid']));
$this->assertFalse($entry->is_me('2.3.4'));
}
/**
* @covers \EesyLDAP\Schema\SchemaEntry::is_me
*/
public function testIsMeByNames() {
$data = array (
'name' => array('test'),
);
$entry = new SchemaEntry($data);
$this->assertTrue($entry->is_me($data['name'][0]));
$this->assertFalse($entry->is_me('badName'));
}
/**
* @covers \EesyLDAP\Schema\SchemaEntry::is_me
*/
public function testIsMeBadID() {
$entry = new SchemaEntry(array());
// @phpstan-ignore-next-line
$this->assertFalse($entry->is_me(array()));
}
}