-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
100 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
/* | ||
* (c) Christian Gripp <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Nucleos\MatomoBundle\Twig\Runtime; | ||
|
||
use Twig\Environment; | ||
use Twig\Extension\RuntimeExtensionInterface; | ||
|
||
final class MatomoRuntime implements RuntimeExtensionInterface | ||
{ | ||
/** | ||
* @param array<string, mixed> $options | ||
*/ | ||
public function renderTracker(Environment $environment, array $options = []): string | ||
{ | ||
$data = array_merge([ | ||
'site_id' => null, | ||
'matomo_host' => 'localhost', | ||
'cookie_domain' => null, | ||
], $options); | ||
|
||
if (null === $data['site_id']) { | ||
return ''; | ||
} | ||
|
||
return $environment->render('@NucleosMatomo/tracker_code.html.twig', $data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* (c) Christian Gripp <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Nucleos\MatomoBundle\Tests\Twig\Runtime; | ||
|
||
use Nucleos\MatomoBundle\Twig\Runtime\MatomoRuntime; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
use Twig\Environment; | ||
|
||
final class MatomoRuntimeTest extends TestCase | ||
{ | ||
/** | ||
* @var Environment&MockObject | ||
*/ | ||
private Environment $environment; | ||
|
||
private MatomoRuntime $runtime; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->environment = $this->createMock(Environment::class); | ||
$this->runtime = new MatomoRuntime(); | ||
} | ||
|
||
public function testRenderTracker(): void | ||
{ | ||
$this->environment->method('render')->with('@NucleosMatomo/tracker_code.html.twig', [ | ||
'site_id' => 13, | ||
'matomo_host' => 'localhost', | ||
'cookie_domain' => null, | ||
]) | ||
->willReturn('HTML CONTENT') | ||
; | ||
|
||
static::assertSame('HTML CONTENT', $this->runtime->renderTracker($this->environment, [ | ||
'site_id' => 13, | ||
])); | ||
} | ||
|
||
public function testRenderTrackerWithoutSiteId(): void | ||
{ | ||
$this->environment->expects(static::never())->method('render'); | ||
|
||
static::assertSame('', $this->runtime->renderTracker($this->environment)); | ||
} | ||
} |