Example #1
0
 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));
 }
Example #2
0
 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));
 }
Example #3
0
 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;
 }
Example #4
0
 public function handleData(&$data)
 {
     SpeedOut_Utils::pcreIncreaseBacktrackLimit($data);
     $data = Minify_HTML::minify($data);
 }
Example #5
0
 protected function deprecateJavaScriptConditionalCompilationCode($js)
 {
     return SpeedOut_Utils::safePregReplace('~/\\*\\s*?(@.*?\\*/)~s', '/* DEPRECATED: \\1', $js);
 }
Example #6
0
 /**
  * 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);
     }
 }
Example #7
0
 protected function getCombinedDataPart($linkData, $linkPath)
 {
     return '// FILE: ' . SpeedOut_Utils::getPathUri($linkPath) . "\n\n{$linkData}\n\n";
 }
Example #8
0
 /**
  * @expectedException SpeedOut_Exception
  */
 public function testSafePregReplaceThrowsException()
 {
     SpeedOut_Utils::safePregReplace('~[yz]', 'x', 'xyz');
 }
Example #9
0
 public function getUrl($id)
 {
     if (is_file($this->getFilePathById($id))) {
         return SpeedOut_Utils::getPathUrl(SpeedOut_Utils::getDocRoot()) . SpeedOut_Utils::getPathUri($this->getFilePathById($id));
     }
 }
Example #10
0
 /**
  * @expectedException SpeedOut_Exception
  */
 public function testInitWithNotInDocumentRootDirException()
 {
     new SpeedOut_CacheStorage_Directory(dirname(SpeedOut_Utils::getDocRoot()));
 }
Example #11
0
 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;
 }
Example #12
0
 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);
 }