From fd3a80e2b1236cd7a3d53776b21107239fd79a37 Mon Sep 17 00:00:00 2001 From: Vinai Kopp Date: Wed, 14 Jan 2015 11:57:56 +0100 Subject: [PATCH 1/2] Add test to uncover glob pattern not being applied The Magento\Ui\DataProvider\Config\FileResolver does not apply the filename glob pattern passed to the method while matching files. This test triggers the error. --- .../DataProvider/Config/FileResolverTest.php | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 dev/tests/unit/testsuite/Magento/Ui/DataProvider/Config/FileResolverTest.php diff --git a/dev/tests/unit/testsuite/Magento/Ui/DataProvider/Config/FileResolverTest.php b/dev/tests/unit/testsuite/Magento/Ui/DataProvider/Config/FileResolverTest.php new file mode 100644 index 0000000000000..4d6267b183cd2 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Ui/DataProvider/Config/FileResolverTest.php @@ -0,0 +1,50 @@ +mockDirectoryRead = $this->getMockBuilder('Magento\Framework\Filesystem\Directory\Read') + ->disableOriginalConstructor() + ->getMock(); + $stubFileIteratorFactory = $this->getMockBuilder('Magento\Framework\Config\FileIteratorFactory') + ->disableOriginalConstructor() + ->getMock(); + $stubFilesystem = $this->getMockBuilder('Magento\Framework\Filesystem') + ->disableOriginalConstructor() + ->getMock(); + $stubFilesystem->expects($this->any()) + ->method('getDirectoryRead') + ->willReturn($this->mockDirectoryRead); + $this->fileResolver = new FileResolver($stubFilesystem, $stubFileIteratorFactory); + } + + /** + * @test + */ + public function itShouldApplyTheFilenamePattern() + { + $this->mockDirectoryRead->expects($this->once()) + ->method('search') + ->with($this->matchesRegularExpression('#\*\.xml$#')) + ->willReturn([]); + + $this->fileResolver->get('*.xml', ''); + } +} From 181be0d8c043ad66b50baa163d5712209a006daa Mon Sep 17 00:00:00 2001 From: Vinai Kopp Date: Thu, 15 Jan 2015 17:15:47 +0100 Subject: [PATCH 2/2] Apply pattern matching datasource config files The Magento\Ui\DataProvider\Config\FileResolver class currently uses the hardcoded pattern '/*/*/etc/data_source/*' to search for data source configuration files. The method argument $filename, which contains the file pattern that should be matched, is not used. Due to this temorarily excludng files by renaming them with a different file type ending is not possible. For example etc/data_source/customer.xml -> etc/data_source/customer.xml.off This patch applies the specified file name pattern to the pattern. --- app/code/Magento/Ui/DataProvider/Config/FileResolver.php | 2 +- .../Magento/Ui/DataProvider/Config/FileResolverTest.php | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Ui/DataProvider/Config/FileResolver.php b/app/code/Magento/Ui/DataProvider/Config/FileResolver.php index 9a5c7f1ca4d1a..97a90ce4c6bc8 100644 --- a/app/code/Magento/Ui/DataProvider/Config/FileResolver.php +++ b/app/code/Magento/Ui/DataProvider/Config/FileResolver.php @@ -45,7 +45,7 @@ public function get($filename, $scope) { $iterator = $this->iteratorFactory->create( $this->directoryRead, - $this->directoryRead->search('/*/*/etc/data_source/*') + $this->directoryRead->search('/*/*/etc/data_source/' . $filename) ); return $iterator; } diff --git a/dev/tests/unit/testsuite/Magento/Ui/DataProvider/Config/FileResolverTest.php b/dev/tests/unit/testsuite/Magento/Ui/DataProvider/Config/FileResolverTest.php index 4d6267b183cd2..7131ec8c5302f 100644 --- a/dev/tests/unit/testsuite/Magento/Ui/DataProvider/Config/FileResolverTest.php +++ b/dev/tests/unit/testsuite/Magento/Ui/DataProvider/Config/FileResolverTest.php @@ -35,10 +35,7 @@ public function setUp() $this->fileResolver = new FileResolver($stubFilesystem, $stubFileIteratorFactory); } - /** - * @test - */ - public function itShouldApplyTheFilenamePattern() + public function testItAppliesTheFilenamePattern() { $this->mockDirectoryRead->expects($this->once()) ->method('search')