/**
  * Scan references to files from other static files and assert they are correct
  *
  * The CSS or LESS files may refer to other resources using @import or url() notation
  * We want to check integrity of all these references
  * Note that the references may have syntax specific to the Magento preprocessing subsystem
  *
  * @param string $area
  * @param string $themePath
  * @param string $locale
  * @param string $module
  * @param string $filePath
  * @param string $absolutePath
  * @dataProvider referencesFromStaticFilesDataProvider
  */
 public function testReferencesFromStaticFiles($area, $themePath, $locale, $module, $filePath, $absolutePath)
 {
     $contents = file_get_contents($absolutePath);
     preg_match_all(\Magento\Framework\View\Url\CssResolver::REGEX_CSS_RELATIVE_URLS, $contents, $matches);
     foreach ($matches[1] as $relatedResource) {
         if (false !== strpos($relatedResource, '@')) {
             // unable to parse paths with LESS variables/mixins
             continue;
         }
         list($relatedModule, $relatedPath) = \Magento\Framework\View\Asset\Repository::extractModule($relatedResource);
         if ($relatedModule) {
             $fallbackModule = $relatedModule;
         } else {
             if ('less' == pathinfo($filePath, PATHINFO_EXTENSION)) {
                 /**
                  * The LESS library treats the related resources with relative links not in the same way as CSS:
                  * when another LESS file is included, it is embedded directly into the resulting document, but the
                  * relative paths of related resources are not adjusted accordingly to the new root file.
                  * Probably it is a bug of the LESS library.
                  */
                 $this->markTestSkipped("Due to LESS library specifics, the '{$relatedResource}' cannot be tested.");
             }
             $fallbackModule = $module;
             $relatedPath = \Magento\Framework\View\FileSystem::getRelatedPath($filePath, $relatedResource);
         }
         // the $relatedPath will be suitable for feeding to the fallback system
         $this->assertNotEmpty($this->getStaticFile($area, $themePath, $locale, $relatedPath, $fallbackModule), "The related resource cannot be resolved through fallback: '{$relatedResource}'");
     }
 }
Beispiel #2
0
 /**
  * Create a file asset with path relative to specified local asset
  *
  * @param string $fileId
  * @param LocalInterface $relativeTo
  * @return File
  */
 public function createRelated($fileId, LocalInterface $relativeTo)
 {
     list($module, $filePath) = self::extractModule($fileId);
     if ($module) {
         return $this->createSimilar($fileId, $relativeTo);
     }
     $filePath = \Magento\Framework\View\FileSystem::getRelatedPath($relativeTo->getFilePath(), $filePath);
     return $this->createSimilar($filePath, $relativeTo);
 }