set result entry identifier earlier, i.e. before a continue for the same level can happen. otherwise  will always get the same value and we end up in an infinite loop
add unit test to make sure the infinite loop never comes back
Merge pull request #8623 from owncloud/fix-8457

LDAP: fix possible infinite loop, that causes hanging wizard, fixes #8457