|
1
|
|
|
<?php |
|
2
|
|
|
namespace Evheniy\JqueryBundle\Tests\Controller; |
|
3
|
|
|
|
|
4
|
|
|
use Assetic\Extension\Twig\AsseticExtension; |
|
5
|
|
|
use Assetic\Factory\AssetFactory; |
|
6
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
7
|
|
|
use Evheniy\JqueryBundle\Twig\JqueryExtension; |
|
8
|
|
|
use Evheniy\JqueryBundle\DependencyInjection\JqueryExtension as JqueryExtensionDI; |
|
9
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class DefaultControllerTest |
|
13
|
|
|
* |
|
14
|
|
|
* @package Evheniy\JqueryBundle\Tests\Controller |
|
15
|
|
|
*/ |
|
16
|
|
|
class DefaultControllerTest extends WebTestCase |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* |
|
20
|
|
|
*/ |
|
21
|
|
|
protected function getTwig(array $data) |
|
22
|
|
|
{ |
|
23
|
|
|
$twig = new \Twig_Environment( |
|
24
|
|
|
new \Twig_Loader_Array( |
|
25
|
|
|
array('JqueryBundle:Jquery:jquery.html.twig' => file_get_contents(dirname(__FILE__) . '/../../Resources/views/Jquery/jquery.html.twig')) |
|
26
|
|
|
) |
|
27
|
|
|
); |
|
28
|
|
|
$container = new ContainerBuilder(); |
|
29
|
|
|
$extension = new JqueryExtensionDI(); |
|
30
|
|
|
$extension->load($data, $container); |
|
31
|
|
|
$twig ->addExtension(new AsseticExtension(new AssetFactory(dirname(__FILE__) . '/'))); |
|
32
|
|
|
$twig ->addExtension(new JqueryExtension($container)); |
|
33
|
|
|
|
|
34
|
|
|
return $twig; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* |
|
39
|
|
|
*/ |
|
40
|
|
|
public function testWithCdn() |
|
41
|
|
|
{ |
|
42
|
|
|
$this->assertRegExp('/src=\"\/\/cdn\.site\.comjs\/jquery-1.11.3.min.js\"/', $this->getTwig(array(array('cdn' => 'cdn.site.com')))->render('JqueryBundle:Jquery:jquery.html.twig')); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* |
|
47
|
|
|
*/ |
|
48
|
|
|
public function testWithOutCdn() |
|
49
|
|
|
{ |
|
50
|
|
|
$this->assertRegExp('/src=\"js\/jquery-1.11.3.min\.js\"/', $this->getTwig(array(array()))->render('JqueryBundle:Jquery:jquery.html.twig')); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* |
|
55
|
|
|
*/ |
|
56
|
|
|
public function testFileCDN() |
|
57
|
|
|
{ |
|
58
|
|
|
$client = static::createClient(); |
|
59
|
|
|
$jquery = $client->getContainer()->getParameter('jquery'); |
|
60
|
|
|
$headers = get_headers('http://ajax.googleapis.com/ajax/libs/jquery/' . $jquery['version'] . '/jquery.min.js'); |
|
61
|
|
|
$this->assertTrue(strpos($headers[0], '200') !== false); |
|
62
|
|
|
$headers = get_headers('https://ajax.googleapis.com/ajax/libs/jquery/' . $jquery['version'] . '/jquery.min.js'); |
|
63
|
|
|
$this->assertTrue(strpos($headers[0], '200') !== false); |
|
64
|
|
|
} |
|
65
|
|
|
} |