3 namespace Drupal\system\Tests\Theme;
5 use Drupal\simpletest\WebTestBase;
8 * Tests Drupal's Twig filters.
12 class TwigFilterTest extends WebTestBase {
19 public static $modules = ['twig_theme_test'];
22 * Test Twig "without" filter.
24 public function testTwigWithoutFilter() {
26 '#theme' => 'twig_theme_test_filter',
28 'content' => ['#markup' => 'You can only find truth with logic if you have already found truth without it.'],
29 'author' => ['#markup' => 'Gilbert Keith Chesterton'],
30 'date' => ['#markup' => '1874-1936'],
35 'class' => ['red', 'green', 'blue'],
38 $rendered = \Drupal::service('renderer')->renderRoot($filter_test);
39 $this->setRawContent($rendered);
43 'expected' => '<div><strong>No author:</strong> You can only find truth with logic if you have already found truth without it.1874-1936.</div>',
44 'message' => '"No author" was successfully rendered.',
47 'expected' => '<div><strong>Complete quote after without:</strong> You can only find truth with logic if you have already found truth without it.Gilbert Keith Chesterton1874-1936.</div>',
48 'message' => '"Complete quote after without" was successfully rendered.',
51 'expected' => '<div><strong>Only author:</strong> Gilbert Keith Chesterton.</div>',
52 'message' => '"Only author:" was successfully rendered.',
55 'expected' => '<div><strong>No author or date:</strong> You can only find truth with logic if you have already found truth without it..</div>',
56 'message' => '"No author or date" was successfully rendered.',
59 'expected' => '<div><strong>Only date:</strong> 1874-1936.</div>',
60 'message' => '"Only date" was successfully rendered.',
63 'expected' => '<div><strong>Complete quote again for good measure:</strong> You can only find truth with logic if you have already found truth without it.Gilbert Keith Chesterton1874-1936.</div>',
64 'message' => '"Complete quote again for good measure" was successfully rendered.',
67 'expected' => '<div><strong>Marked-up:</strong>
69 <p>You can only find truth with logic if you have already found truth without it.</p>
71 – <cite><a href="#">Gilbert Keith Chesterton</a> <em>(1874-1936)</em></cite>
74 'message' => '"Marked-up quote" was successfully rendered.',
77 'expected' => '<div><span id="quotes" checked class="red green blue">All attributes:</span></div>',
78 'message' => 'All attributes printed.',
81 'expected' => '<div><span class="red green blue" id="quotes" checked>Class attributes in front, remainder at the back:</span></div>',
82 'message' => 'Class attributes printed in the front, the rest in the back.',
85 'expected' => '<div><span id="quotes" checked data-class="red green blue">Class attributes in back, remainder at the front:</span></div>',
86 'message' => 'Class attributes printed in the back, the rest in the front.',
89 'expected' => '<div><span class="red green blue">Class attributes only:</span></div>',
90 'message' => 'Class attributes only printed.',
93 'expected' => '<div><span checked id="quotes" class="red green blue">Without boolean attribute.</span></div>',
94 'message' => 'Boolean attribute printed in the front.',
97 'expected' => '<div><span data-id="quotes" checked class="red green blue">Without string attribute.</span></div>',
98 'message' => 'Without string attribute in the front.',
101 'expected' => '<div><span checked>Without id and class attributes.</span></div>',
102 'message' => 'Attributes printed without id and class attributes.',
105 'expected' => '<div><span id="quotes" checked class="red green blue">All attributes again.</span></div>',
106 'message' => 'All attributes printed again.',
109 'expected' => '<div id="quotes-here"><span class="gray-like-a-bunny bem__ized--top-feature" id="quotes-here">ID and class. Having the same ID twice is not valid markup but we want to make sure the filter doesn\'t use \Drupal\Component\Utility\Html::getUniqueId().</span></div>',
110 'message' => 'Class and ID filtered.',
113 'expected' => '<div><strong>Rendered author string length:</strong> 24.</div>',
114 'message' => 'Render filter string\'s length.',
118 foreach ($elements as $element) {
119 $this->assertRaw($element['expected'], $element['message']);