From ce6b73c88a2d538114cd0641be7f28aab1db31c0 Mon Sep 17 00:00:00 2001
From: Klimov Paul <klimov.paul@gmail.com>
Date: Sun, 26 May 2013 14:53:41 +0300
Subject: [PATCH] Method "AssetController::adjustCssUrl()" has been created as
 blank

---
 .../yii/console/controllers/AssetController.php    | 17 +++++++
 .../console/controllers/AssetControllerTest.php    | 54 ++++++++++++++++++++++
 2 files changed, 71 insertions(+)

diff --git a/framework/yii/console/controllers/AssetController.php b/framework/yii/console/controllers/AssetController.php
index ca7896c..852b892 100644
--- a/framework/yii/console/controllers/AssetController.php
+++ b/framework/yii/console/controllers/AssetController.php
@@ -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]].
 	 * @param string $configFile output file name.
 	 */
diff --git a/tests/unit/framework/console/controllers/AssetControllerTest.php b/tests/unit/framework/console/controllers/AssetControllerTest.php
index d792c9e..4983568 100644
--- a/tests/unit/framework/console/controllers/AssetControllerTest.php
+++ b/tests/unit/framework/console/controllers/AssetControllerTest.php
@@ -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 :
 
 	public function testActionTemplate()
@@ -237,4 +254,41 @@ class AssetControllerTest extends TestCase
 			$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!');
+	}
 }