Port of #8623

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

Conflicts:
	apps/user_ldap/tests/wizard.php
fix wizard test, adjust to changed parameters of the tested method, introduced by 9caa354cfc1f73159f335646ca89be4db72b125e