/** * Gets all the imports from the provided CSS source * @param string $source CSS source * @param string $baseUrl Base URL of the crawl * @param string $preyBaseUrl Base URL of the prey * @return array Array with the URLs of the imports as key and value */ private function getImageUrlsFromStyle($source, $baseUrl, $preyBaseUrl) { $cssMin = new CSSMin(); $source = preg_replace(CSSMin::REGEX_IMPORT, '', $source); $source = $cssMin->minify($source, true); $urlMatches = array(); preg_replace_callback('/url( )?\\(["\']?([^;\\\\"\')]*)(["\']?)\\)([^;\\)]*);/', function ($matches) use(&$urlMatches) { $urlMatches[] = $matches[2]; return ''; }, $source); $urls = array(); foreach ($urlMatches as $url) { $url = $this->getAbsoluteUrl($url, $baseUrl, $preyBaseUrl); $urls[$url] = $url; } return $urls; }
/** * @dataProvider providerMinify */ public function testMinify($expected, $source) { $result = CSSMin::min($source, true); $this->assertEquals($expected, $result); }