diff --git a/lib/internal/Magento/Framework/Config/GenericSchemaLocator.php b/lib/internal/Magento/Framework/Config/GenericSchemaLocator.php new file mode 100644 index 0000000000000..25ae19c7e4d72 --- /dev/null +++ b/lib/internal/Magento/Framework/Config/GenericSchemaLocator.php @@ -0,0 +1,67 @@ +moduleDirReader = $reader; + $this->moduleName = $moduleName; + $this->schema = $schema; + $this->perFileSchema = $perFileSchema; + } + + /** + * Get path to merged config schema + * + * @return string|null + */ + public function getSchema() + { + return $this->moduleDirReader->getModuleDir('etc', $this->moduleName) . '/' . $this->schema; + } + + /** + * Get path to per file validation schema + * + * @return string|null + */ + public function getPerFileSchema() + { + return is_null($this->perFileSchema) ? + null : + $this->moduleDirReader->getModuleDir('etc', $this->moduleName) . '/' . $this->perFileSchema; + } +} diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/GenericSchemaLocatorTest.php b/lib/internal/Magento/Framework/Config/Test/Unit/GenericSchemaLocatorTest.php new file mode 100644 index 0000000000000..8c4dd47949899 --- /dev/null +++ b/lib/internal/Magento/Framework/Config/Test/Unit/GenericSchemaLocatorTest.php @@ -0,0 +1,73 @@ +moduleReaderMock = $this->getMock(ModuleDirReader::class, [], [], '', false); + $this->schemaLocator = $this->createNewSchemaLocatorInstance( + $this->moduleReaderMock, + 'Test_ModuleName', + $this->testSchemaFileName, + null + ); + } + + public function testItIsAnInstanceOfSchemaLocatorInterface() + { + $this->assertInstanceOf(SchemaLocatorInterface::class, $this->schemaLocator); + } + + public function testItReturnsThePathToTheSpecifiedModuleXsd() + { + $this->moduleReaderMock->expects($this->any())->method('getModuleDir')->willReturn('....'); + $this->assertSame('..../' . $this->testSchemaFileName, $this->schemaLocator->getSchema()); + } + + public function testItReturnsNullAsTheDefaultPerFileSchema() + { + $this->assertNull($this->schemaLocator->getPerFileSchema()); + } + + public function testItReturnsThePathToThePerFileSchema() + { + $this->moduleReaderMock->expects($this->any())->method('getModuleDir')->willReturn('....'); + $schemaLocator = $this->createNewSchemaLocatorInstance( + $this->moduleReaderMock, + 'Test_ModuleName', + 'some other file name', + $this->testSchemaFileName + ); + $this->assertSame('..../' . $this->testSchemaFileName, $schemaLocator->getPerFileSchema()); + } +}