Add counter cache test for class_name

Backport tests from #14410 to master.

@chancancode @rafaelfranca