Create a wordpress test-system as a clone from productive system

In general test enviroments better use the same domain name as the live site. Since it doesn’t seem like you follow such pattern (and yes, it is harder to follow), you need to make sure you convert all the URLs in the DB properly, and the way you do it will fail with any data which is serialized. Use wp-cli to change URLs instead of re-inventing your own solution.

In addition you will probably will want to change the option or add some code to make sure that google do not try to index the test site.