public static function read_one_ldif($file)
 {
     // open some LDIF file for reading
     $ldif = new Net_LDAP2_LDIF($file, 'r', array('onerror' => 'die'));
     $entry = $ldif->read_entry();
     $ldif->done();
     return $entry;
 }
Пример #2
0
 /**
  * Tests if entry changes are correctly written
  */
 public function testWrite_entryChanges()
 {
     $testentries = $this->testentries;
     $testentries[] = Net_LDAP2_Entry::createFresh('cn=foo,ou=example,dc=com', array('cn' => 'foo'));
     $testentries[] = Net_LDAP2_Entry::createFresh('cn=footest,ou=example,dc=com', array('cn' => 'foo'));
     $this->assertEquals(6, count($testentries), "Init error: Expected count of test entries wrong, check test datasetup!");
     $testconf = $this->defaultConfig;
     $testconf['change'] = 1;
     //prepare some changes
     $testentries[0]->delete('attr1');
     // del whole attr
     $testentries[0]->delete(array('attr2' => 'baz'));
     // del spec. value
     $testentries[0]->delete(array('attr4', 'attr3' => 'bar'));
     // del mixed
     // prepare some replaces and adds
     $testentries[2]->replace(array('attr1' => 'newvaluefor1'));
     $testentries[2]->replace(array('attr2' => array('newvalue1for2', 'newvalue2for2')));
     $testentries[2]->replace(array('attr3' => ''));
     // will result in delete
     $testentries[2]->replace(array('newattr' => 'foo'));
     // will result in add
     // delete whole entry
     $testentries[3]->delete();
     // rename and move
     $testentries[4]->dn('cn=Bar,ou=example,dc=com');
     $testentries[5]->dn('cn=foobartest,ou=newexample,dc=com');
     // make sure we correctly get changes back from the API
     foreach ($testentries as $te) {
         $this->assertGreaterThanOrEqual(2, count($te->getChanges()), 'Probable BUG in Net_LDAP2_Entry detected! Changed entries do not report those changes back! (entry: ' . $te->dn() . ')');
     }
     // carry out write
     $ldif = new Net_LDAP2_LDIF($this->outfile, 'w', $testconf);
     $this->assertTrue(is_resource($ldif->handle()));
     $ldif->write_entry($testentries);
     $this->assertFalse((bool) $ldif->error(), 'Failed writing entry to ' . $this->outfile . ': ' . $ldif->error(true));
     $this->assertGreaterThan(0, filesize($this->outfile), "File '" . $this->outfile . "' is empty but should have content!");
     $ldif->done();
     // compare results
     $expected = array_map('conv_lineend', file(dirname(__FILE__) . '/ldif_data/changes.ldif'));
     // strip 4 starting lines because of comments in the file header:
     array_shift($expected);
     array_shift($expected);
     array_shift($expected);
     array_shift($expected);
     $writtenFileContents = array_map('conv_lineend', file($this->outfile));
     $this->assertEquals($expected, $writtenFileContents, "Written file does not equal expected contents (" . realpath($this->outfile) . ")");
 }