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

Backports of eaf4ed0 from master