Beispiel #1
0
 /**
  * Read configuration scope
  *
  * @return array
  *
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function read()
 {
     $fileList = [];
     foreach ($this->_scopePriorityScheme as $scope) {
         $directories = $this->_fileResolver->get($this->_fileName, $scope);
         foreach ($directories as $key => $directory) {
             $fileList[$key] = $directory;
         }
     }
     if (!count($fileList)) {
         return [];
     }
     /** @var \Magento\Framework\Config\Dom $domDocument */
     $domDocument = null;
     foreach ($fileList as $file) {
         try {
             if ($domDocument === null) {
                 $class = $this->_domDocumentClass;
                 $domDocument = new $class($file, [], null, $this->_schemaFile);
             } else {
                 $domDocument->merge($file);
             }
         } catch (\Magento\Framework\Config\Dom\ValidationException $e) {
             throw new \Magento\Framework\Exception\LocalizedException(new \Magento\Framework\Phrase("Invalid XML in file %1:\n%2", [$file, $e->getMessage()]));
         }
     }
     $output = [];
     if ($domDocument) {
         $output = $this->_converter->convert($domDocument->getDom());
     }
     return $output;
 }
 /**
  * @param string $countryCode
  * @param string $xml
  * @param string $expected
  * @dataProvider dataProviderReadOtherCountryConfig
  */
 public function testReadOtherCountryConfig($countryCode, $xml, $expected)
 {
     $this->helper->expects($this->once())->method('getConfigurationCountryCode')->willReturn($countryCode);
     $this->fileResolver->expects($this->at(0))->method('get')->willReturn([]);
     $this->fileResolver->expects($this->at(1))->method('get')->with($this->equalTo($expected))->willReturn($xml);
     $this->reader = new Reader($this->fileResolver, $this->converter, $this->schemaLocator, $this->validationState, $this->helper);
     $this->reader->read();
 }
 /**
  * Test the successful execution of the 'read' method
  *
  * @return void
  */
 public function testReadSuccessNotValidatedCase()
 {
     $content = '<config><item name="test1"></item><item name="test2"></item></config>';
     $expectedResult = ['result_data'];
     $fileList = ['file' => $content];
     $this->fileResolverMock->expects($this->once())->method('get')->with('system.xml', 'global')->willReturn($fileList);
     $this->compilerMock->expects($this->once())->method('compile')->with($this->isInstanceOf('\\DOMElement'), $this->isInstanceOf('Magento\\Framework\\DataObject'), $this->isInstanceOf('Magento\\Framework\\DataObject'));
     $this->converterMock->expects($this->once())->method('convert')->with($this->isInstanceOf('\\DOMDocument'))->willReturn($expectedResult);
     $this->assertEquals($expectedResult, $this->reader->read());
 }
Beispiel #4
0
 /**
  * @covers \Magento\Framework\App\Config\Initial\Reader::read
  */
 public function testReadValidConfig()
 {
     $testXmlFilesList = array(file_get_contents($this->_filePath . 'initial_config1.xml'), file_get_contents($this->_filePath . 'initial_config2.xml'));
     $expectedConfig = array('data' => array(), 'metadata' => array());
     $this->_fileResolverMock->expects($this->at(0))->method('get')->with('config.xml', 'global')->will($this->returnValue($testXmlFilesList));
     $this->_converterMock->expects($this->once())->method('convert')->with($this->anything())->will($this->returnValue($expectedConfig));
     $this->rootDirectory->expects($this->any())->method('getRelativePath')->will($this->returnArgument(0));
     $this->rootDirectory->expects($this->any())->method('readFile')->will($this->returnValue('<config></config>'));
     $this->assertEquals($expectedConfig, $this->_model->read());
 }
 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);
 }
Beispiel #6
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);
 }
 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');
 }
Beispiel #8
0
 /**
  * Load configuration scope
  *
  * @param string|null $scope
  * @return array
  */
 public function read($scope = null)
 {
     $scope = $scope ?: $this->_defaultScope;
     $fileList = $this->_fileResolver->get($this->_fileName, $scope);
     if (!count($fileList)) {
         return [];
     }
     $output = $this->_readFiles($fileList);
     return $output;
 }
 /**
  * @covers \Magento\Framework\App\Config\Initial\Reader::read
  * @expectedException \Magento\Framework\Exception\LocalizedException
  * @expectedExceptionMessageRegExp /Invalid XML in file \w+/
  */
 public function testReadInvalidConfig()
 {
     $this->createModelAndVerifyConstructor();
     $this->prepareDomFactoryMock();
     $testXmlFilesList = [file_get_contents($this->filePath . 'invalid_config.xml'), file_get_contents($this->filePath . 'initial_config2.xml')];
     $expectedConfig = ['data' => [], 'metadata' => []];
     $this->fileResolverMock->expects($this->at(0))->method('get')->with('config.xml', 'global')->will($this->returnValue($testXmlFilesList));
     $this->converterMock->expects($this->never())->method('convert')->with($this->anything())->will($this->returnValue($expectedConfig));
     $this->model->read();
 }