1, '.mTest' => 'someString', '/path' => 'PATH', '#hash' => 'test', ]; self::assertTrue(UriFactory::setQuery('/valid2', 'query4')); $expected = 'www.test-uri.com?id=1&test=someString&two=PATH&hash=test#none&found=&v=query4'; self::assertEquals($expected, UriFactory::build($uri, $vars)); } #[\PHPUnit\Framework\Attributes\Group('framework')] #[\PHPUnit\Framework\Attributes\TestDox('The uri factory can be set up with default values from a url and build with these default values')] public function testSetupBuild() : void { $uri = 'http://www.test-uri.com/path/here?id=123&ab=c#fragi'; UriFactory::setupUriBuilder(new HttpUri($uri)); self::assertEquals($uri, UriFactory::build('{/tld}{/rootPath}{/}?id={?id}&ab={?ab}#{#}')); self::assertEquals($uri, UriFactory::build('{/scheme}://{/host}{/rootPath}{/}?id={?id}&ab={?ab}#{#}')); self::assertEquals($uri, UriFactory::build('{%}')); self::assertEquals($uri, UriFactory::build('{/tld}{/rootPath}{/}?{?}#{#}')); } #[\PHPUnit\Framework\Attributes\Group('framework')] #[\PHPUnit\Framework\Attributes\TestDox('In case of duplicated query elements the last element is used')] public function testDuplicatedQueryElements() : void { $uri = '/path/here?id=123&ab=c&id=456#fragi'; $expected = '/path/here?id=456&ab=c#fragi'; UriFactory::setupUriBuilder(new HttpUri($uri)); self::assertEquals($expected, UriFactory::build('{/base}{/rootPath}{/}?id={?id}&ab={?ab}#{#}')); } #[\PHPUnit\Framework\Attributes\Group('framework')] #[\PHPUnit\Framework\Attributes\TestDox('The uri variables can be unescaped')] public function testVariableUnescape() : void { $uri = '/path/here?id=123&ab=c#fragi'; $escaped = '{/base}{/rootPath}{/}?id=\{\?id\}&ab={?ab}#{#}'; $unescaped = '/path/here?id={?id}&ab=c#fragi'; UriFactory::setupUriBuilder(new HttpUri($uri)); self::assertEquals($unescaped, UriFactory::build($escaped)); } #[\PHPUnit\Framework\Attributes\Group('framework')] #[\PHPUnit\Framework\Attributes\TestDox('In case of missing ? for query the builder automatically fixes it')] public function testMissingQueryIdentifier() : void { $uri = '/path/here?id=123&ab=c#fragi'; UriFactory::setupUriBuilder(new HttpUri($uri)); self::assertEquals($uri, UriFactory::build('{/base}{/rootPath}{/}&id={?id}&ab={?ab}#{#}')); } #[\PHPUnit\Framework\Attributes\Group('framework')] #[\PHPUnit\Framework\Attributes\TestDox('A normal url will not be changed')] public function testNormalUrlParsing() : void { $uri = 'http://www.test-uri.com/path/here?id=123&ab=c#fragi'; $expected = 'http://www.test-uri.com/path/here?id=123&ab=c#fragi'; self::assertEquals($expected, UriFactory::build($uri)); } }