Welcome to e health forum.
The test advised by your doctor is probably a defecography also called MRI Defecating proctogram. This is a test used to diagnose pelvic floor dysfunction or slow transit constipation. Any form of obstructive lesions or incomplete defecation, due to weakness of the musculature (pelvic floor) will be detected by this testing modality.
In this procedure, your rectum will be filled with a soft paste (Barium contrast) with the same consistency as stool. As you expel the paste, MRI images are taken to evaluate the completeness of stool elimination and rectal muscle contractions.
You will be asked to lie on the MRI scanner and a small tube will be inserted into your bottom to allow a small quantity of a special gel to be put into the rectum. The tube will be removed and you will be asked to lie on your back. You will then be asked to clench, relax and strain while pictures are taken. You may feel worried that this is a little undignified but please be reassured that the technicians and staff will do their best to ensure your privacy at all times.
In total the procedure takes about 20 minutes and is completely painless.
I hope this helps.