protected function setUp()
 {
     $this->validationStateMock = $this->getMock('\\Magento\\Framework\\Config\\ValidationStateInterface', [], [], '', false);
     $this->validationStateMock->method('isValidationRequired')->willReturn(true);
     $urnResolver = new \Magento\Framework\Config\Dom\UrnResolver();
     $this->schemaFile = $urnResolver->getRealPath('urn:magento:framework:App/etc/routes.xsd');
     $this->mergedSchemaFile = $urnResolver->getRealPath('urn:magento:framework:App/etc/routes_merged.xsd');
 }
Ejemplo n.º 2
0
 /**
  * @param \Magento\Framework\Config\FileResolverInterface $fileResolver
  * @param \Magento\Framework\Config\ConverterInterface $converter
  * @param SchemaLocator $schemaLocator
  * @param \Magento\Framework\Config\ValidationStateInterface $validationState
  * @param string $fileName
  * @param string $domDocumentClass
  */
 public function __construct(\Magento\Framework\Config\FileResolverInterface $fileResolver, \Magento\Framework\Config\ConverterInterface $converter, SchemaLocator $schemaLocator, \Magento\Framework\Config\ValidationStateInterface $validationState, $fileName = 'config.xml', $domDocumentClass = 'Magento\\Framework\\Config\\Dom')
 {
     $this->_schemaFile = $validationState->isValidated() ? $schemaLocator->getSchema() : null;
     $this->_fileResolver = $fileResolver;
     $this->_converter = $converter;
     $this->_domDocumentClass = $domDocumentClass;
     $this->_fileName = $fileName;
 }
Ejemplo n.º 3
0
 protected function setUp()
 {
     $this->_fileResolverMock = $this->getMock('Magento\\Framework\\Config\\FileResolverInterface');
     $this->_fileResolverMock->expects($this->once())->method('get')->with('address_formats.xml', 'scope')->will($this->returnValue([file_get_contents(__DIR__ . '/_files/formats_one.xml'), file_get_contents(__DIR__ . '/_files/formats_two.xml')]));
     $this->_converter = $this->getMock('Magento\\Customer\\Model\\Address\\Config\\Converter', ['convert']);
     $moduleReader = $this->getMock('Magento\\Framework\\Module\\Dir\\Reader', ['getModuleDir'], [], '', false);
     $moduleReader->expects($this->once())->method('getModuleDir')->with('etc', 'Magento_Customer')->will($this->returnValue('stub'));
     $this->_schemaLocator = new \Magento\Customer\Model\Address\Config\SchemaLocator($moduleReader);
     $this->_validationState = $this->getMock('Magento\\Framework\\Config\\ValidationStateInterface');
     $this->_validationState->expects($this->once())->method('isValidated')->will($this->returnValue(false));
     $this->_model = new \Magento\Customer\Model\Address\Config\Reader($this->_fileResolverMock, $this->_converter, $this->_schemaLocator, $this->_validationState);
 }
Ejemplo n.º 4
0
 /**
  * Constructor
  *
  * @param \Magento\Framework\Config\FileResolverInterface $fileResolver
  * @param \Magento\Framework\Config\ConverterInterface $converter
  * @param \Magento\Framework\Config\SchemaLocatorInterface $schemaLocator
  * @param \Magento\Framework\Config\ValidationStateInterface $validationState
  * @param string $fileName
  * @param array $idAttributes
  * @param string $domDocumentClass
  * @param string $defaultScope
  */
 public function __construct(\Magento\Framework\Config\FileResolverInterface $fileResolver, \Magento\Framework\Config\ConverterInterface $converter, \Magento\Framework\Config\SchemaLocatorInterface $schemaLocator, \Magento\Framework\Config\ValidationStateInterface $validationState, $fileName, $idAttributes = [], $domDocumentClass = 'Magento\\Framework\\Config\\Dom', $defaultScope = 'global')
 {
     $this->_fileResolver = $fileResolver;
     $this->_converter = $converter;
     $this->_fileName = $fileName;
     $this->_idAttributes = array_replace($this->_idAttributes, $idAttributes);
     $this->_schemaFile = $schemaLocator->getSchema();
     $this->_isValidated = $validationState->isValidated();
     $this->_perFileSchema = $schemaLocator->getPerFileSchema() && $this->_isValidated ? $schemaLocator->getPerFileSchema() : null;
     $this->_domDocumentClass = $domDocumentClass;
     $this->_defaultScope = $defaultScope;
 }
Ejemplo n.º 5
0
 protected function setUp()
 {
     $this->_fileResolverMock = $this->getMock('Magento\\Framework\\Config\\FileResolverInterface');
     $this->_fileResolverMock->expects($this->once())->method('get')->with('catalog_attributes.xml', 'scope')->will($this->returnValue(array(file_get_contents(__DIR__ . '/_files/attributes_config_one.xml'), file_get_contents(__DIR__ . '/_files/attributes_config_two.xml'))));
     $this->_converter = $this->getMock('Magento\\Catalog\\Model\\Attribute\\Config\\Converter', array('convert'));
     $moduleReader = $this->getMock('Magento\\Framework\\Module\\Dir\\Reader', array('getModuleDir'), array(), '', false);
     $moduleReader->expects($this->once())->method('getModuleDir')->with('etc', 'Magento_Catalog')->will($this->returnValue('stub'));
     $this->_schemaLocator = new \Magento\Catalog\Model\Attribute\Config\SchemaLocator($moduleReader);
     $this->_validationState = $this->getMock('Magento\\Framework\\Config\\ValidationStateInterface');
     $this->_validationState->expects($this->once())->method('isValidated')->will($this->returnValue(false));
     $this->_model = new \Magento\Catalog\Model\Attribute\Config\Reader($this->_fileResolverMock, $this->_converter, $this->_schemaLocator, $this->_validationState);
 }
Ejemplo n.º 6
0
 public function setUp()
 {
     $this->validationStateMock = $this->getMock(
         '\Magento\Framework\Config\ValidationStateInterface',
         [],
         [],
         '',
         false
     );
     $this->validationStateMock->method('isValidationRequired')
         ->willReturn(true);
 }
Ejemplo n.º 7
0
 protected function setUp()
 {
     $this->_fileResolverMock = $this->getMock('Magento\\Framework\\Config\\FileResolverInterface');
     $this->_fileResolverMock->expects($this->once())->method('get')->with('pdf.xml', 'scope')->will($this->returnValue([file_get_contents(__DIR__ . '/_files/pdf_one.xml'), file_get_contents(__DIR__ . '/_files/pdf_two.xml')]));
     $this->_converter = $this->getMock('Magento\\Sales\\Model\\Order\\Pdf\\Config\\Converter', ['convert']);
     $moduleReader = $this->getMock('Magento\\Framework\\Module\\Dir\\Reader', ['getModuleDir'], [], '', false);
     $moduleReader->expects($this->once())->method('getModuleDir')->with('etc', 'Magento_Sales')->will($this->returnValue('stub'));
     $this->_schemaLocator = new \Magento\Sales\Model\Order\Pdf\Config\SchemaLocator($moduleReader);
     $this->_validationState = $this->getMock('Magento\\Framework\\Config\\ValidationStateInterface');
     $this->_validationState->expects($this->any())->method('isValidationRequired')->willReturn(false);
     $this->_model = new \Magento\Sales\Model\Order\Pdf\Config\Reader($this->_fileResolverMock, $this->_converter, $this->_schemaLocator, $this->_validationState, 'pdf.xml');
 }
Ejemplo n.º 8
0
 /**
  * Set up
  *
  * @return void
  */
 protected function setUp()
 {
     $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     $this->fileUtility = \Magento\Framework\App\Utility\Files::init();
     $this->validationStateMock = $this->getMockBuilder('Magento\\Framework\\Config\\ValidationStateInterface')->setMethods(['isValidationRequired'])->getMockForAbstractClass();
     $this->schemaLocatorMock = $this->getMockBuilder('Magento\\Config\\Model\\Config\\SchemaLocator')->disableOriginalConstructor()->setMethods(['getPerFileSchema'])->getMock();
     $this->fileResolverMock = $this->getMockBuilder('Magento\\Framework\\Config\\FileResolverInterface')->getMockForAbstractClass();
     $this->validationStateMock->expects($this->atLeastOnce())->method('isValidationRequired')->willReturn(false);
     $this->schemaLocatorMock->expects($this->atLeastOnce())->method('getPerFileSchema')->willReturn(false);
     /** @var \Magento\Paypal\Model\Config\Structure\Reader\ConverterStub $converter */
     $this->converter = $this->objectManager->create('Magento\\Paypal\\Model\\Config\\Structure\\Reader\\ConverterStub');
     $this->reader = $this->objectManager->create('Magento\\Paypal\\Model\\Config\\Structure\\Reader\\ReaderStub', ['fileResolver' => $this->fileResolverMock, 'converter' => $this->converter, 'schemaLocator' => $this->schemaLocatorMock, 'validationState' => $this->validationStateMock, 'fileName' => 'no_existing_file.xml', 'domDocumentClass' => 'Magento\\Framework\\Config\\Dom']);
 }
Ejemplo n.º 9
0
 protected function setUp()
 {
     if (!function_exists('libxml_set_external_entity_loader')) {
         $this->markTestSkipped('Skipped on HHVM. Will be fixed in MAGETWO-45033');
     }
     $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->filePath = __DIR__ . '/_files/';
     $this->fileResolverMock = $this->getMock('Magento\\Framework\\Config\\FileResolverInterface');
     $this->converterMock = $this->getMock('Magento\\Framework\\App\\Config\\Initial\\Converter');
     $this->schemaLocatorMock = $this->getMock('Magento\\Framework\\App\\Config\\Initial\\SchemaLocator', [], [], '', false);
     $this->validationStateMock = $this->getMock('Magento\\Framework\\Config\\ValidationStateInterface');
     $this->validationStateMock->expects($this->any())->method('isValidationRequired')->will($this->returnValue(true));
     $this->domFactoryMock = $this->getMock('Magento\\Framework\\Config\\DomFactory', [], [], '', false);
 }
Ejemplo n.º 10
0
 /**
  * Read configuration files
  *
  * @param array $fileList
  * @return array
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function _readFiles($fileList)
 {
     /** @var \Magento\Framework\Config\Dom $configMerger */
     $configMerger = null;
     foreach ($fileList as $key => $content) {
         try {
             if (!$configMerger) {
                 $configMerger = $this->_createConfigMerger($this->_domDocumentClass, $content);
             } else {
                 $configMerger->merge($content);
             }
         } catch (\Magento\Framework\Config\Dom\ValidationException $e) {
             throw new \Magento\Framework\Exception\LocalizedException(new \Magento\Framework\Phrase("Invalid XML in file %1:\n%2", [$key, $e->getMessage()]));
         }
     }
     if ($this->validationState->isValidationRequired()) {
         $errors = [];
         if ($configMerger && !$configMerger->validate($this->_schemaFile, $errors)) {
             $message = "Invalid Document \n";
             throw new \Magento\Framework\Exception\LocalizedException(new \Magento\Framework\Phrase($message . implode("\n", $errors)));
         }
     }
     $output = [];
     if ($configMerger) {
         $output = $this->_converter->convert($configMerger->getDom());
     }
     return $output;
 }
Ejemplo n.º 11
0
 /**
  * Validate self contents towards to specified schema
  *
  * @param string|null $schemaFilePath
  * @return array
  */
 public function validate($schemaFilePath = null)
 {
     if (!$this->validationState->isValidationRequired()) {
         return [];
     }
     return $this->validateDomDocument($this->getDom(), $schemaFilePath);
 }
Ejemplo n.º 12
0
 /**
  * Validate self contents towards to specified schema
  *
  * @param string $schemaFileName absolute path to schema file
  * @param array &$errors
  * @return bool
  */
 public function validate($schemaFileName, &$errors = [])
 {
     if ($this->validationState->isValidationRequired()) {
         $errors = $this->validateDomDocument($this->dom, $schemaFileName, $this->errorFormat);
         return !count($errors);
     }
     return true;
 }
Ejemplo n.º 13
0
 protected function setUp()
 {
     $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->filePath = __DIR__ . '/_files/';
     $this->fileResolverMock = $this->getMock('Magento\Framework\Config\FileResolverInterface');
     $this->converterMock = $this->getMock('Magento\Framework\App\Config\Initial\Converter');
     $this->schemaLocatorMock = $this->getMock(
         'Magento\Framework\App\Config\Initial\SchemaLocator',
         [],
         [],
         '',
         false
     );
     $this->validationStateMock = $this->getMock('Magento\Framework\Config\ValidationStateInterface');
     $this->validationStateMock->expects($this->any())
         ->method('isValidationRequired')
         ->will($this->returnValue(true));
     $this->domFactoryMock = $this->getMock('Magento\Framework\Config\DomFactory', [], [], '', false);
 }