Multivariate ranks and quantiles using optimal transport: Consistency, rates and nonparametric testing