Added tests for group sharing functionality.

And of course the changes for the bugs that the tests picked up.

Also exposed the clearUserProfile method in the API test case so it can
be specialised for examples such as these where further tables have been
added.