8 protected $cssFiles = array(
14 protected $jsFiles = array(
16 'js/jquery.yiigridview.js',
19 protected $assetsFolder;
26 public function setUp()
28 Yii::setPathOfAlias(
'webroot', Yii::getPathOfAlias(
'site.tests.runtime.www'));
29 $this->assetsFolder =
'/assets';
31 $this->cs = Yii::createComponent(array(
32 'class' =>
'common.extensions.ExtendedClientScript.ExtendedClientScript',
33 'disableRegisterFiles' =>
false,
34 'fileUrl' => $this->assetsFolder,
35 'basePath' => Yii::getPathOfAlias(
'webroot'),
37 'combineCss' =>
false,
39 'compressCombinedCss' =>
false,
43 'compressCombinedJs' =>
false,
45 'jsMinPath' =>
'common.extensions.ExtendedClientScript.jsmin.*',
47 'cssMinPath' =>
'common.extensions.ExtendedClientScript.cssmin.*'
51 public function tearDown()
53 $fsIter =
new FilesystemIterator(Yii::getPathOfAlias(
'webroot') . $this->assetsFolder);
54 foreach ($fsIter as $f) {
55 if (preg_match(
'/.*.(css|js)/', $f->getFileName())) {
56 unlink($f->getPathname());
61 public function testPublishCss()
63 foreach ($this->cssFiles as $f) {
64 $this->cs->registerCssFile($this->assetsFolder .
'/' . $f);
68 $this->cs->renderHead($output);
70 preg_match_all(
'/href="(?P<url>.*)"/', $output, $matches);
71 $this->assertEquals(count($this->cssFiles), count($matches[
'url']));
74 public function testCombineCss()
76 $this->cs->combineCss =
true;
78 foreach ($this->cssFiles as $f) {
79 $this->cs->registerCssFile($this->assetsFolder .
'/' . $f);
83 $this->cs->renderHead($output);
85 preg_match(
'/href="(?P<url>.*)"/', $output, $matches);
86 $this->assertFileExists(Yii::getPathOfAlias(
'webroot') . $matches[
'url']);
89 public function testCombineCompressCss()
91 $this->cs->combineCss =
true;
92 $this->cs->compressCombinedCss =
true;
94 foreach ($this->cssFiles as $f) {
95 $this->cs->registerCssFile($this->assetsFolder .
'/' . $f);
99 $this->cs->renderHead($output);
101 preg_match(
'/href="(?P<url>.*)"/', $output, $matches);
102 $this->assertFileExists(Yii::getPathOfAlias(
'webroot') . $matches[
'url']);
105 public function testPublishJs()
107 foreach ($this->jsFiles as $f) {
108 $this->cs->registerScriptFile($this->assetsFolder .
'/' . $f);
112 $this->cs->renderHead($output);
115 preg_match_all(
'/src="(?P<url>.*)"/', $output, $matches);
116 $this->assertEquals(count($this->jsFiles), count($matches[
'url']));
119 public function testCombineJs()
121 $this->cs->combineJs =
true;
123 foreach ($this->jsFiles as $f) {
124 $this->cs->registerScriptFile($this->assetsFolder .
'/' . $f);
128 $this->cs->renderHead($output);
131 preg_match(
'/src="(?P<url>.*)"/', $output, $matches);
132 $this->assertFileExists(Yii::getPathOfAlias(
'webroot') . $matches[
'url']);
135 public function testCombineCompressJs()
137 $this->cs->combineJs =
true;
138 $this->cs->compressCombinedJs =
true;
140 foreach ($this->jsFiles as $f) {
141 $this->cs->registerScriptFile($this->assetsFolder .
'/' . $f);
145 $this->cs->renderHead($output);
147 preg_match(
'/src="(?P<url>.*)"/', $output, $matches);
148 $this->assertFileExists(Yii::getPathOfAlias(
'webroot') . $matches[
'url']);
151 public function testCombineCompressJsCss()
153 $this->cs->combineJs =
true;
154 $this->cs->compressCombinedJs =
true;
155 $this->cs->combineCss =
true;
156 $this->cs->compressCombinedCss =
true;
159 foreach ($this->cssFiles as $f) {
160 $this->cs->registerCssFile($this->assetsFolder .
'/' . $f);
162 foreach ($this->jsFiles as $f) {
163 $this->cs->registerScriptFile($this->assetsFolder .
'/' . $f);
167 $this->cs->renderHead($output);
169 preg_match(
'/href="(?P<url>.*)"/', $output, $matches);
170 $this->assertFileExists(Yii::getPathOfAlias(
'webroot') . $matches[
'url']);
172 preg_match(
'/src="(?P<url>.*)"/', $output, $matches);
173 $this->assertFileExists(Yii::getPathOfAlias(
'webroot') . $matches[
'url']);
177 public function testDisableRegisterFiles()
179 $this->cs->disableRegisterFiles =
true;
181 foreach ($this->cssFiles as $f) {
182 $this->cs->registerCssFile($this->assetsFolder .
'/' . $f);
184 foreach ($this->jsFiles as $f) {
185 $this->cs->registerScriptFile($this->assetsFolder .
'/' . $f);
189 $this->cs->renderHead($output);
191 preg_match(
'/href="(?P<url>.*)"/', $output, $matches);
192 $this->assertArrayNotHasKey(
'url', $matches);
194 preg_match(
'/src="(?P<url>.*)"/', $output, $matches);
195 $this->assertArrayNotHasKey(
'url', $matches);