From bc16ce66a0290bc518d8613380ddf1146f9f9cc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20L=C3=B8vgaard?= Date: Tue, 30 Jun 2020 14:58:11 +0200 Subject: [PATCH] Added gtag library --- src/Tag/Gtag.php | 1 + src/Tag/GtagConfig.php | 1 + src/Tag/GtagEvent.php | 1 + src/Tag/GtagLibrary.php | 20 ++++++++ src/Tag/GtagSet.php | 2 + src/templates/SetonoTagBagGtag/library.php | 6 +++ tests/Tag/GtagLibraryTest.php | 58 ++++++++++++++++++++++ 7 files changed, 89 insertions(+) create mode 100644 src/Tag/GtagLibrary.php create mode 100644 src/templates/SetonoTagBagGtag/library.php create mode 100644 tests/Tag/GtagLibraryTest.php diff --git a/src/Tag/Gtag.php b/src/Tag/Gtag.php index 81cae49..0405a88 100644 --- a/src/Tag/Gtag.php +++ b/src/Tag/Gtag.php @@ -13,6 +13,7 @@ public function __construct(string $template, array $parameters = []) { parent::__construct($template); + $this->setName('setono_tag_bag_gtag'); $this->parameters = $parameters; } diff --git a/src/Tag/GtagConfig.php b/src/Tag/GtagConfig.php index 433cb8b..e429f88 100644 --- a/src/Tag/GtagConfig.php +++ b/src/Tag/GtagConfig.php @@ -13,6 +13,7 @@ public function __construct(string $target, array $parameters = []) { parent::__construct('@SetonoTagBagGtag/config', $parameters); + $this->setName('setono_tag_bag_gtag_config'); $this->target = $target; } diff --git a/src/Tag/GtagEvent.php b/src/Tag/GtagEvent.php index d096d39..40a75d3 100644 --- a/src/Tag/GtagEvent.php +++ b/src/Tag/GtagEvent.php @@ -13,6 +13,7 @@ public function __construct(string $event, array $parameters = []) { parent::__construct('@SetonoTagBagGtag/event', $parameters); + $this->setName('setono_tag_bag_gtag_event'); $this->event = $event; } diff --git a/src/Tag/GtagLibrary.php b/src/Tag/GtagLibrary.php new file mode 100644 index 0000000..6396538 --- /dev/null +++ b/src/Tag/GtagLibrary.php @@ -0,0 +1,20 @@ + $id, + ]); + + $this->setName(self::NAME); + $this->setUnique(true); + } +} diff --git a/src/Tag/GtagSet.php b/src/Tag/GtagSet.php index 0eb5f6a..53a4ee7 100644 --- a/src/Tag/GtagSet.php +++ b/src/Tag/GtagSet.php @@ -9,5 +9,7 @@ class GtagSet extends Gtag implements GtagSetInterface public function __construct(array $parameters) { parent::__construct('@SetonoTagBagGtag/set', $parameters); + + $this->setName('setono_tag_bag_gtag_set'); } } diff --git a/src/templates/SetonoTagBagGtag/library.php b/src/templates/SetonoTagBagGtag/library.php new file mode 100644 index 0000000..5a61dc9 --- /dev/null +++ b/src/templates/SetonoTagBagGtag/library.php @@ -0,0 +1,6 @@ + + diff --git a/tests/Tag/GtagLibraryTest.php b/tests/Tag/GtagLibraryTest.php new file mode 100644 index 0000000..15cd580 --- /dev/null +++ b/tests/Tag/GtagLibraryTest.php @@ -0,0 +1,58 @@ +assertInstanceOf(TagInterface::class, $tag); + $this->assertInstanceOf(PhpTemplatesTagInterface::class, $tag); + } + + /** + * @test + */ + public function it_has_default_values(): void + { + $tag = new GtagLibrary('id'); + + $this->assertSame('@SetonoTagBagGtag/library', $tag->getTemplate()); + } + + /** + * @test + */ + public function it_renders_with_parameters(): void + { + $tag = new GtagLibrary('id'); + + $renderer = new PhpTemplatesRenderer(new Engine([__DIR__ . '/../../src/templates'])); + + $expected = << + + +SCRIPT; + + $this->assertTrue($renderer->supports($tag)); + $this->assertSame($expected, $renderer->render($tag)); + } +}