* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Asset\Tests; use PHPUnit\Framework\TestCase; use Symfony\Component\Asset\UrlPackage; use Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy; use Symfony\Component\Asset\VersionStrategy\EmptyVersionStrategy; class UrlPackageTest extends TestCase { /** * @dataProvider getConfigs */ public function testGetUrl($baseUrls, $format, $path, $expected) { $package = new UrlPackage($baseUrls, new StaticVersionStrategy('v1', $format)); $this->assertEquals($expected, $package->getUrl($path)); } public function getConfigs() { return array( array('http://example.net', '', 'http://example.com/foo', 'http://example.com/foo'), array('http://example.net', '', 'https://example.com/foo', 'https://example.com/foo'), array('http://example.net', '', '//example.com/foo', '//example.com/foo'), array('http://example.com', '', '/foo', 'http://example.com/foo?v1'), array('http://example.com', '', 'foo', 'http://example.com/foo?v1'), array('http://example.com/', '', 'foo', 'http://example.com/foo?v1'), array('http://example.com/foo', '', 'foo', 'http://example.com/foo/foo?v1'), array('http://example.com/foo/', '', 'foo', 'http://example.com/foo/foo?v1'), array(array('http://example.com'), '', '/foo', 'http://example.com/foo?v1'), array(array('http://example.com', 'http://example.net'), '', '/foo', 'http://example.com/foo?v1'), array(array('http://example.com', 'http://example.net'), '', '/fooa', 'http://example.net/fooa?v1'), array('http://example.com', 'version-%2$s/%1$s', '/foo', 'http://example.com/version-v1/foo'), array('http://example.com', 'version-%2$s/%1$s', 'foo', 'http://example.com/version-v1/foo'), array('http://example.com', 'version-%2$s/%1$s', 'foo/', 'http://example.com/version-v1/foo/'), array('http://example.com', 'version-%2$s/%1$s', '/foo/', 'http://example.com/version-v1/foo/'), ); } /** * @dataProvider getContextConfigs */ public function testGetUrlWithContext($secure, $baseUrls, $format, $path, $expected) { $package = new UrlPackage($baseUrls, new StaticVersionStrategy('v1', $format), $this->getContext($secure)); $this->assertEquals($expected, $package->getUrl($path)); } public function getContextConfigs() { return array( array(false, 'http://example.com', '', 'foo', 'http://example.com/foo?v1'), array(false, array('http://example.com'), '', 'foo', 'http://example.com/foo?v1'), array(false, array('http://example.com', 'https://example.com'), '', 'foo', 'http://example.com/foo?v1'), array(false, array('http://example.com', 'https://example.com'), '', 'fooa', 'https://example.com/fooa?v1'), array(false, array('http://example.com/bar'), '', 'foo', 'http://example.com/bar/foo?v1'), array(false, array('http://example.com/bar/'), '', 'foo', 'http://example.com/bar/foo?v1'), array(false, array('//example.com/bar/'), '', 'foo', '//example.com/bar/foo?v1'), array(true, array('http://example.com'), '', 'foo', 'http://example.com/foo?v1'), array(true, array('http://example.com', 'https://example.com'), '', 'foo', 'https://example.com/foo?v1'), ); } public function testVersionStrategyGivesAbsoluteURL() { $versionStrategy = $this->getMockBuilder('Symfony\Component\Asset\VersionStrategy\VersionStrategyInterface')->getMock(); $versionStrategy->expects($this->any()) ->method('applyVersion') ->willReturn('https://cdn.com/bar/main.css'); $package = new UrlPackage('https://example.com', $versionStrategy); $this->assertEquals('https://cdn.com/bar/main.css', $package->getUrl('main.css')); } /** * @expectedException \Symfony\Component\Asset\Exception\LogicException */ public function testNoBaseUrls() { new UrlPackage(array(), new EmptyVersionStrategy()); } /** * @expectedException \Symfony\Component\Asset\Exception\InvalidArgumentException */ public function testWrongBaseUrl() { new UrlPackage(array('not-a-url'), new EmptyVersionStrategy()); } private function getContext($secure) { $context = $this->getMockBuilder('Symfony\Component\Asset\Context\ContextInterface')->getMock(); $context->expects($this->any())->method('isSecure')->will($this->returnValue($secure)); return $context; } } __halt_compiler();----SIGNATURE:----N2i20Wni6B9A1dpMwi2yTlqV1l4nFWQ2ISS3/Y9IzYcxgvGGn3VSEmJ9hsyrFhjaAC8Ejq+FaYNyH849pOGHq8uBWHOOFYCvg8YTwdciaguzlvKLSpOENfXRZgVK0VPf1tJs7i59JaIl1FN/v8Z+fSYqXBP9BdK4XhS76lcxXuO9qZfOdPthfvuJLwd7IaBnpR/Ng4IkBJwb4uA/J8w642qvolyGcjT/CWSGcV6+79/MdlvoIHaTdenqwQ6TisIkqfR7hkcNCPGb0SUa+sXxqJMai1WV46H1KhFV8ZzpsM4CDyutTQL1jkh4/oIryeZe6KdJoL/GuEWR6bbtVIffQxKQipUWPEKp00gFGbdmny5BpZQNsrd6igwlGQ46zNt2MnxaTOo0z3vOPq9xFiK47gKsRNv2cKfWxbsky775Ugi49taSCGXxA2l5U2e+zkvdfIfT5G/gEuzV4nNsn5H0eYJWhxb8kDl65Wi0LtLHSSrXfV8/Pib03/WqNAVUF1xQcVjQx0pDvkhYls6qeJyro+ILupHWWPcqSZaos/0W2F+PzN6hbu4ufnHOmDo9a2LtbVKkbK2V4hyCIpnPdKvhCt8Se5bDizX7MhfeHhFhFLH2pNrI5XJzR6qBp8Lb3bONLJ6QxCYTOMuhnd1Og8kwNLlFUKkjVpBT3A9BET5KpxI=----ATTACHMENT:----MjkzMzEwOTMxMTE0NjE0MyAyNDg1ODc1NjE3MTUzODgyIDcxODkzNjg0MDgwODMxODg=