MDL-32076 core_grade: fixed ajax handling of unlimited grades and added some unit tests