Exemplo n.º 1
0
 public function testGetUrl()
 {
     $helper = new AssetsHelper();
     $this->assertEquals($helper->getUrl('http://example.com/foo.js'), 'http://example.com/foo.js', '->getUrl() does nothing if an absolute URL is given');
     $helper = new AssetsHelper();
     $this->assertEquals($helper->getUrl('foo.js'), '/foo.js', '->getUrl() appends a / on relative paths');
     $this->assertEquals($helper->getUrl('/foo.js'), '/foo.js', '->getUrl() does nothing on absolute paths');
     $helper = new AssetsHelper('/foo');
     $this->assertEquals($helper->getUrl('foo.js'), '/foo/foo.js', '->getUrl() appends the basePath on relative paths');
     $this->assertEquals($helper->getUrl('/foo.js'), '/foo.js', '->getUrl() does not append the basePath on absolute paths');
     $helper = new AssetsHelper(null, 'http://assets.example.com/');
     $this->assertEquals($helper->getUrl('foo.js'), 'http://assets.example.com/foo.js', '->getUrl() prepends the base URL');
     $this->assertEquals($helper->getUrl('/foo.js'), 'http://assets.example.com/foo.js', '->getUrl() prepends the base URL');
     $helper = new AssetsHelper(null, 'http://www.example.com/foo');
     $this->assertEquals($helper->getUrl('foo.js'), 'http://www.example.com/foo/foo.js', '->getUrl() prepends the base URL with a path');
     $this->assertEquals($helper->getUrl('/foo.js'), 'http://www.example.com/foo/foo.js', '->getUrl() prepends the base URL with a path');
     $helper = new AssetsHelper('/foo', 'http://www.example.com/');
     $this->assertEquals($helper->getUrl('foo.js'), 'http://www.example.com/foo/foo.js', '->getUrl() prepends the base URL and the base path if defined');
     $this->assertEquals($helper->getUrl('/foo.js'), 'http://www.example.com/foo.js', '->getUrl() prepends the base URL but not the base path on absolute paths');
     $helper = new AssetsHelper('/bar', 'http://www.example.com/foo');
     $this->assertEquals($helper->getUrl('foo.js'), 'http://www.example.com/foo/bar/foo.js', '->getUrl() prepends the base URL and the base path if defined');
     $this->assertEquals($helper->getUrl('/foo.js'), 'http://www.example.com/foo/foo.js', '->getUrl() prepends the base URL but not the base path on absolute paths');
     $helper = new AssetsHelper('/bar', 'http://www.example.com/foo', 'abcd');
     $this->assertEquals($helper->getUrl('foo.js'), 'http://www.example.com/foo/bar/foo.js?abcd', '->getUrl() appends the version if defined');
 }
 public function testMagicToString()
 {
     $assetHelper = new AssetsHelper();
     $assetHelper->setBaseURLs('');
     $helper = new StylesheetsHelper($assetHelper);
     $helper->add('foo', array('media' => 'ba>'));
     $this->assertEquals($helper->__toString(), '<link href="/foo" rel="stylesheet" type="text/css" media="ba&gt;" />' . "\n", '->__toString() converts the stylesheet configuration to HTML');
 }
 public function testMagicToString()
 {
     $assetHelper = new AssetsHelper();
     $assetHelper->setBaseURLs('');
     $helper = new JavascriptsHelper($assetHelper);
     $helper->add('foo', array('class' => 'ba>'));
     $this->assertEquals($helper->__toString(), '<script type="text/javascript" src="/foo" class="ba&gt;"></script>' . "\n", '->__toString() converts the JavaScript configuration to HTML');
 }
    $URLs[] = $helper->getBaseURL($i);
}
$URLs = array_values(array_unique($URLs));
sort($URLs);
$t->is($URLs, array('http://www1.example.com', 'http://www2.example.com'), '->getBaseURL() returns a random base URL if several are given');
$helper->setBaseURLs('');
$t->is($helper->getBaseURL(1), '', '->getBaseURL() returns an empty string if no base URL exist');
// ->getUrl()
$t->diag('->getUrl()');
$helper = new AssetsHelper();
$t->is($helper->getUrl('http://example.com/foo.js'), 'http://example.com/foo.js', '->getUrl() does nothing if an absolute URL is given');
$helper = new AssetsHelper();
$t->is($helper->getUrl('foo.js'), '/foo.js', '->getUrl() appends a / on relative paths');
$t->is($helper->getUrl('/foo.js'), '/foo.js', '->getUrl() does nothing on absolute paths');
$helper = new AssetsHelper('/foo');
$t->is($helper->getUrl('foo.js'), '/foo/foo.js', '->getUrl() appends the basePath on relative paths');
$t->is($helper->getUrl('/foo.js'), '/foo.js', '->getUrl() does not append the basePath on absolute paths');
$helper = new AssetsHelper(null, 'http://assets.example.com/');
$t->is($helper->getUrl('foo.js'), 'http://assets.example.com/foo.js', '->getUrl() prepends the base URL');
$t->is($helper->getUrl('/foo.js'), 'http://assets.example.com/foo.js', '->getUrl() prepends the base URL');
$helper = new AssetsHelper(null, 'http://www.example.com/foo');
$t->is($helper->getUrl('foo.js'), 'http://www.example.com/foo/foo.js', '->getUrl() prepends the base URL with a path');
$t->is($helper->getUrl('/foo.js'), 'http://www.example.com/foo/foo.js', '->getUrl() prepends the base URL with a path');
$helper = new AssetsHelper('/foo', 'http://www.example.com/');
$t->is($helper->getUrl('foo.js'), 'http://www.example.com/foo/foo.js', '->getUrl() prepends the base URL and the base path if defined');
$t->is($helper->getUrl('/foo.js'), 'http://www.example.com/foo.js', '->getUrl() prepends the base URL but not the base path on absolute paths');
$helper = new AssetsHelper('/bar', 'http://www.example.com/foo');
$t->is($helper->getUrl('foo.js'), 'http://www.example.com/foo/bar/foo.js', '->getUrl() prepends the base URL and the base path if defined');
$t->is($helper->getUrl('/foo.js'), 'http://www.example.com/foo/foo.js', '->getUrl() prepends the base URL but not the base path on absolute paths');
$helper = new AssetsHelper('/bar', 'http://www.example.com/foo', 'abcd');
$t->is($helper->getUrl('foo.js'), 'http://www.example.com/foo/bar/foo.js?abcd', '->getUrl() appends the version if defined');
Exemplo n.º 5
0
 /**
  * Constructor.
  *
  * @param Symfony\Components\HttpFoundation\Request $request A Request instance
  * @param string|array                              $baseURLs The domain URL or an array of domain URLs
  * @param string                                    $version  The version
  */
 public function __construct(Request $request, $baseURLs = array(), $version = null)
 {
     parent::__construct($request->getBasePath(), $baseURLs, $version);
 }