public function testCombinedDataIsCorrect() { $this->assertEquals(1, SpeedOut_Utils::safePregMatch($this->getCombinedLinkRegexp(), $this->getHandledHtmlData(), $m)); $combinedFileLink = $m[1]; $combinedFilePath = str_replace(SpeedOut_Utils::getPathUrl(SpeedOut_Utils::getDocRoot()), SpeedOut_Utils::getDocRoot(), $combinedFileLink); $this->assertTrue(is_file($combinedFilePath)); $this->assertEquals($this->getTestDataFile('_expected_combined.' . $this->getFileType()), file_get_contents($combinedFilePath)); }
public function testStoreAndGetUrl() { $storeId = $this->generateStoreId(); $expectedData = mt_rand(); $this->storage->store($storeId, $expectedData); $actualUrl = $this->storage->getUrl($storeId); $this->assertTrue(SpeedOut_Utils::isExternalLink($actualUrl)); // because of tests are running from CLI $actualPath = SpeedOut_Utils::getDocRoot() . substr($actualUrl, strlen(SpeedOut_Utils::getPathUrl(SpeedOut_Utils::getDocRoot()))); $this->assertEquals($expectedData, file_get_contents($actualPath)); }
public function isMatch($data) { $isMatched = !$this->requiredRegexps; foreach ($this->requiredRegexps as $regexp) { if (SpeedOut_Utils::safePregMatch($regexp, $data)) { $isMatched = true; break; } } foreach ($this->excludedRegexps as $regexp) { if (SpeedOut_Utils::safePregMatch($regexp, $data)) { $isMatched = false; break; } } return $isMatched; }
public function handleData(&$data) { SpeedOut_Utils::pcreIncreaseBacktrackLimit($data); $data = Minify_HTML::minify($data); }
protected function deprecateJavaScriptConditionalCompilationCode($js) { return SpeedOut_Utils::safePregReplace('~/\\*\\s*?(@.*?\\*/)~s', '/* DEPRECATED: \\1', $js); }
/** * Get URL for external or URI for local path of some link * @static * @param $link * @param string $baseDir * @return string|null */ public static function getRealLink($link, $baseDir = null) { if (self::isExternalLink($link)) { return $link; } else { $path = ($baseDir && self::isRelativeLink($link) ? $baseDir : self::getDocRoot()) . '/' . SpeedOut_Utils::safePregReplace('~\\?.*~', '', $link); return self::getPathUri($path, false); } }
protected function getCombinedDataPart($linkData, $linkPath) { return '// FILE: ' . SpeedOut_Utils::getPathUri($linkPath) . "\n\n{$linkData}\n\n"; }
/** * @expectedException SpeedOut_Exception */ public function testSafePregReplaceThrowsException() { SpeedOut_Utils::safePregReplace('~[yz]', 'x', 'xyz'); }
public function getUrl($id) { if (is_file($this->getFilePathById($id))) { return SpeedOut_Utils::getPathUrl(SpeedOut_Utils::getDocRoot()) . SpeedOut_Utils::getPathUri($this->getFilePathById($id)); } }
/** * @expectedException SpeedOut_Exception */ public function testInitWithNotInDocumentRootDirException() { new SpeedOut_CacheStorage_Directory(dirname(SpeedOut_Utils::getDocRoot())); }
protected function getLinksNodes($html) { $html = $this->removeHtmlComments($html); $linksData = array(); foreach ($this->getLinksNodesRegexps() as $regexp) { if (SpeedOut_Utils::safePregMatchAll($regexp, $html, $m)) { foreach ($m[1] as $i => $link) { if (!SpeedOut_Utils::isExternalLink($link) && $this->linksFilter->isMatch($link)) { $linksData[$link] = $m[0][$i]; } } } } return $linksData; }
protected function replaceImportsInLinkedData(&$linkedFileData, $linkPath) { $linkBaseDir = dirname($linkPath); $importsRegexp = '~@import\\s*?["\'](.*?)["\'].*?;~'; $replaceLinksDataRegexps = array(); $importedLinksPaths =& $this->handlingProcessData[__METHOD__ . 'importsLinksPaths']; if (!$importedLinksPaths) { $importedLinksPaths = array(); } if (SpeedOut_Utils::safePregMatchAll($importsRegexp, $linkedFileData, $m)) { foreach ($m[1] as $i => $importLink) { $importLinkPath = SpeedOut_Utils::getLinkPath($importLink, $linkBaseDir); if (!SpeedOut_Utils::isExternalLink($importLink) && !in_array($importLinkPath, $importedLinksPaths) && $this->isValidInternalLink($importLinkPath, 'combined CSS data')) { $importedLinksPaths[] = $importLinkPath; $replaceLinksDataRegexps['~' . preg_quote($m[0][$i], '~') . '~'] = $this->getLinkData($importLinkPath); } } } foreach ($replaceLinksDataRegexps as $regexp => $replace) { $linkedFileData = SpeedOut_Utils::safePregReplace($regexp, $replace, $linkedFileData, 1); } $linkedFileData = SpeedOut_Utils::safePregReplace($importsRegexp, '', $linkedFileData); }