Author: Chad Sikorra (Chad.Sikorra@gmail.com)
Inheritance: implements LdapTools\Ldif\Entry\LdifEntryInterface, implements LdapTools\Schema\SchemaAwareInterface, implements LdapTools\Connection\LdapAwareInterface, use trait LdifEntryTrait, use trait LdapTools\Schema\SchemaAwareTrait, use trait LdapTools\Connection\LdapAwareTrait
コード例 #1
0
 function it_should_parse_ldif_data()
 {
     $ldif = file_get_contents(__DIR__ . '/../../resources/ldif/sample1.txt');
     $add1 = new LdifEntryAdd('cn=Barbara Jensen, ou=Product Development, dc=airius, dc=com', ['objectclass' => ['top', 'person', 'organizationalPerson'], 'cn' => ['Barbara Jensen', 'Barbara J Jensen', 'Babs Jensen'], 'sn' => 'Jensen', 'uid' => 'bjensen', 'telephonenumber' => '+1 408 555 1212', 'description' => "Babs is a big sailing fan, and travels extensively in search of perfect sailing conditions.", 'title' => 'Product Manager, Rod and Reel Division']);
     $add1->addComment('implicit add example');
     $add1->addComment('With a continued comment included');
     $add2 = new LdifEntryAdd('cn=Fiona Jensen, ou=Marketing, dc=airius, dc=com', ['objectclass' => ['top', 'person', 'organizationalPerson'], 'cn' => 'Fiona Jensen', 'sn' => 'Jensen', 'uid' => 'fiona', 'telephonenumber' => '+1 408 555 1212', 'description' => 'This description will spread across multiple lines.']);
     $add2->addComment('explicit add example', 'cn=Fiona Jensen, ou=Marketing, dc=airius, dc=com');
     $delete1 = new LdifEntryDelete('cn=Robert Jensen, ou=Marketing, dc=airius, dc=com');
     $delete1->addComment('delete example');
     $modrdn = new LdifEntryModRdn('cn=Paul Jensen, ou=Product Development, dc=airius, dc=com', null, 'cn=Paula Jensen', true);
     $modrdn->addComment('using a modrdn');
     $moddn = new LdifEntryModDn('ou=PD Accountants, ou=Product Development, dc=airius, dc=com', 'ou=Accounting, dc=airius, dc=com', 'ou=Product Development Accountants', false);
     $moddn->addComment('using a moddn');
     $modify1 = new LdifEntryModify('cn=Paula Jensen, ou=Product Development, dc=airius, dc=com');
     $modify1->add('postaladdress', '123 Anystreet $ Sunnyvale, CA $ 94086');
     $modify1->reset('description');
     $modify1->replace('telephonenumber', ['+1 408 555 1234', '+1 408 555 5678']);
     $modify1->delete('facsimiletelephonenumber', '+1 408 555 9876');
     $modify1->addComment('modifying an entry');
     $modify2 = new LdifEntryModify('cn=Ingrid Jensen, ou=Product Support, dc=airius, dc=com');
     $modify2->replace('postaladdress', []);
     $modify2->reset('description');
     $modify2->addComment('a replace and delete');
     $delete2 = new LdifEntryDelete('ou=Product Development, dc=airius, dc=com');
     $delete2->addControl((new LdapControl('1.2.840.113556.1.4.805'))->setCriticality(true));
     $delete2->addComment('Delete with a LDAP control');
     $this->parse($ldif)->getComments()->shouldBeEqualTo(['A sample LDIF with entries from the RFC: https://www.ietf.org/rfc/rfc2849.txt', 'This line should be concatenated as a single comment.']);
     $this->parse($ldif)->getEntries()->shouldHaveCount(8);
     $this->parse($ldif)->getEntries()->shouldHaveIndexWithValue(0, $add1);
     $this->parse($ldif)->getEntries()->shouldHaveIndexWithValue(1, $add2);
     $this->parse($ldif)->getEntries()->shouldHaveIndexWithValue(2, $delete1);
     $this->parse($ldif)->getEntries()->shouldHaveIndexWithValue(3, $modrdn);
     $this->parse($ldif)->getEntries()->shouldHaveIndexWithValue(4, $moddn);
     $this->parse($ldif)->getEntries()->shouldHaveIndexWithValue(5, $modify1);
     $this->parse($ldif)->getEntries()->shouldHaveIndexWithValue(6, $modify2);
     $this->parse($ldif)->getEntries()->shouldHaveIndexWithValue(7, $delete2);
 }
コード例 #2
0
ファイル: LdifSpec.php プロジェクト: ldaptools/ldaptools
 function it_should_fold_long_lines_when_specified()
 {
     $dn = 'cn=foo,dc=example,dc=local';
     $description = 'This is a long line that will go over the 76 char limit and then be continued on the next line. We dont need no stinking wordwrap.';
     $givenName = 'foo';
     $comment = 'This is an LDIF file with some really long lines just to test some folded lines so they show up on the next.';
     $comment1 = 'An example comment.';
     $comment2 = 'This comment will go past the line length and should also be split onto the next line.';
     $add = new LdifEntryAdd($dn, ['description' => $description, 'givenName' => $givenName]);
     $add->addComment($comment1, $comment2);
     $this->addEntry($add);
     $this->addComment($comment);
     $ldif = "# This is an LDIF file with some really long lines just to test some folded li\r\n" . " nes so they show up on the next.\r\n" . "version: 1\r\n" . "\r\n" . "# {$comment1}\r\n" . "# This comment will go past the line length and should also be split onto the \r\n" . " next line.\r\n" . "dn: cn=foo,dc=example,dc=local\r\n" . "changetype: add\r\n" . "description: This is a long line that will go over the 76 char limit and then be continue\r\n" . " d on the next line. We dont need no stinking wordwrap.\r\n" . "givenName: {$givenName}\r\n";
     $this->setLineFolding(true);
     $this->toString()->shouldBeEqualTo($ldif);
 }