2018-08-26 12:23:47 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Engelsystem\Test\Unit\Renderer\Twig\Extensions;
|
|
|
|
|
|
|
|
use Engelsystem\Http\UrlGenerator;
|
|
|
|
use Engelsystem\Renderer\Twig\Extensions\Url;
|
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
|
|
|
|
|
|
|
class UrlTest extends ExtensionTest
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @covers \Engelsystem\Renderer\Twig\Extensions\Url::__construct
|
|
|
|
* @covers \Engelsystem\Renderer\Twig\Extensions\Url::getFunctions
|
|
|
|
*/
|
2022-12-14 19:15:20 +01:00
|
|
|
public function testGetGlobals(): void
|
2018-08-26 12:23:47 +02:00
|
|
|
{
|
|
|
|
/** @var UrlGenerator|MockObject $urlGenerator */
|
|
|
|
$urlGenerator = $this->createMock(UrlGenerator::class);
|
|
|
|
|
|
|
|
$extension = new Url($urlGenerator);
|
|
|
|
$functions = $extension->getFunctions();
|
|
|
|
|
|
|
|
$this->assertExtensionExists('url', [$extension, 'getUrl'], $functions);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string[][]
|
|
|
|
*/
|
2022-12-14 19:15:20 +01:00
|
|
|
public function getUrls(): array
|
2018-08-26 12:23:47 +02:00
|
|
|
{
|
|
|
|
return [
|
|
|
|
['/', '/', 'http://foo.bar/'],
|
|
|
|
['/foo', '/foo', 'http://foo.bar/foo'],
|
|
|
|
['foo_bar', 'foo-bar', 'http://foo.bar/foo-bar'],
|
|
|
|
['dolor', 'dolor', 'http://foo.bar/dolor?lorem_ipsum=dolor', ['lorem_ipsum' => 'dolor']],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider getUrls
|
|
|
|
*
|
2022-12-15 20:20:33 +01:00
|
|
|
* @covers \Engelsystem\Renderer\Twig\Extensions\Url::getUrl
|
2018-08-26 12:23:47 +02:00
|
|
|
*/
|
2022-12-14 19:15:20 +01:00
|
|
|
public function testGetUrl(string $url, string $urlTo, string $return, array $parameters = []): void
|
2018-08-26 12:23:47 +02:00
|
|
|
{
|
|
|
|
/** @var UrlGenerator|MockObject $urlGenerator */
|
|
|
|
$urlGenerator = $this->createMock(UrlGenerator::class);
|
|
|
|
|
|
|
|
$urlGenerator->expects($this->once())
|
|
|
|
->method('to')
|
|
|
|
->with($urlTo, $parameters)
|
|
|
|
->willReturn($return);
|
|
|
|
|
|
|
|
$extension = new Url($urlGenerator);
|
|
|
|
$generatedUrl = $extension->getUrl($url, $parameters);
|
|
|
|
|
|
|
|
$this->assertEquals($return, $generatedUrl);
|
|
|
|
}
|
|
|
|
}
|