[T4] Add unit test for #24659 and fix existing unit tests.