Here and there we assume that we are running the tests on sample data. Would be nice to gradually remove such dependencies/assumptions.
Attached patches now mostly deal with hardcoded borrowernumbers or assuming 51 when there is no userenv.