A legal ally of Donald Trump has testified to a New York court that is considering whether to approve charges against the former president over a hush-money payment to an adult actress.