create([
'name' => 'Test Plugin',
'markup_language' => 'liquid',
'render_markup' => <<<'LIQUID'
{% assign min = 1 %}
{% assign max = facts | size %}
{% assign diff = max | minus: min %}
{% assign randomNumber = "now" | date: "u" | modulo: diff | plus: min %}
{% template session %}
{{ facts[randomNumber] }}
{% endtemplate %}
{% template title_bar %}
{{ trmnl.plugin_settings.instance_name }}
{{ instance }}
{% endtemplate %}
{% render "session",
trmnl: trmnl,
facts: facts,
randomNumber: randomNumber,
size_mod: ""
%}
{% render "title_bar",
trmnl: trmnl,
instance: "Please try to enjoy each fact equally."
%}
LIQUID
,
'data_payload' => [
'facts' => ['Fact 1', 'Fact 2', 'Fact 3'],
],
]);
$result = $plugin->render('full');
// Should render both templates
// Check for any of the facts (since random number generation is non-deterministic)
$this->assertTrue(
str_contains($result, 'Fact 1') ||
str_contains($result, 'Fact 2') ||
str_contains($result, 'Fact 3')
);
$this->assertStringContainsString('Test Plugin', $result);
$this->assertStringContainsString('Please try to enjoy each fact equally', $result);
$this->assertStringContainsString('class="view view--full"', $result);
}
public function test_plugin_with_inline_templates_using_with_syntax(): void
{
$plugin = Plugin::factory()->create([
'name' => 'Test Plugin',
'markup_language' => 'liquid',
'render_markup' => <<<'LIQUID'
{% assign min = 1 %}
{% assign max = facts | size %}
{% assign diff = max | minus: min %}
{% assign randomNumber = "now" | date: "u" | modulo: diff | plus: min %}
{% template session %}
{{ facts[randomNumber] }}
{% endtemplate %}
{% template title_bar %}
{{ trmnl.plugin_settings.instance_name }}
{{ instance }}
{% endtemplate %}
{% render "session" with
trmnl: trmnl,
facts: facts,
randomNumber: randomNumber,
size_mod: ""
%}
{% render "title_bar" with
trmnl: trmnl,
instance: "Please try to enjoy each fact equally."
%}
LIQUID
,
'data_payload' => [
'facts' => ['Fact 1', 'Fact 2', 'Fact 3'],
],
]);
$result = $plugin->render('full');
// Should render both templates
// Check for any of the facts (since random number generation is non-deterministic)
$this->assertTrue(
str_contains($result, 'Fact 1') ||
str_contains($result, 'Fact 2') ||
str_contains($result, 'Fact 3')
);
$this->assertStringContainsString('Test Plugin', $result);
$this->assertStringContainsString('Please try to enjoy each fact equally', $result);
$this->assertStringContainsString('class="view view--full"', $result);
}
public function test_plugin_with_simple_inline_template(): void
{
$plugin = Plugin::factory()->create([
'markup_language' => 'liquid',
'render_markup' => <<<'LIQUID'
{% template simple %}
{{ title }}
{{ content }}
{% endtemplate %}
{% render "simple",
title: "Hello World",
content: "This is a test"
%}
LIQUID
,
]);
$result = $plugin->render('full');
$this->assertStringContainsString('Hello World', $result);
$this->assertStringContainsString('This is a test', $result);
$this->assertStringContainsString('class="simple"', $result);
}
}