If the court ordered a drug test, quite obviously she cannot refuse that test without potentially severe consequences. Frankly, if she's asking you for help and you can't figure out that much on your own, you should tell her that you don't have a clue about custody proceedings and that she should consult a lawyer. I mean no offense, but ignorance is dangerous in court.

Tell her to find a lawyer and work with a lawyer.