/** * @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); }
/** * @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)); }