Fixed #23768 -- Rewrote template tests as unit tests

could you limit line length to 120 characters so horizontal scrolling isn't required in GitHub?
missing whitespace for: `{% autoescape on%}`