[1.7.x] Fixed #23352 -- Added tests for MigrationGraph.{forwards,backwards}_plan

Backport of be4baaefe2 from master