Ticket 21530

This adds tests to the pull request adds tests to #2007.

There are two commits to make it easy to demonstrate that there is a failing test, which is fixed by the suggested patch. I can squash to a single commit if required.