Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a8c9b1b

Browse files
committed
[Asset] added some tests
1 parent 5d56cd2 commit a8c9b1b

File tree

6 files changed

+295
-0
lines changed

6 files changed

+295
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Asset\Tests;
13+
14+
use Symfony\Component\Asset\Package;
15+
16+
class PackageTest extends \PHPUnit_Framework_TestCase
17+
{
18+
/**
19+
* @dataProvider getConfigs
20+
*/
21+
public function testGetUrl($version, $format, $path, $expected)
22+
{
23+
$package = new Package($version, $format);
24+
$this->assertEquals($expected, $package->getUrl($path));
25+
}
26+
27+
public function getConfigs()
28+
{
29+
return array(
30+
array('v1', '', 'http://example.com/foo', 'http://example.com/foo'),
31+
array('v1', '', 'https://example.com/foo', 'https://example.com/foo'),
32+
array('v1', '', '//example.com/foo', '//example.com/foo'),
33+
34+
array('v1', '', '/foo', '/foo?v1'),
35+
array('v1', '', 'foo', 'foo?v1'),
36+
37+
array('', '', '/foo', '/foo'),
38+
array('', '', 'foo', 'foo'),
39+
40+
array('v1', 'version-%2$s/%1$s', '/foo', '/version-v1/foo'),
41+
array('v1', 'version-%2$s/%1$s', 'foo', 'version-v1/foo'),
42+
array('v1', 'version-%2$s/%1$s', 'foo/', 'version-v1/foo/'),
43+
array('v1', 'version-%2$s/%1$s', '/foo/', '/version-v1/foo/'),
44+
);
45+
}
46+
47+
public function testGetUrlWithSpecificVersion()
48+
{
49+
$package = new Package('v1');
50+
$this->assertEquals('/foo?v2', $package->getUrl('/foo', 'v2'));
51+
}
52+
53+
public function testGetVersion()
54+
{
55+
$package = new Package('v1');
56+
$this->assertEquals('v1', $package->getVersion());
57+
}
58+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Asset\Tests;
13+
14+
use Symfony\Component\Asset\PathPackage;
15+
16+
class PathPackageTest extends \PHPUnit_Framework_TestCase
17+
{
18+
/**
19+
* @dataProvider getConfigs
20+
*/
21+
public function testGetUrl($basePath, $format, $path, $expected)
22+
{
23+
$package = new PathPackage($basePath, 'v1', $format);
24+
$this->assertEquals($expected, $package->getUrl($path));
25+
}
26+
27+
public function getConfigs()
28+
{
29+
return array(
30+
array('/foo', '', 'http://example.com/foo', 'http://example.com/foo'),
31+
array('/foo', '', 'https://example.com/foo', 'https://example.com/foo'),
32+
array('/foo', '', '//example.com/foo', '//example.com/foo'),
33+
34+
array('/foo', '', '/foo', '/foo?v1'),
35+
array('/foo', '', 'foo', '/foo/foo?v1'),
36+
array('foo', '', 'foo', '/foo/foo?v1'),
37+
array('foo/', '', 'foo', '/foo/foo?v1'),
38+
array('/foo/', '', 'foo', '/foo/foo?v1'),
39+
40+
array('/foo', 'version-%2$s/%1$s', '/foo', '/version-v1/foo'),
41+
array('/foo', 'version-%2$s/%1$s', 'foo', '/foo/version-v1/foo'),
42+
array('/foo', 'version-%2$s/%1$s', 'foo/', '/foo/version-v1/foo/'),
43+
array('/foo', 'version-%2$s/%1$s', '/foo/', '/version-v1/foo/'),
44+
);
45+
}
46+
47+
public function testGetUrlWithSpecificVersion()
48+
{
49+
$package = new PathPackage('v1');
50+
$this->assertEquals('/foo?v2', $package->getUrl('/foo', 'v2'));
51+
}
52+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Asset\Tests;
13+
14+
use Symfony\Component\Asset\RequestPathPackage;
15+
16+
class RequestPathPackageTest extends \PHPUnit_Framework_TestCase
17+
{
18+
/**
19+
* @dataProvider getConfigs
20+
*/
21+
public function testGetUrl($basePathRequest, $basePath, $format, $path, $expected)
22+
{
23+
$package = new RequestPathPackage($this->getRequestStack($basePathRequest), $basePath, 'v1', $format);
24+
$this->assertEquals($expected, $package->getUrl($path));
25+
}
26+
27+
public function getConfigs()
28+
{
29+
return array(
30+
array('', '/foo', '', '/foo', '/foo?v1'),
31+
array('', '/foo', '', 'foo', '/foo/foo?v1'),
32+
array('', 'foo', '', 'foo', '/foo/foo?v1'),
33+
array('', 'foo/', '', 'foo', '/foo/foo?v1'),
34+
array('', '/foo/', '', 'foo', '/foo/foo?v1'),
35+
36+
array('/bar', '/foo', '', '/foo', '/foo?v1'),
37+
array('/bar', '/foo', '', 'foo', '/bar/foo/foo?v1'),
38+
array('/bar', 'foo', '', 'foo', '/bar/foo/foo?v1'),
39+
array('/bar', 'foo/', '', 'foo', '/bar/foo/foo?v1'),
40+
array('/bar', '/foo/', '', 'foo', '/bar/foo/foo?v1'),
41+
);
42+
}
43+
44+
private function getRequestStack($basePath)
45+
{
46+
$request = $this->getMock('Symfony\Component\HttpFoundation\Request');
47+
$request->expects($this->any())->method('getBasePath')->will($this->returnValue($basePath));
48+
49+
$stack = $this->getMock('Symfony\Component\HttpFoundation\RequestStack');
50+
$stack->expects($this->any())->method('getCurrentRequest')->will($this->returnValue($request));
51+
52+
return $stack;
53+
}
54+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Asset\Tests;
13+
14+
use Symfony\Component\Asset\RequestUrlPackage;
15+
16+
class RequestUrlPackageTest extends \PHPUnit_Framework_TestCase
17+
{
18+
/**
19+
* @dataProvider getConfigs
20+
*/
21+
public function testGetUrl($secure, $basePath, $format, $path, $expected)
22+
{
23+
$package = new RequestUrlPackage($this->getRequestStack($secure), $basePath, 'v1', $format);
24+
$this->assertEquals($expected, $package->getUrl($path));
25+
}
26+
27+
public function getConfigs()
28+
{
29+
return array(
30+
array(false, 'http://example.com', '', 'foo', 'http://example.com/foo?v1'),
31+
array(false, array('http://example.com'), '', 'foo', 'http://example.com/foo?v1'),
32+
array(false, array('http://example.com', 'https://example.com'), '', 'foo', 'http://example.com/foo?v1'),
33+
array(false, array('http://example.com', 'https://example.com'), '', 'fooa', 'https://example.com/fooa?v1'),
34+
array(false, array('http://example.com/bar'), '', 'foo', 'http://example.com/bar/foo?v1'),
35+
array(false, array('http://example.com/bar/'), '', 'foo', 'http://example.com/bar/foo?v1'),
36+
array(false, array('//example.com/bar/'), '', 'foo', '//example.com/bar/foo?v1'),
37+
38+
array(true, array('http://example.com'), '', 'foo', 'http://example.com/foo?v1'),
39+
array(true, array('http://example.com', 'https://example.com'), '', 'foo', 'https://example.com/foo?v1'),
40+
);
41+
}
42+
43+
/**
44+
* @expectedException \LogicException
45+
*/
46+
public function testNoBaseUrls()
47+
{
48+
new RequestUrlPackage($this->getRequestStack(false), array());
49+
}
50+
51+
private function getRequestStack($secure)
52+
{
53+
$request = $this->getMock('Symfony\Component\HttpFoundation\Request');
54+
$request->expects($this->any())->method('isSecure')->will($this->returnValue($secure));
55+
56+
$stack = $this->getMock('Symfony\Component\HttpFoundation\RequestStack');
57+
$stack->expects($this->any())->method('getCurrentRequest')->will($this->returnValue($request));
58+
59+
return $stack;
60+
}
61+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Asset\Tests;
13+
14+
use Symfony\Component\Asset\UrlPackage;
15+
16+
class UrlPackageTest extends \PHPUnit_Framework_TestCase
17+
{
18+
/**
19+
* @dataProvider getConfigs
20+
*/
21+
public function testGetUrl($baseUrls, $format, $path, $expected)
22+
{
23+
$package = new UrlPackage($baseUrls, 'v1', $format);
24+
$this->assertEquals($expected, $package->getUrl($path));
25+
}
26+
27+
public function getConfigs()
28+
{
29+
return array(
30+
array('http://example.net', '', 'http://example.com/foo', 'http://example.com/foo'),
31+
array('http://example.net', '', 'https://example.com/foo', 'https://example.com/foo'),
32+
array('http://example.net', '', '//example.com/foo', '//example.com/foo'),
33+
34+
array('http://example.com', '', '/foo', 'http://example.com/foo?v1'),
35+
array('http://example.com', '', 'foo', 'http://example.com/foo?v1'),
36+
array('http://example.com/', '', 'foo', 'http://example.com/foo?v1'),
37+
array('http://example.com/foo', '', 'foo', 'http://example.com/foo/foo?v1'),
38+
array('http://example.com/foo/', '', 'foo', 'http://example.com/foo/foo?v1'),
39+
40+
array(array('http://example.com'), '', '/foo', 'http://example.com/foo?v1'),
41+
array(array('http://example.com', 'http://example.net'), '', '/foo', 'http://example.com/foo?v1'),
42+
array(array('http://example.com', 'http://example.net'), '', '/fooa', 'http://example.net/fooa?v1'),
43+
44+
array('http://example.com', 'version-%2$s/%1$s', '/foo', 'http://example.com/version-v1/foo'),
45+
array('http://example.com', 'version-%2$s/%1$s', 'foo', 'http://example.com/version-v1/foo'),
46+
array('http://example.com', 'version-%2$s/%1$s', 'foo/', 'http://example.com/version-v1/foo/'),
47+
array('http://example.com', 'version-%2$s/%1$s', '/foo/', 'http://example.com/version-v1/foo/'),
48+
);
49+
}
50+
51+
public function testGetUrlWithSpecificVersion()
52+
{
53+
$package = new UrlPackage('http://example.com');
54+
$this->assertEquals('http://example.com/foo?v2', $package->getUrl('/foo', 'v2'));
55+
}
56+
57+
/**
58+
* @expectedException \LogicException
59+
*/
60+
public function testNoBaseUrls()
61+
{
62+
new UrlPackage(array(), 'v1');
63+
}
64+
}

src/Symfony/Component/Asset/composer.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
"require": {
1919
"php": ">=5.3.3"
2020
},
21+
"suggest": {
22+
"symfony/http-foundation": ""
23+
},
24+
"require-dev": {
25+
"symfony/http-foundation": "~2.4"
26+
},
2127
"autoload": {
2228
"psr-0": { "Symfony\\Component\\Asset\\": "" }
2329
},

0 commit comments

Comments
 (0)