Todo
* Update documentation in settings.php to warn that enabling twig_debug mode will break tests.
Original issue description
I don't think is is necessarily a bug as such, but automated tests that perform assertions directly against rendered HTML will fail when Twig debug mode is enabled. This is because the debug mode wraps the output of each Twig template with HTML comments containing debug information, so while the element is still intact and correct, performing a direct comparison against known good HTML will fail.
For example, this small test fragment fails when debug mode is on, even though the output is displayed correctly to the user
$img_tag = theme('image_style', $variables);
$this->assertEqual($img_tag, '<img class="image-style-test" src="' . $url . '" width="120" height="60" alt="" />');In an ideal world, tests shouldn't be doing assertions against HTML strings IMO, but since that's not a fight I want to get into I suggest adding a note to the documentation in default.settings.php that warns of potential false failures when debug mode is enabled.
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | drupal-twig_debug_markup_tests_doc_note-1971860-14.patch | 770 bytes | arh1 |
| #4 | drupal-twig_debug_markup_tests_doc_note-1971860-4.patch | 779 bytes | arh1 |
Comments
Comment #1
star-szrFrom #1898458-22: theme_test.module - Convert PHPTemplate templates to Twig:
Need to think about this some more but it might work.
Comment #2
fabianx commentedTagging
Comment #2.0
fabianx commentedfix typo
Comment #3
fabianx commentedTagging with novice and documentation.
Comment #4
arh1 commentedHere's a patch to add documentation about this issue.
Comment #5
arh1 commentedComment #7
mariafromatoz commented#4: drupal-twig_debug_markup_tests_doc_note-1971860-4.patch queued for re-testing.
Comment #8
fabianx commentedLooks good to me!
Comment #9
star-szrComment #10
alexpottComment #11
jhodgdonCould we perhaps make the wording of this a bit better? It currently says:
It seems a bit odd to me... I don't think that we "make tests against" anything (we make test assertions about stuff, and we compare values in tests), and I don't think that we "perform" tests (we run them).
Comment #12
alexander_danilenko commentedLooks good. I am not english native speaker but it is good to understand
Comment #13
jhodgdonAs a native speaker of English, I found it very awkward.... How about:
Comment #14
arh1 commentedThat wording sounds fine to me. Updated patch attached.
Comment #15
jhodgdonOK, thanks! I'll get that committed shortly.
Comment #16
jhodgdonThanks again! Committed to 8.x.
Comment #17.0
(not verified) commentedUpdated issue summary.