In the play, Portia's father designs the casket test in his will as a way to exert influence on the choice of Portia's suitor even after his death. It is designed so that Portia will marry the suitor who values her for herself.
Shakespeare took the story of the the three caskets from a well-known folk tale. Other writers who had used it before him were John Gower in Confessio amantis, Boccaccio in The Decameron, and the anonymous author of Gesta Romanorum.
Shakespeare combined at least two folk-tale motifs with details from several other sources to create his play.
The casket scene was officially designed by Portia's father, This states that Portia would get a chance to marry whoever selects the correct casket. yes it is true that Portia's freedom is restricted, but however it proves to be a smart move by the father,