diff --git a/src/Schema/Attribute.php b/src/Schema/Attribute.php index 2d2a1de..1b66cb0 100644 --- a/src/Schema/Attribute.php +++ b/src/Schema/Attribute.php @@ -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 $property_aliases + * @property-read array $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', ); diff --git a/src/Schema/Attribute/BooleanAttribute.php b/src/Schema/Attribute/BooleanAttribute.php index d5720e0..b67d5d4 100644 --- a/src/Schema/Attribute/BooleanAttribute.php +++ b/src/Schema/Attribute/BooleanAttribute.php @@ -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 ) + * @return ( $one_value is True ? string|null : array ) */ 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); diff --git a/src/Schema/ObjectClass.php b/src/Schema/ObjectClass.php index 7cb7028..fbf85b4 100644 --- a/src/Schema/ObjectClass.php +++ b/src/Schema/ObjectClass.php @@ -17,6 +17,7 @@ namespace EesyLDAP\Schema; * @property-read string|null $type * @property-read array $must * @property-read array $may + * @property-read array $property_aliases */ class ObjectClass extends SchemaEntry { @@ -52,6 +53,7 @@ class ObjectClass extends SchemaEntry { */ protected static $computed_properties = array( 'names', + 'property_aliases', 'type', ); diff --git a/src/Schema/SchemaEntry.php b/src/Schema/SchemaEntry.php index d72e009..7ff41d7 100644 --- a/src/Schema/SchemaEntry.php +++ b/src/Schema/SchemaEntry.php @@ -7,6 +7,7 @@ namespace EesyLDAP\Schema; * @property-read string $oid * @property-read string $name * @property-read array $names + * @property-read array $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]; } diff --git a/tests/Schema/Attribute/BooleanAttributeTest.php b/tests/Schema/Attribute/BooleanAttributeTest.php new file mode 100644 index 0000000..b8fd523 --- /dev/null +++ b/tests/Schema/Attribute/BooleanAttributeTest.php @@ -0,0 +1,176 @@ + '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)); + } + +} diff --git a/tests/Schema/AttributeTest.php b/tests/Schema/AttributeTest.php new file mode 100644 index 0000000..3e89b1d --- /dev/null +++ b/tests/Schema/AttributeTest.php @@ -0,0 +1,173 @@ + '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)); + } + +} diff --git a/tests/Schema/ObjectClassTest.php b/tests/Schema/ObjectClassTest.php new file mode 100644 index 0000000..ba4d1e5 --- /dev/null +++ b/tests/Schema/ObjectClassTest.php @@ -0,0 +1,100 @@ + '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')); + } + +} diff --git a/tests/Schema/SchemaEntryTest.php b/tests/Schema/SchemaEntryTest.php new file mode 100644 index 0000000..bb7ef46 --- /dev/null +++ b/tests/Schema/SchemaEntryTest.php @@ -0,0 +1,319 @@ + '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', $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())); + } + +}