/** * @return string * @throws \UnexpectedValueException */ public function current() { $path = $this->directoryRead->getAbsolutePath($this->key()); $moduleName = $this->_moduleDirResolver->getModuleName($path); if (!$moduleName) { throw new \UnexpectedValueException(sprintf("Unable to determine a module, file '%s' belongs to.", $this->key())); } $contents = $this->directoryRead->readFile($this->key()); return str_replace('<template ', '<template module="' . $moduleName . '" ', $contents); }
/** * @return string * @throws \UnexpectedValueException */ public function current() { $path = $this->key(); $moduleName = $this->_moduleDirResolver->getModuleName($path); if (!$moduleName) { throw new \UnexpectedValueException(sprintf("Unable to determine a module, file '%s' belongs to.", $this->key())); } /** @var \Magento\Framework\Filesystem\File\Read $fileRead */ $fileRead = $this->fileReadFactory->create($this->key(), DriverPool::FILE); $contents = $fileRead->readAll(); return str_replace('<template ', '<template module="' . $moduleName . '" ', $contents); }
/** * @expectedException \UnexpectedValueException * @expectedExceptionMessage Unable to determine a module */ public function testReadUnknownModule() { $this->_moduleDirResolver->expects($this->once())->method('getModuleName')->will($this->returnValue(null)); $this->_converter->expects($this->never())->method('convert'); $this->_model->read('scope'); }
/** * @param string $path * @param string $expectedResult * @dataProvider getModuleNameDataProvider */ public function testGetModuleName($path, $expectedResult) { $this->_moduleList->expects($this->once())->method('getNames')->will($this->returnValue(['Fixture_ModuleOne', 'Fixture_ModuleTwo'])); $this->_moduleDirs->expects($this->atLeastOnce())->method('getDir')->will($this->returnValueMap([['Fixture_ModuleOne', '', 'app/code/Fixture/ModuleOne'], ['Fixture_ModuleTwo', '', 'app/code/Fixture/ModuleTwo']])); $this->assertSame($expectedResult, $this->_model->getModuleName($path)); }