Rate optimal estimation of quadratic functionals in inverse problems with partially unknown operator and application to testing problems