Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
ce6b73c8
Commit
ce6b73c8
authored
May 26, 2013
by
Klimov Paul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Method "AssetController::adjustCssUrl()" has been created as blank
parent
afeee0a3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
0 deletions
+71
-0
AssetController.php
framework/yii/console/controllers/AssetController.php
+17
-0
AssetControllerTest.php
...nit/framework/console/controllers/AssetControllerTest.php
+54
-0
No files found.
framework/yii/console/controllers/AssetController.php
View file @
ce6b73c8
...
@@ -528,6 +528,23 @@ EOD
...
@@ -528,6 +528,23 @@ EOD
}
}
/**
/**
* Adjusts CSS content allowing URL references pointing to the original resources.
* @param string $cssContent source CSS content.
* @param string $inputFilePath input CSS file name.
* @param string $outputFilePath output CSS file name.
* @return string adjusted CSS content.
*/
protected
function
adjustCssUrl
(
$cssContent
,
$inputFilePath
,
$outputFilePath
)
{
$callback
=
function
(
$matches
)
use
(
$inputFilePath
,
$outputFilePath
)
{
return
$matches
[
0
];
};
$cssContent
=
preg_replace_callback
(
'/[\w\-]:\s*url\("(.*)"\)+/is'
,
$callback
,
$cssContent
);
return
$cssContent
;
}
/**
* Creates template of configuration file for [[actionCompress]].
* Creates template of configuration file for [[actionCompress]].
* @param string $configFile output file name.
* @param string $configFile output file name.
*/
*/
...
...
tests/unit/framework/console/controllers/AssetControllerTest.php
View file @
ce6b73c8
...
@@ -169,6 +169,23 @@ class AssetControllerTest extends TestCase
...
@@ -169,6 +169,23 @@ class AssetControllerTest extends TestCase
}
}
}
}
/**
* Invokes the asset controller method even if it is protected.
* @param string $methodName name of the method to be invoked.
* @param array $args method arguments.
* @return mixed method invoke result.
*/
protected
function
invokeAssetControllerMethod
(
$methodName
,
array
$args
=
array
())
{
$controller
=
$this
->
createAssetController
();
$controllerClassReflection
=
new
ReflectionClass
(
get_class
(
$controller
));
$methodReflection
=
$controllerClassReflection
->
getMethod
(
$methodName
);
$methodReflection
->
setAccessible
(
true
);
$result
=
$methodReflection
->
invokeArgs
(
$controller
,
$args
);
$methodReflection
->
setAccessible
(
false
);
return
$result
;
}
// Tests :
// Tests :
public
function
testActionTemplate
()
public
function
testActionTemplate
()
...
@@ -237,4 +254,41 @@ class AssetControllerTest extends TestCase
...
@@ -237,4 +254,41 @@ class AssetControllerTest extends TestCase
$this
->
assertContains
(
$content
,
$compressedJsFileContent
,
"Source of '
{
$name
}
' is missing in combined file!"
);
$this
->
assertContains
(
$content
,
$compressedJsFileContent
,
"Source of '
{
$name
}
' is missing in combined file!"
);
}
}
}
}
/**
* Data provider for [[testAdjustCssUrl()]].
* @return array test data.
*/
public
function
adjustCssUrlDataProvider
()
{
return
array
(
array
(
'.test-class {background-image: url("test.png");}'
,
'/test/base/path/assets/input'
,
'/test/base/path/assets/output'
,
'.test-class {background-image: url("../input/test.png");}'
,
),
array
(
'.test-class {background-image: url("../img/test.png");}'
,
'/test/base/path/assets/input'
,
'/test/base/path/assets/output'
,
'.test-class {background-image: url("../input/img/test.png");}'
,
),
);
}
/**
* @dataProvider adjustCssUrlDataProvider
*
* @param $cssContent
* @param $inputFilePath
* @param $outputFilePath
* @param $expectedCssContent
*/
public
function
testAdjustCssUrl
(
$cssContent
,
$inputFilePath
,
$outputFilePath
,
$expectedCssContent
)
{
$adjustedCssContent
=
$this
->
invokeAssetControllerMethod
(
'adjustCssUrl'
,
array
(
$cssContent
,
$inputFilePath
,
$outputFilePath
));
$this
->
assertEquals
(
$expectedCssContent
,
$adjustedCssContent
,
'Unable to adjust CSS correctly!'
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment