Skip to content

Commit e082adc

Browse files
committed
Tests updated for {% embed %} tag processing.
an `{% embed %}` block has been added to the input.html.twig with an additional gettext call, this is now picked up when the file is scanned, and tests have been updated accordingly. The embed.html.twig file represents the embed template, it contains a gettext call, but it is not scanned automatically, instead it should be fed into gettext with all the other template files. This design choice was made in order to keep the scanner simple as it only operates on the tokens rather than a full graph of dependencies. In fact I think the parse function doesn't even check for it's existence when parsing the tokens.
1 parent 804e05e commit e082adc

File tree

5 files changed

+22
-2
lines changed

5 files changed

+22
-2
lines changed

tests/TimberFunctionsScannerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function testTwigFunctionsExtractor()
6262
$file = __DIR__ . '/assets/input.html.twig';
6363
$code = file_get_contents($file);
6464
$functions = $scanner->scan($code, $file);
65-
$this->assertCount(11, $functions);
65+
$this->assertCount(12, $functions);
6666

6767
// text 1
6868
$function = array_shift($functions);

tests/TimberScannerTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ public function testTwigCodeScanner()
3636
$scanner = new TimberScanner(Translations::create());
3737
list('' => $translations) = $this->initAndGetTranslations($scanner);
3838

39-
$this->assertCount(8, $translations);
39+
$this->assertCount(9, $translations);
4040
$this->assertCount(0, $translations->getHeaders());
4141

4242
$file = __DIR__ . '/assets/default-domain.po';
43+
// Note: This test can fail due to `git config core.autocrlf` converting line endings to CRLF
44+
// Double check any test error output for `#Warning: Strings contain different line endings!`
4345
$this->assertSame(
4446
file_get_contents($file),
4547
(new PoGenerator())->generateString($translations),
@@ -59,6 +61,8 @@ public function testTwigCodeScannerOtherDomains()
5961
$this->assertCount(1, $tr1);
6062
$this->assertCount(1, $tr1->getHeaders());
6163
$file1 = __DIR__ . '/assets/text-domain1.po';
64+
// Note: This test can fail due to `git config core.autocrlf` converting line endings to CRLF
65+
// Double check any test error output for `#Warning: Strings contain different line endings!`
6266
$this->assertSame(
6367
file_get_contents($file1),
6468
(new PoGenerator())->generateString($tr1),
@@ -68,6 +72,8 @@ public function testTwigCodeScannerOtherDomains()
6872
$this->assertCount(2, $tr2);
6973
$this->assertCount(1, $tr2->getHeaders());
7074
$file2 = __DIR__ . '/assets/text-domain2.po';
75+
// Note: This test can fail due to `git config core.autocrlf` converting line endings to CRLF
76+
// Double check any test error output for `#Warning: Strings contain different line endings!`
7177
$this->assertSame(
7278
file_get_contents($file2),
7379
(new PoGenerator())->generateString($tr2),

tests/assets/default-domain.po

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,7 @@ msgstr ""
3636
msgid "text 11 with plural"
3737
msgid_plural "The plural form"
3838
msgstr[0] ""
39+
40+
#: ./tests/assets/input.html.twig:26
41+
msgid "text 12 content inside a block in a embed template"
42+
msgstr ""

tests/assets/embed.html.twig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<div class="embedded-content">
2+
<h2>{{ __("text 13 header in the embed template, this should be scanned only if the file containing it is.") }}</h2>
3+
{% block main %}
4+
{% endblock %}
5+
</div>

tests/assets/input.html.twig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,8 @@
2121
</p>
2222
<p>
2323
</div>
24+
{% embed 'embed.html.twig' %}
25+
{% block main %}
26+
<p>{{ __("text 12 content inside a block in a embed template") }}</p>
27+
{% endblock %}
28+
{% endembed %}

0 commit comments

Comments
 (0)