/**
  * Get real file path by it's URN reference
  *
  * @param string $schema
  * @return string
  * @throws NotFoundException
  */
 public function getRealPath($schema)
 {
     if (strpos($schema, 'urn:') !== 0) {
         return $schema;
     }
     $componentRegistrar = new ComponentRegistrar();
     $matches = [];
     $modulePattern = '/urn:(?<vendor>([a-zA-Z]*)):module:(?<module>([A-Za-z\\_]*)):(?<path>(.+))/';
     $frameworkPattern = '/urn:(?<vendor>([a-zA-Z]*)):(?<framework>(framework[A-Za-z\\-]*)):(?<path>(.+))/';
     if (preg_match($modulePattern, $schema, $matches)) {
         //urn:magento:module:Magento_Catalog:etc/catalog_attributes.xsd
         $package = $componentRegistrar->getPath(ComponentRegistrar::MODULE, $matches['module']);
     } else {
         if (preg_match($frameworkPattern, $schema, $matches)) {
             //urn:magento:framework:Module/etc/module.xsd
             //urn:magento:framework-amqp:Module/etc/module.xsd
             $package = $componentRegistrar->getPath(ComponentRegistrar::LIBRARY, $matches['vendor'] . '/' . $matches['framework']);
         } else {
             throw new NotFoundException(new Phrase("Unsupported format of schema location: '%1'", [$schema]));
         }
     }
     $schemaPath = $package . '/' . $matches['path'];
     if (empty($package) || !file_exists($schemaPath)) {
         throw new NotFoundException(new Phrase("Could not locate schema: '%1' at '%2'", [$schema, $schemaPath]));
     }
     return $schemaPath;
 }
 private function assertFixturesRegistered()
 {
     $this->assertSame(__DIR__ . '/_files/components/b', $this->componentRegistrar->getPath(ComponentRegistrar::LIBRARY, self::LIBRARY_NAME));
     $this->assertSame(__DIR__ . '/_files/components', $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, self::MODULE_NAME));
     $this->assertSame(__DIR__ . '/_files/components/a/aa/aaa', $this->componentRegistrar->getPath(ComponentRegistrar::THEME, self::THEME_NAME));
     $this->assertSame(__DIR__ . '/_files/components/a/aa', $this->componentRegistrar->getPath(ComponentRegistrar::LANGUAGE, self::LANGUAGE_NAME));
 }
 /**
  * Get real file path by it's URN reference
  *
  * @param string $schema
  * @return string
  * @throws \UnexpectedValueException
  */
 public function getRealPath($schema)
 {
     $componentRegistrar = new ComponentRegistrar();
     if (substr($schema, 0, 4) == 'urn:') {
         // resolve schema location
         $urnParts = explode(':', $schema);
         if ($urnParts[2] == 'module') {
             // urn:magento:module:Magento_Catalog:etc/catalog_attributes.xsd
             // 0 : urn, 1: magento, 2: module, 3: Magento_Catalog, 4: etc/catalog_attributes.xsd
             // moduleName -> Magento_Catalog
             $schemaPath = $componentRegistrar->getPath(ComponentRegistrar::MODULE, $urnParts[3]) . '/' . $urnParts[4];
         } else {
             if (strpos($urnParts[2], 'framework') === 0) {
                 // urn:magento:framework:Module/etc/module.xsd
                 // 0: urn, 1: magento, 2: framework, 3: Module/etc/module.xsd
                 // libaryName -> magento/framework
                 $libraryName = $urnParts[1] . '/' . $urnParts[2];
                 $schemaPath = $componentRegistrar->getPath(ComponentRegistrar::LIBRARY, $libraryName) . '/' . $urnParts[3];
             } else {
                 throw new \UnexpectedValueException("Unsupported format of schema location: " . $schema);
             }
         }
         if (!empty($schemaPath) && file_exists($schemaPath)) {
             $schema = $schemaPath;
         } else {
             throw new \UnexpectedValueException("Could not locate schema: '" . $schema . "' at '" . $schemaPath . "'");
         }
     }
     return $schema;
 }
Beispiel #4
0
 /**
  * @inheritdoc
  */
 public function install()
 {
     $this->eavConfig->clear();
     $importModel = $this->importModel;
     $importModel->setData(['entity' => 'catalog_product', 'behavior' => 'append', 'import_images_file_dir' => 'pub/media/catalog/product', Import::FIELD_NAME_VALIDATION_STRATEGY => ProcessingErrorAggregatorInterface::VALIDATION_STRATEGY_SKIP_ERRORS]);
     $source = $this->csvSourceFactory->create(['file' => 'fixtures/products.csv', 'directory' => $this->readFactory->create($this->componentRegistrar->getPath(ComponentRegistrar::MODULE, 'Magento_ConfigurableSampleData'))]);
     $currentPath = getcwd();
     chdir(BP);
     $importModel->validateSource($source);
     $importModel->importSource();
     chdir($currentPath);
     $this->eavConfig->clear();
     $this->reindex();
 }
 /**
  * Get package name of a theme by its full theme path
  *
  * @param string $themePath
  * @return string
  * @throws \Zend_Json_Exception
  */
 public function getPackageName($themePath)
 {
     $themePath = $this->componentRegistrar->getPath(ComponentRegistrar::THEME, $themePath);
     $themeDir = $this->readDirFactory->create($themePath);
     if ($themeDir->isExist('composer.json')) {
         $rawData = [];
         $themeFile = $themeDir->readFile('composer.json');
         if ($themeFile) {
             $rawData = \Zend_Json::decode($themeFile);
         }
         return isset($rawData['name']) ? $rawData['name'] : '';
     }
     return '';
 }
Beispiel #6
0
 /**
  * Check module existence
  *
  * @param string $moduleName
  * @return bool
  */
 public function isModuleExists($moduleName)
 {
     $key = __METHOD__ . "/{$moduleName}";
     if (!isset(self::$_cache[$key])) {
         self::$_cache[$key] = file_exists($this->componentRegistrar->getPath(ComponentRegistrar::MODULE, $moduleName));
     }
     return self::$_cache[$key];
 }
 public function testGetRealPathWithModuleUrn()
 {
     $xsdUrn = 'urn:magento:module:Magento_Customer:etc/address_formats.xsd';
     $componentRegistrar = new ComponentRegistrar();
     $xsdPath = $componentRegistrar->getPath(ComponentRegistrar::MODULE, 'Magento_Customer') . '/etc/address_formats.xsd';
     $result = $this->urnResolver->getRealPath($xsdUrn);
     $this->assertSame($xsdPath, $result, 'XSD paths does not match.');
 }
 /**
  * @return array
  */
 protected function getBlackList()
 {
     $blackListFiles = [];
     $componentRegistrar = new ComponentRegistrar();
     foreach ($this->getFilesData('blacklist/files_list*') as $fileInfo) {
         $blackListFiles[] = $componentRegistrar->getPath(ComponentRegistrar::MODULE, $fileInfo[0]) . DIRECTORY_SEPARATOR . $fileInfo[1];
     }
     return $blackListFiles;
 }
 /**
  * Download sample file action
  *
  * @return \Magento\Framework\Controller\Result\Raw
  */
 public function execute()
 {
     $fileName = $this->getRequest()->getParam('filename') . '.csv';
     $moduleDir = $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, self::SAMPLE_FILES_MODULE);
     $fileAbsolutePath = $moduleDir . '/Files/Sample/' . $fileName;
     $directoryRead = $this->readFactory->create($moduleDir);
     $filePath = $directoryRead->getRelativePath($fileAbsolutePath);
     if (!$directoryRead->isFile($filePath)) {
         /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
         $this->messageManager->addError(__('There is no sample file for this entity.'));
         $resultRedirect = $this->resultRedirectFactory->create();
         $resultRedirect->setPath('*/import');
         return $resultRedirect;
     }
     $fileSize = isset($directoryRead->stat($filePath)['size']) ? $directoryRead->stat($filePath)['size'] : null;
     $this->fileFactory->create($fileName, null, DirectoryList::VAR_DIR, 'application/octet-stream', $fileSize);
     /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
     $resultRaw = $this->resultRawFactory->create();
     $resultRaw->setContents($directoryRead->readFile($filePath));
     return $resultRaw;
 }
 /**
  * Return pattern for theme locale directories, where <locale_placeholder> is placed to mark a locale's location.
  *
  * @param \Magento\Framework\View\Design\ThemeInterface $theme
  * @return string
  * @throws \Exception
  */
 protected static function _getLocalePatternDir(\Magento\Framework\View\Design\ThemeInterface $theme)
 {
     $localePlaceholder = '<locale_placeholder>';
     $params = ['area' => $theme->getArea(), 'theme' => $theme, 'locale' => $localePlaceholder];
     $patternDirs = self::$_fallbackRule->getPatternDirs($params);
     $themePath = self::$_componentRegistrar->getPath(\Magento\Framework\Component\ComponentRegistrar::THEME, $theme->getFullPath());
     foreach ($patternDirs as $patternDir) {
         $patternPath = $patternDir . '/';
         if (strpos($patternPath, $themePath) !== false && strpos($patternPath, $localePlaceholder) !== false) {
             return $patternDir;
         }
     }
     throw new \Exception('Unable to determine theme locale path');
 }
Beispiel #11
0
 public function testLayoutFile()
 {
     $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
     $invoker(function ($layoutFile) {
         $layoutXml = simplexml_load_file($layoutFile);
         $this->_testObsoleteReferences($layoutXml);
         $this->_testObsoleteAttributes($layoutXml);
         $selectorHeadBlock = '(name()="block" or name()="referenceBlock") and ' . '(@name="head" or @name="convert_root_head" or @name="vde_head")';
         $this->assertSame([], $layoutXml->xpath('//block[@class="Magento\\Theme\\Block\\Html\\Head\\Css" ' . 'or @class="Magento\\Theme\\Block\\Html\\Head\\Link" ' . 'or @class="Magento\\Theme\\Block\\Html\\Head\\Script"]' . '/parent::*[not(' . $selectorHeadBlock . ')]'), 'Blocks \\Magento\\Theme\\Block\\Html\\Head\\{Css,Link,Script} ' . 'are allowed within the "head" block only. ' . 'Verify integrity of the nodes nesting.');
         $this->assertSame([], $layoutXml->xpath('/layout//*[@output="toHtml"]'), 'output="toHtml" is obsolete. Use output="1"');
         foreach ($layoutXml as $handle) {
             $this->assertNotContains((string) $handle['id'], $this->_obsoleteNodes, 'This layout handle is obsolete.');
         }
         foreach ($layoutXml->xpath('@helper') as $action) {
             $this->assertNotContains('/', $action->getAttribute('helper'));
             $this->assertContains('::', $action->getAttribute('helper'));
         }
         $componentRegistrar = new ComponentRegistrar();
         if (false !== strpos($layoutFile, $componentRegistrar->getPath(ComponentRegistrar::MODULE, 'Magento_Sales') . '/view/adminhtml/layout/sales_order') || false !== strpos($layoutFile, $componentRegistrar->getPath(ComponentRegistrar::MODULE, 'Magento_Shipping') . '/view/adminhtml/layout/adminhtml_order')) {
             $this->markTestIncomplete("The file {$layoutFile} has to use \\Magento\\Core\\Block\\Text\\List, \n" . 'there is no solution to get rid of it right now.');
         }
         $this->assertSame([], $layoutXml->xpath('/layout//block[@class="Magento\\Framework\\View\\Element\\Text\\ListText"]'), 'The class \\Magento\\Framework\\View\\Element\\Text\\ListTest' . ' is not supposed to be used in layout anymore.');
     }, \Magento\Framework\App\Utility\Files::init()->getLayoutFiles());
 }
Beispiel #12
0
 /**
  * Get paths by context
  *
  * @param string $type
  * @param array $value
  * @return string
  * @throws \InvalidArgumentException
  */
 public function buildPathToLocaleDirectoryByContext($type, $value)
 {
     switch ($type) {
         case self::CONTEXT_TYPE_MODULE:
             $path = $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, $value);
             break;
         case self::CONTEXT_TYPE_THEME:
             $path = $this->componentRegistrar->getPath(ComponentRegistrar::THEME, $value);
             break;
         case self::CONTEXT_TYPE_LIB:
             $path = BP . '/lib/web';
             break;
         default:
             throw new \InvalidArgumentException(sprintf('Invalid context given: "%s".', $type));
     }
     return $path . '/' . self::LOCALE_DIRECTORY . '/';
 }
Beispiel #13
0
 /**
  * @return \Magento\Backend\Model\Menu\Config
  */
 protected function prepareMenuConfig()
 {
     $this->loginAdminUser();
     $componentRegistrar = new \Magento\Framework\Component\ComponentRegistrar();
     $libraryPath = $componentRegistrar->getPath(ComponentRegistrar::LIBRARY, 'magento/framework');
     $reflection = new \ReflectionClass('Magento\\Framework\\Component\\ComponentRegistrar');
     $paths = $reflection->getProperty('paths');
     $paths->setAccessible(true);
     $paths->setValue([ComponentRegistrar::MODULE => [], ComponentRegistrar::THEME => [], ComponentRegistrar::LANGUAGE => [], ComponentRegistrar::LIBRARY => []]);
     $paths->setAccessible(false);
     ComponentRegistrar::register(ComponentRegistrar::LIBRARY, 'magento/framework', $libraryPath);
     ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_Backend', __DIR__ . '/_files/menu/Magento/Backend');
     /* @var $validationState \Magento\Framework\App\Arguments\ValidationState */
     $validationState = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Framework\\App\\Arguments\\ValidationState', ['appMode' => State::MODE_DEFAULT]);
     /* @var $configReader \Magento\Backend\Model\Menu\Config\Reader */
     $configReader = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Backend\\Model\\Menu\\Config\\Reader', ['validationState' => $validationState]);
     return \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Backend\\Model\\Menu\\Config', ['configReader' => $configReader, 'configCacheType' => $this->configCacheType]);
 }
Beispiel #14
0
 /**
  * {@inheritdoc}
  */
 public function get($filename, $scope)
 {
     switch ($scope) {
         case 'global':
             $iterator = $this->moduleReader->getConfigurationFiles($filename)->toArray();
             $themeConfigFile = $this->currentTheme->getCustomization()->getCustomViewConfigPath();
             if ($themeConfigFile
                 && $this->rootDirectory->isExist($this->rootDirectory->getRelativePath($themeConfigFile))
             ) {
                 $iterator[$this->rootDirectory->getRelativePath($themeConfigFile)] =
                     $this->rootDirectory->readFile(
                         $this->rootDirectory->getRelativePath(
                             $themeConfigFile
                         )
                     );
             } else {
                 $designPath =
                     $this->componentRegistrar->getPath(
                         ComponentRegistrar::THEME,
                         $this->area . '/' . $this->themePath
                     ) . '/etc/view.xml';
                 if (file_exists($designPath)) {
                     try {
                         $designDom = new \DOMDocument;
                         $designDom->load($designPath);
                         $iterator[$designPath] = $designDom->saveXML();
                     } catch (\Exception $e) {
                         throw new \Magento\Framework\Exception\LocalizedException(
                             new \Magento\Framework\Phrase('Could not read config file')
                         );
                     }
                 }
             }
             break;
         default:
             $iterator = $this->iteratorFactory->create([]);
             break;
     }
     return $iterator;
 }
 /**
  * Extract whitelisted entries and words from configuration xml
  *
  * @param \SimpleXMLElement $configXml
  * @return \Magento\TestFramework\Inspection\WordsFinder
  * @throws \Magento\TestFramework\Inspection\Exception
  */
 protected function _extractWhitelist(\SimpleXMLElement $configXml)
 {
     // Load whitelist entries
     $whitelist = [];
     $nodes = $configXml->xpath('//config/whitelist/item');
     foreach ($nodes as $node) {
         $path = $node->xpath('path');
         if (!$path) {
             throw new \Magento\TestFramework\Inspection\Exception('A "path" must be defined for the whitelisted item');
         }
         $component = $node->xpath('component');
         if ($component) {
             $componentType = $component[0]->xpath('@type')[0];
             $componentName = $component[0]->xpath('@name')[0];
             $path = $this->componentRegistrar->getPath((string) $componentType, (string) $componentName) . '/' . (string) $path[0];
         } else {
             $path = $this->_baseDir . '/' . (string) $path[0];
         }
         // Words
         $words = [];
         $wordNodes = $node->xpath('word');
         if ($wordNodes) {
             foreach ($wordNodes as $wordNode) {
                 $words[] = (string) $wordNode;
             }
         }
         $whitelist[$path] = $words;
     }
     // Merge with already present whitelist
     foreach ($whitelist as $newPath => $newWords) {
         if (isset($this->_whitelist[$newPath])) {
             $newWords = array_merge($this->_whitelist[$newPath], $newWords);
         }
         $this->_whitelist[$newPath] = array_unique($newWords);
     }
     return $this;
 }
 /**
  * Contains all library files
  *
  * @return array
  */
 public function libraryDataProvider()
 {
     // @TODO: remove this code when class Magento\Framework\Data\Collection will fixed
     $componentRegistrar = new ComponentRegistrar();
     include_once $componentRegistrar->getPath(ComponentRegistrar::LIBRARY, 'magento/framework') . '/Option/ArrayInterface.php';
     $blackList = Files::init()->readLists(__DIR__ . '/_files/blacklist.txt');
     $dataProvider = Files::init()->getPhpFiles(Files::INCLUDE_LIBS | Files::AS_DATA_SET);
     foreach ($dataProvider as $key => $data) {
         $file = str_replace(BP . '/', '', $data[0]);
         if (in_array($file, $blackList)) {
             unset($dataProvider[$key]);
         } else {
             include_once $data[0];
         }
     }
     return $dataProvider;
 }
<?php

/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
use Magento\Framework\Component\ComponentRegistrar;
$registrar = new ComponentRegistrar();
if ($registrar->getPath(ComponentRegistrar::MODULE, 'Magento_TestModuleIntegrationFromConfig') === null) {
    ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_TestModuleIntegrationFromConfig', __DIR__);
}
<?php

/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
use Magento\Framework\Component\ComponentRegistrar;
$registrar = new ComponentRegistrar();
if ($registrar->getPath(ComponentRegistrar::MODULE, 'Magento_TestModuleJoinDirectives') === null) {
    ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_TestModuleJoinDirectives', __DIR__);
}
Beispiel #19
0
<?php

/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
use Magento\Framework\Component\ComponentRegistrar;
$registrar = new ComponentRegistrar();
if ($registrar->getPath(ComponentRegistrar::MODULE, 'Magento_TestModuleDefaultHydrator') === null) {
    ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_TestModuleDefaultHydrator', __DIR__);
}
 protected function setUp()
 {
     $this->_phraseCollector = new \Magento\Setup\Module\I18n\Parser\Adapter\Php\Tokenizer\PhraseCollector(new \Magento\Setup\Module\I18n\Parser\Adapter\Php\Tokenizer(), true, 'Magento\\Framework\\Phrase');
     $componentRegistrar = new ComponentRegistrar();
     $this->blackList = [$componentRegistrar->getPath(ComponentRegistrar::MODULE, 'Magento_Translation') . '/Model/Js/DataProvider.php'];
 }
 /**
  * @param string $fileId
  * @return string
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function getFixture($fileId)
 {
     list($moduleName, $filePath) = \Magento\Framework\View\Asset\Repository::extractModule($this->normalizePath($fileId));
     return $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, $moduleName) . '/' . $filePath;
 }
Beispiel #22
0
 /**
  * Assert that restricted classes are not used in the file
  *
  * @param string $file
  * @return void
  */
 protected function _testRestrictedClasses($file)
 {
     $content = file_get_contents($file);
     $componentRegistrar = new ComponentRegistrar();
     foreach (self::$_classes as $restrictedClass => $classRules) {
         foreach ($classRules['exclude'] as $skippedPathInfo) {
             $skippedPath = $componentRegistrar->getPath($skippedPathInfo['type'], $skippedPathInfo['name']) . '/' . $skippedPathInfo['path'];
             if (strpos($file, $skippedPath) === 0) {
                 continue 2;
             }
         }
         $this->assertFalse(\Magento\TestFramework\Utility\CodeCheck::isClassUsed($restrictedClass, $content), sprintf("Class '%s' is restricted in %s. Suggested replacement: %s", $restrictedClass, $file, $classRules['replacement']));
     }
 }
 public function testGetPath()
 {
     $this->assertSame("some/path/name/one", $this->object->getPath(ComponentRegistrar::MODULE, 'test_module_one'));
     $this->assertSame("some/path/name/two", $this->object->getPath(ComponentRegistrar::MODULE, 'test_module_two'));
 }
<?php

/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
use Magento\Framework\Component\ComponentRegistrar;
$registrar = new ComponentRegistrar();
if ($registrar->getPath(ComponentRegistrar::MODULE, 'Magento_TestModule3') === null) {
    ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_TestModule3', __DIR__);
}
Beispiel #25
0
 /**
  * Get path to the file in the library based on namespace path
  *
  * @param string $namespacePath
  * @param string $badClass
  * @return null|string
  */
 protected function getLibraryDirByPath($namespacePath, $badClass)
 {
     $libraryDir = null;
     $fullPath = null;
     $componentRegistrar = new ComponentRegistrar();
     $namespaceParts = explode('/', $namespacePath);
     if (isset($namespaceParts[1]) && $namespaceParts[1]) {
         $vendor = array_shift($namespaceParts);
         $lib = array_shift($namespaceParts);
         if ($lib == 'framework') {
             $subLib = $namespaceParts[0];
             $subLib = strtolower(preg_replace('/(.)([A-Z])/', "\$1-\$2", $subLib));
             $libraryName = $vendor . '/' . $lib . '-' . $subLib;
             $libraryDir = $componentRegistrar->getPath(ComponentRegistrar::LIBRARY, strtolower($libraryName));
             if ($libraryDir) {
                 array_shift($namespaceParts);
             } else {
                 $libraryName = $vendor . '/' . $lib;
                 $libraryDir = $componentRegistrar->getPath(ComponentRegistrar::LIBRARY, strtolower($libraryName));
             }
         } else {
             $lib = strtolower(preg_replace('/(.)([A-Z])/', "\$1-\$2", $lib));
             $libraryName = $vendor . '/' . $lib;
             $libraryDir = $componentRegistrar->getPath(ComponentRegistrar::LIBRARY, strtolower($libraryName));
         }
     }
     if ($libraryDir) {
         $fullPath = $libraryDir . '/' . implode('/', $namespaceParts) . '/' . str_replace('\\', '/', $badClass) . '.php';
     }
     return $fullPath;
 }