Some tests for the patch in #1143. Finally!

Okay, I finally got round to writing the test cases for #1143. 

@tomchristie: can you review? — I made sure the current (and new) tests pass but there was talk of reordering the logic. If you comment here I'll adjust.