setExpectedException(LAMException::class, 'this is no LDIF'); $importer = new Importer(); $importer->getTasks($lines); } /** * Wrong format version. */ public function testWrongVersion() { $lines = array( "version: 3" ); $this->setExpectedException(LAMException::class, 'version: 3'); $importer = new Importer(); $importer->getTasks($lines); } /** * Multiple versions. */ public function testMultipleVersions() { $lines = array( "version: 1", "", "version: 1" ); $this->setExpectedException(LAMException::class); $importer = new Importer(); $importer->getTasks($lines); } /** * Data after version. */ public function testDataAfterVersion() { $lines = array( "version: 1", "some: data" ); $this->setExpectedException(LAMException::class); $importer = new Importer(); $importer->getTasks($lines); } /** * DN line without any data. */ public function testDnNoData() { $lines = array( "version: 1", "", "dn: uid=test,dc=example,dc=com" ); $this->setExpectedException(LAMException::class, 'dn: uid=test,dc=example,dc=com'); $importer = new Importer(); $importer->getTasks($lines); } /** * One complete entry. */ public function testSingleFullEntry() { $lines = array( "version: 1", "", "dn: uid=test,dc=example,dc=com", "objectClass: inetOrgPerson", "uid: test", ); $importer = new Importer(); $tasks = $importer->getTasks($lines); $this->assertEquals(1, sizeof($tasks)); } /** * Change entry with invalid changetype. */ public function testChangeInvalidType() { $lines = array( "version: 1", "", "dn: uid=test,dc=example,dc=com", "changeType: invalid", "uid: test", ); $this->setExpectedException(LAMException::class, 'uid=test,dc=example,dc=com - changeType: invalid'); $importer = new Importer(); $tasks = $importer->getTasks($lines); } /** * Change entry with add changetype. */ public function testChangeAdd() { $lines = array( "version: 1", "", "dn: uid=test,dc=example,dc=com", "changeType: add", "uid: test", ); $importer = new Importer(); $tasks = $importer->getTasks($lines); $this->assertEquals(1, sizeof($tasks)); $task = $tasks[0]; $this->assertEquals(AddEntryTask::class, get_class($task)); } /** * Change entry with modrdn changetype and invalid options. */ public function testChangeModRdnInvalidData() { $lines = array( "version: 1", "", "dn: uid=test,dc=example,dc=com", "changeType: modrdn", "uid: test", ); $this->setExpectedException(LAMException::class, 'uid=test,dc=example,dc=com'); $importer = new Importer(); $tasks = $importer->getTasks($lines); } /** * Change entry with modrdn changetype and invalid deleteoldrdn. */ public function testChangeModRdnInvalidDeleteoldrdn() { $lines = array( "version: 1", "", "dn: uid=test,dc=example,dc=com", "changeType: modrdn", "newrdn: uid1=test", "deleteoldrdn: x", ); $this->setExpectedException(LAMException::class, 'uid=test,dc=example,dc=com'); $importer = new Importer(); $tasks = $importer->getTasks($lines); } /** * Change entry with modrdn changetype. */ public function testChangeModRdn() { $lines = array( "version: 1", "", "dn: uid=test,dc=example,dc=com", "changeType: modrdn", "newrdn: uid1=test", "deleteoldrdn: 0", ); $importer = new Importer(); $tasks = $importer->getTasks($lines); $this->assertEquals(1, sizeof($tasks)); $task = $tasks[0]; $this->assertEquals(RenameEntryTask::class, get_class($task)); } /** * Change entry with delete changetype with extra line. */ public function testChangeDeleteInvalid() { $lines = array( "version: 1", "", "dn: uid=test,dc=example,dc=com", "changeType: delete", "uid: test", ); $this->setExpectedException(LAMException::class, 'uid=test,dc=example,dc=com'); $importer = new Importer(); $tasks = $importer->getTasks($lines); } /** * Change entry with delete changetype. */ public function testChangeDelete() { $lines = array( "version: 1", "", "dn: uid=test,dc=example,dc=com", "changeType: delete", ); $importer = new Importer(); $tasks = $importer->getTasks($lines); $this->assertEquals(1, sizeof($tasks)); $task = $tasks[0]; $this->assertEquals(DeleteEntryTask::class, get_class($task)); } }