/**
  * Get an array of URNs
  *
  * @param OutputInterface $output
  * @return array
  */
 private function getUrnDictionary(OutputInterface $output)
 {
     $files = $this->filesUtility->getXmlCatalogFiles('*.xml');
     $files = array_merge($files, $this->filesUtility->getXmlCatalogFiles('*.xsd'));
     $urns = [];
     foreach ($files as $file) {
         $content = $this->rootDirRead->readFile($this->rootDirRead->getRelativePath($file[0]));
         $matches = [];
         preg_match_all('/schemaLocation="(urn\\:magento\\:[^"]*)"/i', $content, $matches);
         if (isset($matches[1])) {
             $urns = array_merge($urns, $matches[1]);
         }
     }
     $urns = array_unique($urns);
     $paths = [];
     foreach ($urns as $urn) {
         try {
             $paths[$urn] = $this->urnResolver->getRealPath($urn);
         } catch (\Exception $e) {
             // don't add unsupported element to array
             if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
                 $output->writeln($e->getMessage());
             }
         }
     }
     return $paths;
 }
Пример #2
0
 public function testGetClassFilesOnlyTests()
 {
     $classFiles = $this->model->getClassFiles(false, true, false, false, false);
     $classFiles = preg_grep($this->moduleTests, $classFiles, PREG_GREP_INVERT);
     $classFiles = preg_grep($this->libTests, $classFiles, PREG_GREP_INVERT);
     $classFiles = preg_grep($this->frameworkTests, $classFiles, PREG_GREP_INVERT);
     $classFiles = preg_grep($this->toolsTests, $classFiles, PREG_GREP_INVERT);
     $classFiles = preg_grep($this->rootTestsDir, $classFiles, PREG_GREP_INVERT);
     $classFiles = preg_grep($this->setupTestsDir, $classFiles, PREG_GREP_INVERT);
     $this->assertEmpty($classFiles);
 }
Пример #3
0
 /**
  * Get translation data
  *
  * @param string $themePath
  * @return string[]
  * @throws \Exception
  * @throws \Magento\Framework\Exception
  */
 public function getData($themePath)
 {
     $dictionary = [];
     $files = $this->filesUtility->getJsFiles($this->appState->getAreaCode(), $themePath);
     foreach ($files as $filePath) {
         $content = $this->rootDirectory->readFile($this->rootDirectory->getRelativePath($filePath[0]));
         foreach ($this->getPhrases($content) as $phrase) {
             $translatedPhrase = (string) __($phrase);
             if ($phrase != $translatedPhrase) {
                 $dictionary[$phrase] = $translatedPhrase;
             }
         }
     }
     return $dictionary;
 }
 /**
  * @return void
  */
 public function testGetData()
 {
     $themePath = 'blank';
     $areaCode = 'adminhtml';
     $files = [['path1'], ['path2']];
     $relativePathMap = [['path1' => 'relativePath1'], ['path2' => 'relativePath2']];
     $contentsMap = [['relativePath1' => 'content1$.mage.__("hello1")content1'], ['relativePath2' => 'content2$.mage.__("hello2")content2']];
     $patterns = ['~\\$\\.mage\\.__\\([\'|\\"](.+?)[\'|\\"]\\)~'];
     $this->appStateMock->expects($this->once())->method('getAreaCode')->willReturn($areaCode);
     $this->filesUtilityMock->expects($this->once())->method('getJsFiles')->with($areaCode, $themePath)->willReturn($files);
     $this->rootDirectoryMock->expects($this->any())->method('getRelativePath')->willReturnMap($relativePathMap);
     $this->rootDirectoryMock->expects($this->any())->method('readFile')->willReturnMap($contentsMap);
     $this->configMock->expects($this->any())->method('getPatterns')->willReturn($patterns);
     $this->assertEquals([], $this->model->getData($themePath));
 }
Пример #5
0
 /**
  * Gets alien dependencies information for current module by analyzing file's contents
  *
  * @param string $currentModule
  * @param string $fileType
  * @param string $file
  * @param string $contents
  * @return array
  */
 public function getDependencyInfo($currentModule, $fileType, $file, &$contents)
 {
     if (!in_array($fileType, ['php', 'template'])) {
         return [];
     }
     $pattern = '~\\b(?<class>(?<module>(' . implode('_|', \Magento\Framework\App\Utility\Files::init()->getNamespaces()) . '[_\\\\])[a-zA-Z0-9]+)[a-zA-Z0-9_\\\\]*)\\b~';
     $dependenciesInfo = [];
     if (preg_match_all($pattern, $contents, $matches)) {
         $matches['module'] = array_unique($matches['module']);
         foreach ($matches['module'] as $i => $referenceModule) {
             $referenceModule = str_replace('_', '\\', $referenceModule);
             if ($currentModule == $referenceModule) {
                 continue;
             }
             $dependenciesInfo[] = ['module' => $referenceModule, 'type' => \Magento\TestFramework\Dependency\RuleInterface::TYPE_HARD, 'source' => trim($matches['class'][$i])];
         }
     }
     $result = $this->_caseGetUrl($currentModule, $contents);
     if (count($result)) {
         $dependenciesInfo = array_merge($dependenciesInfo, $result);
     }
     $result = $this->_caseLayoutBlock($currentModule, $fileType, $file, $contents);
     if (count($result)) {
         $dependenciesInfo = array_merge($dependenciesInfo, $result);
     }
     return $dependenciesInfo;
 }
 public function testLocalXmlFilesAbsent()
 {
     $area = '*';
     $package = '*';
     $theme = '*';
     $this->assertEmpty(glob(\Magento\Framework\App\Utility\Files::init()->getPathToSource() . "/app/design/{$area}/{$package}/{$theme}/local.xml"));
 }
Пример #7
0
 /**
  * Returns whitelist based on blacklist and git changed files
  *
  * @param array $fileTypes
  * @param string $changedFilesBaseDir
  * @param string $baseFilesFolder
  * @return array
  */
 public static function getWhitelist($fileTypes = ['php'], $changedFilesBaseDir = '', $baseFilesFolder = '')
 {
     $globPatternsFolder = self::getBaseFilesFolder();
     if ('' !== $baseFilesFolder) {
         $globPatternsFolder = $baseFilesFolder;
     }
     $directoriesToCheck = Files::init()->readLists($globPatternsFolder . '/_files/whitelist/common.txt');
     $changedFiles = [];
     $globFilesListPattern = ($changedFilesBaseDir ?: self::getChangedFilesBaseDir()) . '/_files/changed_files*';
     foreach (glob($globFilesListPattern) as $listFile) {
         $changedFiles = array_merge($changedFiles, file($listFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES));
     }
     array_walk($changedFiles, function (&$file) {
         $file = BP . '/' . $file;
     });
     $changedFiles = array_filter($changedFiles, function ($path) use($directoriesToCheck, $fileTypes) {
         if (!file_exists($path)) {
             return false;
         }
         $path = realpath($path);
         foreach ($directoriesToCheck as $directory) {
             $directory = realpath($directory);
             if (strpos($path, $directory) === 0) {
                 if (!empty($fileTypes)) {
                     return in_array(pathinfo($path, PATHINFO_EXTENSION), $fileTypes);
                 }
                 return true;
             }
         }
         return false;
     });
     return $changedFiles;
 }
Пример #8
0
 public function testReadListsCorruptedFile()
 {
     $result = Files::init()->readLists(__DIR__ . '/_files/list_corrupted_file.txt');
     foreach ($result as $path) {
         $this->assertNotContains('unknown.txt', $path);
     }
 }
 /**
  * Build Framework dependencies report
  *
  * @param string $outputPath
  * @return void
  */
 protected function buildReport($outputPath)
 {
     $filePaths = $this->registrar->getPaths(ComponentRegistrar::MODULE);
     $filesForParse = Files::init()->getFiles($filePaths, '*');
     $configFiles = Files::init()->getConfigFiles('module.xml', [], false);
     ServiceLocator::getFrameworkDependenciesReportBuilder()->build(['parse' => ['files_for_parse' => $filesForParse, 'config_files' => $configFiles, 'declared_namespaces' => Files::init()->getNamespaces()], 'write' => ['report_filename' => $outputPath]]);
 }
Пример #10
0
    /**
     * Accumulate all static view files in the application and record all found areas, themes and languages
     *
     * Returns an array of areas and files with meta information
     *
     * @param array $requestedLocales
     * @return array
     */
    private function collectAppFiles($requestedLocales)
    {
        $areas = [];
        $locales = [];
        $files = $this->filesUtil->getStaticPreProcessingFiles();
        foreach ($files as $info) {
            list($area, $themePath, $locale) = $info;
            if ($themePath) {
                $areas[$area][$themePath] = $themePath;
            }
            if ($locale) {
                $locales[$locale] = $locale;
            }
        }
        foreach ($requestedLocales as $locale) {
            unset($locales[$locale]);
        }
        if (!empty($locales)) {
            $langList = implode(', ', $locales);
            $this->output->writeln(
                "WARNING: there were files for the following languages detected in the file system: {$langList}."
                . ' These languages were not requested, so the files will not be populated.'
            );
        }

        return [$areas, $files];
    }
Пример #11
0
 /**
  * Constructor
  *
  * @param array $mapRouters
  * @param array $mapLayoutBlocks
  * @param array $mapLayoutHandles
  */
 public function __construct(array $mapRouters, array $mapLayoutBlocks, array $mapLayoutHandles)
 {
     $this->_mapRouters = $mapRouters;
     $this->_mapLayoutBlocks = $mapLayoutBlocks;
     $this->_mapLayoutHandles = $mapLayoutHandles;
     $this->_namespaces = implode('|', \Magento\Framework\App\Utility\Files::init()->getNamespaces());
 }
Пример #12
0
 public function testObsoleteDirectives()
 {
     $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
     $invoker(function ($file) {
         $this->assertNotRegExp('/\\{\\{htmlescape.*?\\}\\}/i', file_get_contents($file), 'Directive {{htmlescape}} is obsolete. Use {{escapehtml}} instead.');
     }, \Magento\Framework\App\Utility\Files::init()->getEmailTemplates());
 }
 public function testObsoleteJavascriptAttributeType()
 {
     $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
     $invoker(function ($file) {
         $this->assertNotRegexp('/type="text\\/javascript"/', file_get_contents($file), 'Please do not use "text/javascript" type attribute.');
     }, \Magento\Framework\App\Utility\Files::init()->getPhtmlFiles());
 }
Пример #14
0
 /**
  * Helper method to setup the black and white lists
  *
  * @param string $type
  * @return void
  */
 public static function setupFileLists($type = '')
 {
     if ($type != '' && !preg_match('/\\/$/', $type)) {
         $type = $type . '/';
     }
     self::$whiteList = Files::readLists(__DIR__ . '/_files/' . $type . 'whitelist/*.txt');
     self::$blackList = Files::readLists(__DIR__ . '/_files/' . $type . 'blacklist/*.txt');
 }
Пример #15
0
 /**
  * Return layout handles that are declared in the base layouts for frontend
  *
  * @return array
  */
 protected function _getBaseFrontendHandles()
 {
     if ($this->_baseFrontendHandles === null) {
         $files = \Magento\Framework\App\Utility\Files::init()->getLayoutFiles(['include_design' => false, 'area' => 'frontend'], false);
         $this->_baseFrontendHandles = $this->_extractLayoutHandles($files);
     }
     return $this->_baseFrontendHandles;
 }
 /**
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage ARG_IS_WRONG argument has invalid value, please run info:language:list
  */
 public function testExecuteInvalidLanguageArgument()
 {
     $this->filesUtil->expects(self::any())->method('getStaticPreProcessingFiles')->willReturn([]);
     $this->objectManager->expects($this->at(0))->method('create')->willReturn($this->filesUtil);
     $wrongParam = ['languages' => ['ARG_IS_WRONG']];
     $commandTester = new CommandTester($this->command);
     $commandTester->execute($wrongParam);
 }
 public function testXmlFiles()
 {
     $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
     $invoker(function ($configFile) {
         $schema = $this->urnResolver->getRealPath('urn:magento:module:Magento_Widget:etc/widget.xsd');
         $this->_validateFileExpectSuccess($configFile, $schema);
     }, array_merge(\Magento\Framework\App\Utility\Files::init()->getConfigFiles('widget.xml'), \Magento\Framework\App\Utility\Files::init()->getLayoutConfigFiles('widget.xml')));
 }
Пример #18
0
 /**
  * Skip blacklisted files
  *
  * @param array $fileList
  * @return array
  * @throws \Exception
  */
 private function filterFiles(array $fileList)
 {
     $blackListFiles = Files::init()->readLists(__DIR__ . '/_files/blacklist/*.txt');
     $filter = function ($value) use($blackListFiles) {
         return !in_array($value, $blackListFiles);
     };
     return array_filter($fileList, $filter);
 }
Пример #19
0
 public function testBlocksIntoContainers()
 {
     $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
     $invoker(function ($file) {
         $xml = simplexml_load_file($file);
         $this->assertSame([], $xml->xpath('/widgets/*/supported_blocks'), 'Obsolete node: <supported_blocks>. To be replaced with <supported_containers>');
         $this->assertSame([], $xml->xpath('/widgets/*/*/*/block_name'), 'Obsolete node: <block_name>. To be replaced with <container_name>');
     }, \Magento\Framework\App\Utility\Files::init()->getConfigFiles('widget.xml'));
 }
 /**
  * @param array $deniedDirectives
  * @return string
  */
 protected function createMessage($deniedDirectives)
 {
     $rootPath = Files::init()->getPathToSource();
     $message = 'HHVM-incompatible ini_get/ini_set options were found:';
     foreach ($deniedDirectives as $file => $fileDeniedDirectives) {
         $message .= "\n" . str_replace($rootPath, '', $file) . ': [' . implode(', ', $fileDeniedDirectives) . ']';
     }
     return $message;
 }
 /**
  * @return void
  */
 public function testXssSensitiveOutput()
 {
     $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
     $xssOutputValidator = new XssOutputValidator();
     $invoker(function ($file) use($xssOutputValidator) {
         $lines = $xssOutputValidator->getLinesWithXssSensitiveOutput($file);
         $this->assertEmpty($lines, "Potentially XSS vulnerability. " . "Please verify that output is escaped at lines " . $lines);
     }, Files::init()->getPhtmlFiles());
 }
Пример #22
0
 /**
  * @return array
  */
 public function declaredConsistentlyDataProvider()
 {
     $result = [];
     $root = \Magento\Framework\App\Utility\Files::init()->getPathToSource();
     foreach (Package::readDeclarationFiles($root) as $row) {
         $result[] = $row;
     }
     return $result;
 }
 public function testSystemConfigurationDeclaration()
 {
     $fileList = \Magento\Framework\App\Utility\Files::init()->getConfigFiles('system.xml', ['wsdl.xml', 'wsdl2.xml', 'wsi.xml'], false);
     foreach ($fileList as $configFile) {
         $configXml = simplexml_load_file($configFile);
         $xpath = '/config/tabs|/config/sections';
         $this->assertEmpty($configXml->xpath($xpath), 'Obsolete system configuration structure detected in file ' . $configFile . '.');
     }
 }
Пример #24
0
 public function testAclDeclarations()
 {
     $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
     $invoker(function ($aclFile) {
         $aclXml = simplexml_load_file($aclFile);
         $xpath = '/config/acl/*[boolean(./children) or boolean(./title)]';
         $this->assertEmpty($aclXml->xpath($xpath), 'Obsolete acl structure detected in file ' . $aclFile . '.');
     }, \Magento\Framework\App\Utility\Files::init()->getMainConfigFiles());
 }
Пример #25
0
 public function testGetLayoutConfigFiles()
 {
     $this->dirSearch->expects($this->once())->method('collectFiles')->with(ComponentRegistrar::THEME, '/etc/some.file')->willReturn(['/one/some.file', '/two/some.file']);
     $expected = ['/one/some.file', '/two/some.file'];
     $actual = Files::init()->getLayoutConfigFiles('some.file', false);
     $this->assertSame($expected, $actual);
     // Check that the result is cached (collectFiles() is called only once)
     $this->assertSame($expected, $actual);
 }
Пример #26
0
 /**
  * Get translation data
  *
  * @param string $themePath
  * @return array
  * @throws \Exception
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function getData($themePath)
 {
     $areaCode = $this->appState->getAreaCode();
     $files = array_merge($this->filesUtility->getJsFiles('base', $themePath), $this->filesUtility->getJsFiles($areaCode, $themePath), $this->filesUtility->getStaticHtmlFiles('base', $themePath), $this->filesUtility->getStaticHtmlFiles($areaCode, $themePath));
     $dictionary = [];
     foreach ($files as $filePath) {
         /** @var \Magento\Framework\Filesystem\File\Read $read */
         $read = $this->fileReadFactory->create($filePath[0], \Magento\Framework\Filesystem\DriverPool::FILE);
         $content = $read->readAll();
         foreach ($this->getPhrases($content) as $phrase) {
             $translatedPhrase = $this->translate->render([$phrase], []);
             if ($phrase != $translatedPhrase) {
                 $dictionary[$phrase] = $translatedPhrase;
             }
         }
     }
     return $dictionary;
 }
Пример #27
0
 public function testSchemaUsingPartialXml($expectedErrors = null)
 {
     $xmlFile = $this->_getKnownValidPartialXml();
     if ($xmlFile === null) {
         $this->markTestSkipped('No Partial File');
         return;
     }
     $schema = \Magento\Framework\App\Utility\Files::init()->getPathToSource() . $this->_getXsd();
     $this->_validateFileExpectFailure($xmlFile, $schema, $expectedErrors);
 }
Пример #28
0
 public function testXmlFiles()
 {
     if (null === $this->_getXmlName()) {
         $this->markTestSkipped('No XML validation of files requested');
     }
     $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
     $invoker(function ($configFile) {
         $this->_validateFileExpectSuccess($configFile, $this->_getXsd(), $this->_getFileXsd());
     }, \Magento\Framework\App\Utility\Files::init()->getConfigFiles($this->_getXmlName()));
 }
 public function testGetChildHtml()
 {
     $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
     $invoker(function ($file) {
         $result = \Magento\Framework\App\Utility\Classes::getAllMatches(file_get_contents($file), "/(->getChildHtml\\([^,()]+, ?[^,()]+,)/i");
         $this->assertEmpty($result, "3rd parameter is not needed anymore for getChildHtml() in '{$file}': " . print_r($result, true));
         $result = \Magento\Framework\App\Utility\Classes::getAllMatches(file_get_contents($file), "/(->getChildChildHtml\\([^,()]+, ?[^,()]+, ?[^,()]+,)/i");
         $this->assertEmpty($result, "4th parameter is not needed anymore for getChildChildHtml() in '{$file}': " . print_r($result, true));
     }, Files::init()->getPhpFiles(Files::INCLUDE_APP_CODE | Files::INCLUDE_PUB_CODE | Files::INCLUDE_LIBS | Files::INCLUDE_TEMPLATES | Files::INCLUDE_TESTS | Files::AS_DATA_SET | Files::INCLUDE_NON_CLASSES));
 }
Пример #30
0
 public function testWords()
 {
     $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
     $invoker(function ($file) {
         $words = self::$_wordsFinder->findWords(realpath($file));
         if ($words) {
             $this->fail("Found words: '" . implode("', '", $words) . "' in '{$file}' file");
         }
     }, \Magento\Framework\App\Utility\Files::init()->getAllFiles());
 }