From e786d514ef72699bdedada6444665d882dd015c3 Mon Sep 17 00:00:00 2001 From: Will Wright Date: Tue, 28 Jul 2020 22:41:30 -0700 Subject: [PATCH 01/33] magento/magento2#29315: \Magento\Config\Model\Config\Source\Email\Template::toOptionArray throws error when setPath() is not called first - Guard against an edge case where toOptionArray is called without having set a path first --- .../Model/Config/Source/Email/Template.php | 10 ++-- .../Config/Source/Email/TemplateTest.php | 46 ++++++++++++++++++- 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Config/Model/Config/Source/Email/Template.php b/app/code/Magento/Config/Model/Config/Source/Email/Template.php index ac168f16ca182..182faa53e5288 100644 --- a/app/code/Magento/Config/Model/Config/Source/Email/Template.php +++ b/app/code/Magento/Config/Model/Config/Source/Email/Template.php @@ -60,10 +60,12 @@ public function toOptionArray() $this->_coreRegistry->register('config_system_email_template', $collection); } $options = $collection->toOptionArray(); - $templateId = str_replace('/', '_', $this->getPath()); - $templateLabel = $this->_emailConfig->getTemplateLabel($templateId); - $templateLabel = __('%1 (Default)', $templateLabel); - array_unshift($options, ['value' => $templateId, 'label' => $templateLabel]); + if (!empty($this->getPath())) { + $templateId = str_replace('/', '_', $this->getPath()); + $templateLabel = $this->_emailConfig->getTemplateLabel($templateId); + $templateLabel = __('%1 (Default)', $templateLabel); + array_unshift($options, ['value' => $templateId, 'label' => $templateLabel]); + } return $options; } } diff --git a/app/code/Magento/Config/Test/Unit/Model/Config/Source/Email/TemplateTest.php b/app/code/Magento/Config/Test/Unit/Model/Config/Source/Email/TemplateTest.php index 356d1133aca81..74ab4baa4e990 100644 --- a/app/code/Magento/Config/Test/Unit/Model/Config/Source/Email/TemplateTest.php +++ b/app/code/Magento/Config/Test/Unit/Model/Config/Source/Email/TemplateTest.php @@ -102,4 +102,48 @@ public function testToOptionArray() $this->_model->setPath('template/new'); $this->assertEquals($expectedResult, $this->_model->toOptionArray()); } -} + + public function testToOptionArrayWithoutPath() + { + $collection = $this->createMock(Collection::class); + $collection->expects( + $this->once() + )->method( + 'toOptionArray' + )->willReturn( + [ + ['value' => 'template_one', 'label' => 'Template One'], + ['value' => 'template_two', 'label' => 'Template Two'], + ] + ); + + $this->_coreRegistry->expects( + $this->once() + )->method( + 'registry' + )->with( + 'config_system_email_template' + )->willReturn( + $collection + ); + + $this->_emailConfig->expects( + $this->never() + )->method( + 'getTemplateLabel' + )->with('') + ->willThrowException(new \UnexpectedValueException("Email template '' is not defined.")); + + $expectedResult = [ + [ + 'value' => 'template_one', + 'label' => 'Template One', + ], + [ + 'value' => 'template_two', + 'label' => 'Template Two', + ], + ]; + + $this->assertEquals($expectedResult, $this->_model->toOptionArray()); + }} From e0972bf2ac019a1b4645f2aaa7ac2e6016859fe5 Mon Sep 17 00:00:00 2001 From: Will Wright Date: Wed, 29 Jul 2020 22:15:00 -0700 Subject: [PATCH 02/33] magento/magento2#29315: \Magento\Config\Model\Config\Source\Email\Template::toOptionArray throws error when setPath() is not called first - Fix formatting for static tests --- .../Unit/Model/Config/Source/Email/TemplateTest.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Config/Test/Unit/Model/Config/Source/Email/TemplateTest.php b/app/code/Magento/Config/Test/Unit/Model/Config/Source/Email/TemplateTest.php index 74ab4baa4e990..9b531280f66c6 100644 --- a/app/code/Magento/Config/Test/Unit/Model/Config/Source/Email/TemplateTest.php +++ b/app/code/Magento/Config/Test/Unit/Model/Config/Source/Email/TemplateTest.php @@ -131,8 +131,12 @@ public function testToOptionArrayWithoutPath() $this->never() )->method( 'getTemplateLabel' - )->with('') - ->willThrowException(new \UnexpectedValueException("Email template '' is not defined.")); + )->with( + '' + ) + ->willThrowException( + new \UnexpectedValueException("Email template '' is not defined.") + ); $expectedResult = [ [ @@ -146,4 +150,5 @@ public function testToOptionArrayWithoutPath() ]; $this->assertEquals($expectedResult, $this->_model->toOptionArray()); - }} + } +} From 8f43c639da9fc2f8fbb4394fc38889f718b584b6 Mon Sep 17 00:00:00 2001 From: oleksandrkravchuk Date: Thu, 30 Jul 2020 23:01:54 +0300 Subject: [PATCH 03/33] community-features#252 Create static test for action controllers. Add Legacy test to check if newly created controllers do not extend AbstractAction. --- .../Magento/App/Action/AbstractActionTest.php | 160 ++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 dev/tests/static/testsuite/Magento/Test/Legacy/Magento/App/Action/AbstractActionTest.php diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/Magento/App/Action/AbstractActionTest.php b/dev/tests/static/testsuite/Magento/Test/Legacy/Magento/App/Action/AbstractActionTest.php new file mode 100644 index 0000000000000..472b557ab389f --- /dev/null +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/Magento/App/Action/AbstractActionTest.php @@ -0,0 +1,160 @@ +classNameExtractor = new ClassNameExtractor(); + $this->fileUtilities = Files::init(); + } + + /** + * Test new + * + */ + public function testNewControllersDoNotExtendAbstractAction(): void + { + $files = $this->getTestFiles(); + $found = []; + + foreach ($files as $file) { + $class = $this->classNameExtractor->getNameWithNamespace(file_get_contents($file[0])); + + if ($class) { + try { + $classReflection = new ReflectionClass($class); + if ($classReflection->isSubclassOf(AbstractAction::class)) { + $found[] = $class; + } + } catch (Exception $exception) { + $this->addWarning('Skipped due to exception: ' . $class); + } + } + } + + $this->assertEmpty( + $found, + "The following new controller(s) extend " . AbstractAction::class . "\r\n" + . "All new controller classes must implement " . ActionInterface::class . " instead.\r\n" + . print_r($found, true) + ); + } + + /** + * Provide files for test. + * + * @return array + */ + private function getTestFiles(): array + { + $phpFiles = self::getAddedFilesList(self::getChangedFilesBaseDir()); + + $phpFiles = Files::composeDataSets($phpFiles); + $fileTypes = Files::INCLUDE_APP_CODE | Files::INCLUDE_LIBS | Files::AS_DATA_SET; + return array_intersect_key($phpFiles, $this->fileUtilities->getPhpFiles($fileTypes)); + } + + /** + * Provide list of new files. + * + * @param $changedFilesBaseDir + * + * @return string[] + */ + private static function getAddedFilesList($changedFilesBaseDir) + { + return self::getFilesFromListFile( + $changedFilesBaseDir, + 'changed_files*.added.*', + function () { + // if no list files, probably, this is the dev environment + // phpcs:ignore Generic.PHP.NoSilencedErrors,Magento2.Security.InsecureFunction + @exec('git diff --cached --name-only --diff-filter=A', $addedFiles); + return $addedFiles; + } + ); + } + + /** + * Read files from generated lists. + * + * @param string $listsBaseDir + * @param string $listFilePattern + * @param callable $noListCallback + * @return string[] + */ + private static function getFilesFromListFile( + string $listsBaseDir, + string $listFilePattern, + callable $noListCallback + ): array { + $filesDefinedInList = []; + + $listFiles = glob($listsBaseDir . '/_files/' . $listFilePattern); + if (!empty($listFiles)) { + foreach ($listFiles as $listFile) { + // phpcs:ignore Magento2.Performance.ForeachArrayMerge.ForeachArrayMerge + $filesDefinedInList = array_merge( + $filesDefinedInList, + file($listFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) + ); + } + } else { + $filesDefinedInList = call_user_func($noListCallback); + } + + array_walk( + $filesDefinedInList, + function (&$file) { + $file = BP . '/' . $file; + } + ); + + $filesDefinedInList = array_values(array_unique($filesDefinedInList)); + + return $filesDefinedInList; + } + + /** + * Returns base directory for generated lists. + * + * @return string + */ + private static function getChangedFilesBaseDir(): string + { + return BP . DIRECTORY_SEPARATOR . 'dev' . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'static' . + DIRECTORY_SEPARATOR . 'testsuite' . DIRECTORY_SEPARATOR . 'Magento' . DIRECTORY_SEPARATOR . 'Test'; + } +} From 602dc6894a0ba909d3b631a28155ab58459aa12d Mon Sep 17 00:00:00 2001 From: Oleksandr Kravchuk Date: Fri, 31 Jul 2020 09:26:31 +0300 Subject: [PATCH 04/33] Update dev/tests/static/testsuite/Magento/Test/Legacy/Magento/App/Action/AbstractActionTest.php Refactoring. Co-authored-by: Ihor Sviziev --- .../Test/Legacy/Magento/App/Action/AbstractActionTest.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/Magento/App/Action/AbstractActionTest.php b/dev/tests/static/testsuite/Magento/Test/Legacy/Magento/App/Action/AbstractActionTest.php index 472b557ab389f..ced06dcc4ada6 100644 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/Magento/App/Action/AbstractActionTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/Magento/App/Action/AbstractActionTest.php @@ -125,12 +125,10 @@ private static function getFilesFromListFile( $listFiles = glob($listsBaseDir . '/_files/' . $listFilePattern); if (!empty($listFiles)) { foreach ($listFiles as $listFile) { - // phpcs:ignore Magento2.Performance.ForeachArrayMerge.ForeachArrayMerge - $filesDefinedInList = array_merge( - $filesDefinedInList, - file($listFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) - ); + $filesDefinedInList[] = file($listFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); } + + $filesDefinedInList = array_merge([], ...$filesDefinedInList); } else { $filesDefinedInList = call_user_func($noListCallback); } From 9342d4c0e01664a8e155160118ab70f49aeb9225 Mon Sep 17 00:00:00 2001 From: oleksandrkravchuk Date: Fri, 31 Jul 2020 10:03:52 +0200 Subject: [PATCH 05/33] community-features#252 Create static test for action controllers. Fix static tests. --- .../Magento/App/Action/AbstractActionTest.php | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/Magento/App/Action/AbstractActionTest.php b/dev/tests/static/testsuite/Magento/Test/Legacy/Magento/App/Action/AbstractActionTest.php index ced06dcc4ada6..d109b263b6b84 100644 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/Magento/App/Action/AbstractActionTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/Magento/App/Action/AbstractActionTest.php @@ -5,7 +5,7 @@ */ declare(strict_types=1); -namespace Magento\Test\Legacy\App\Action; +namespace Magento\Test\Legacy\Magento\App\Action; use Exception; use Magento\Framework\App\Action\AbstractAction; @@ -41,9 +41,8 @@ protected function setUp(): void } /** - * Test new - * - */ + * Test newly created controllers do not extend deprecated AbstractAction. + */ public function testNewControllersDoNotExtendAbstractAction(): void { $files = $this->getTestFiles(); @@ -121,25 +120,21 @@ private static function getFilesFromListFile( callable $noListCallback ): array { $filesDefinedInList = []; - $listFiles = glob($listsBaseDir . '/_files/' . $listFilePattern); if (!empty($listFiles)) { foreach ($listFiles as $listFile) { $filesDefinedInList[] = file($listFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); } - - $filesDefinedInList = array_merge([], ...$filesDefinedInList); + $filesDefinedInList = array_merge([], ...$filesDefinedInList); } else { $filesDefinedInList = call_user_func($noListCallback); } - array_walk( $filesDefinedInList, function (&$file) { $file = BP . '/' . $file; } ); - $filesDefinedInList = array_values(array_unique($filesDefinedInList)); return $filesDefinedInList; From 8195b0c1ff66189ad50f7b25c5724f2bff36d365 Mon Sep 17 00:00:00 2001 From: oleksandrkravchuk Date: Fri, 31 Jul 2020 12:04:40 +0200 Subject: [PATCH 06/33] community-features#252 Create static test for action controllers. Fix static tests. --- .../Magento/{ => Framework}/App/Action/AbstractActionTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename dev/tests/static/testsuite/Magento/Test/Legacy/Magento/{ => Framework}/App/Action/AbstractActionTest.php (98%) diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/Magento/App/Action/AbstractActionTest.php b/dev/tests/static/testsuite/Magento/Test/Legacy/Magento/Framework/App/Action/AbstractActionTest.php similarity index 98% rename from dev/tests/static/testsuite/Magento/Test/Legacy/Magento/App/Action/AbstractActionTest.php rename to dev/tests/static/testsuite/Magento/Test/Legacy/Magento/Framework/App/Action/AbstractActionTest.php index d109b263b6b84..d5427752004d9 100644 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/Magento/App/Action/AbstractActionTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/Magento/Framework/App/Action/AbstractActionTest.php @@ -5,7 +5,7 @@ */ declare(strict_types=1); -namespace Magento\Test\Legacy\Magento\App\Action; +namespace Magento\Test\Legacy\Magento\Framework\App\Action; use Exception; use Magento\Framework\App\Action\AbstractAction; From 308a5f46cf4378efff331d5ac3035310c009c4fd Mon Sep 17 00:00:00 2001 From: oleksandrkravchuk Date: Mon, 3 Aug 2020 21:44:10 +0200 Subject: [PATCH 07/33] community-features#252 Create static test for action controllers. Incapsulate logic in new class. Add test coverage. --- .../integration/etc/config-global.php.dist | 11 ---- .../Utility/ChildrenClassesSearch.php | 53 +++++++++++++++++++ .../Utility/ChildrenClassesSearchTest.php | 39 ++++++++++++++ .../Utility/PartialNamespace/Baz.php | 23 ++++++++ .../Utility/PartialNamespace/Foo.php | 34 ++++++++++++ .../App/Action/AbstractActionTest.php | 28 +++------- 6 files changed, 156 insertions(+), 32 deletions(-) delete mode 100644 dev/tests/integration/etc/config-global.php.dist create mode 100644 dev/tests/static/framework/Magento/TestFramework/Utility/ChildrenClassesSearch.php create mode 100644 dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearchTest.php create mode 100644 dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/PartialNamespace/Baz.php create mode 100644 dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/PartialNamespace/Foo.php diff --git a/dev/tests/integration/etc/config-global.php.dist b/dev/tests/integration/etc/config-global.php.dist deleted file mode 100644 index fbc6714859529..0000000000000 --- a/dev/tests/integration/etc/config-global.php.dist +++ /dev/null @@ -1,11 +0,0 @@ - 0, - 'admin/security/admin_account_sharing' => 1, - 'admin/security/limit_password_reset_requests_method' => 0, -]; diff --git a/dev/tests/static/framework/Magento/TestFramework/Utility/ChildrenClassesSearch.php b/dev/tests/static/framework/Magento/TestFramework/Utility/ChildrenClassesSearch.php new file mode 100644 index 0000000000000..6905e1b4f442c --- /dev/null +++ b/dev/tests/static/framework/Magento/TestFramework/Utility/ChildrenClassesSearch.php @@ -0,0 +1,53 @@ +classNameExtractor = new ClassNameExtractor(); + } + + /** + * Get list of classes name which are subclasses of mentioned class. + * + * @param array $fileList + * @param string $parent + * @param bool $asDataSet + * + * @return array + * @throws \ReflectionException + */ + public function getClassesWhichAreChildrenOf(array $fileList, string $parent, bool $asDataSet = true): array + { + $found = []; + + foreach ($fileList as $file) { + $name = $asDataSet ? $file[0] : $file; + $class = $this->classNameExtractor->getNameWithNamespace(file_get_contents($name)); + + if ($class) { + $classReflection = new \ReflectionClass($class); + if ($classReflection->isSubclassOf($parent)) { + $found[] = $class; + } + } + } + + return $found; + } +} diff --git a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearchTest.php b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearchTest.php new file mode 100644 index 0000000000000..9947414f7d364 --- /dev/null +++ b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearchTest.php @@ -0,0 +1,39 @@ +childrenClassesSearch = new ChildrenClassesSearch(); + } + + public function testChildrenSearch(): void + { + $files = [ + __DIR__ . '/PartialNamespace/Foo.php', + __DIR__ . '/PartialNamespace/Bar.php', + __DIR__ . '/PartialNamespace/Baz.php', + ]; + + $found = $this->childrenClassesSearch->getClassesWhichAreChildrenOf( + $files, + AbstractAction::class, + false + ); + + $this->assertCount(1, $found); + $this->assertEquals(current($found), \Magento\TestFramework\Utility\PartialNamespace\Foo::class); + } +} diff --git a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/PartialNamespace/Baz.php b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/PartialNamespace/Baz.php new file mode 100644 index 0000000000000..1b54259b348ea --- /dev/null +++ b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/PartialNamespace/Baz.php @@ -0,0 +1,23 @@ +classNameExtractor = new ClassNameExtractor(); + $this->childrenClassesSearch = new ChildrenClassesSearch(); $this->fileUtilities = Files::init(); } /** * Test newly created controllers do not extend deprecated AbstractAction. + * + * @throws \ReflectionException */ public function testNewControllersDoNotExtendAbstractAction(): void { $files = $this->getTestFiles(); - $found = []; - - foreach ($files as $file) { - $class = $this->classNameExtractor->getNameWithNamespace(file_get_contents($file[0])); - if ($class) { - try { - $classReflection = new ReflectionClass($class); - if ($classReflection->isSubclassOf(AbstractAction::class)) { - $found[] = $class; - } - } catch (Exception $exception) { - $this->addWarning('Skipped due to exception: ' . $class); - } - } - } + $found = $this->childrenClassesSearch->getClassesWhichAreChildrenOf($files, AbstractAction::class); $this->assertEmpty( $found, From 125a5d4f02ac12e9323e9f9ce0af01b9da21a62c Mon Sep 17 00:00:00 2001 From: oleksandrkravchuk Date: Tue, 4 Aug 2020 09:20:39 +0200 Subject: [PATCH 08/33] community-features#252 Create static test for action controllers. Recover accidentally removed file. --- dev/tests/integration/etc/config-global.php.dist | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 dev/tests/integration/etc/config-global.php.dist diff --git a/dev/tests/integration/etc/config-global.php.dist b/dev/tests/integration/etc/config-global.php.dist new file mode 100644 index 0000000000000..fbc6714859529 --- /dev/null +++ b/dev/tests/integration/etc/config-global.php.dist @@ -0,0 +1,11 @@ + 0, + 'admin/security/admin_account_sharing' => 1, + 'admin/security/limit_password_reset_requests_method' => 0, +]; From 87a70e92e3d60f087bf0fe6dd380f27ef300d351 Mon Sep 17 00:00:00 2001 From: oleksandrkravchuk Date: Tue, 4 Aug 2020 18:17:04 +0200 Subject: [PATCH 09/33] community-features#252 Create static test for action controllers. Apply code review changes. --- .../TestFramework/Utility/AddedFiles.php | 35 ++++++++++ .../TestFramework/Utility/FilesSearch.php | 48 +++++++++++++ .../Utility/ChildrenClassesSearch/A.php | 10 +++ .../Utility/ChildrenClassesSearch/B.php | 10 +++ .../Utility/ChildrenClassesSearch/C.php | 10 +++ .../Utility/ChildrenClassesSearch/D.php | 10 +++ .../Utility/ChildrenClassesSearch/E.php | 10 +++ .../Utility/ChildrenClassesSearch/F.php | 10 +++ .../Utility/ChildrenClassesSearch/Z.php | 10 +++ .../Utility/ChildrenClassesSearchTest.php | 31 ++++++--- .../TestFramework/Utility/FilesSearchTest.php | 54 +++++++++++++++ .../Utility/PartialNamespace/Baz.php | 23 ------- .../Utility/PartialNamespace/Foo.php | 34 ---------- .../_files/changed_files_some_name_test.txt | 3 + .../App/Action/AbstractActionTest.php | 60 +---------------- .../Magento/Test/Php/LiveCodeTest.php | 67 ++----------------- 16 files changed, 241 insertions(+), 184 deletions(-) create mode 100644 dev/tests/static/framework/Magento/TestFramework/Utility/AddedFiles.php create mode 100644 dev/tests/static/framework/Magento/TestFramework/Utility/FilesSearch.php create mode 100644 dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/A.php create mode 100644 dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/B.php create mode 100644 dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/C.php create mode 100644 dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/D.php create mode 100644 dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/E.php create mode 100644 dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/F.php create mode 100644 dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/Z.php create mode 100644 dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/FilesSearchTest.php delete mode 100644 dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/PartialNamespace/Baz.php delete mode 100644 dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/PartialNamespace/Foo.php create mode 100644 dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/_files/changed_files_some_name_test.txt diff --git a/dev/tests/static/framework/Magento/TestFramework/Utility/AddedFiles.php b/dev/tests/static/framework/Magento/TestFramework/Utility/AddedFiles.php new file mode 100644 index 0000000000000..6b1184418e16e --- /dev/null +++ b/dev/tests/static/framework/Magento/TestFramework/Utility/AddedFiles.php @@ -0,0 +1,35 @@ +childrenClassesSearch->getClassesWhichAreChildrenOf( $files, - AbstractAction::class, + A::class, false ); - $this->assertCount(1, $found); - $this->assertEquals(current($found), \Magento\TestFramework\Utility\PartialNamespace\Foo::class); + $expected = [ + B::class, + E::class, + F::class + ]; + + $this->assertSame($expected, $found); } } diff --git a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/FilesSearchTest.php b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/FilesSearchTest.php new file mode 100644 index 0000000000000..8c1206c56ce8e --- /dev/null +++ b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/FilesSearchTest.php @@ -0,0 +1,54 @@ +assertSame($files, $expected); + } + + /** + * Test callblack function in case when files with lists did not found. + */ + public function testGetEmptyList(): void + { + $pattern = 'zzz.txt'; + + + $files = FilesSearch::getFilesFromListFile(__DIR__, $pattern, function () { + return ['1', '2', '3']; + }); + + $expected = [ + BP . '/1', + BP . '/2', + BP . '/3' + ]; + + $this->assertSame($files, $expected); + } +} diff --git a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/PartialNamespace/Baz.php b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/PartialNamespace/Baz.php deleted file mode 100644 index 1b54259b348ea..0000000000000 --- a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/PartialNamespace/Baz.php +++ /dev/null @@ -1,23 +0,0 @@ -getChangedFilesBaseDir()); $phpFiles = Files::composeDataSets($phpFiles); $fileTypes = Files::INCLUDE_APP_CODE | Files::INCLUDE_LIBS | Files::AS_DATA_SET; return array_intersect_key($phpFiles, $this->fileUtilities->getPhpFiles($fileTypes)); } - /** - * Provide list of new files. - * - * @param $changedFilesBaseDir - * - * @return string[] - */ - private static function getAddedFilesList($changedFilesBaseDir) - { - return self::getFilesFromListFile( - $changedFilesBaseDir, - 'changed_files*.added.*', - function () { - // if no list files, probably, this is the dev environment - // phpcs:ignore Generic.PHP.NoSilencedErrors,Magento2.Security.InsecureFunction - @exec('git diff --cached --name-only --diff-filter=A', $addedFiles); - return $addedFiles; - } - ); - } - - /** - * Read files from generated lists. - * - * @param string $listsBaseDir - * @param string $listFilePattern - * @param callable $noListCallback - * @return string[] - */ - private static function getFilesFromListFile( - string $listsBaseDir, - string $listFilePattern, - callable $noListCallback - ): array { - $filesDefinedInList = []; - $listFiles = glob($listsBaseDir . '/_files/' . $listFilePattern); - if (!empty($listFiles)) { - foreach ($listFiles as $listFile) { - $filesDefinedInList[] = file($listFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); - } - $filesDefinedInList = array_merge([], ...$filesDefinedInList); - } else { - $filesDefinedInList = call_user_func($noListCallback); - } - array_walk( - $filesDefinedInList, - function (&$file) { - $file = BP . '/' . $file; - } - ); - $filesDefinedInList = array_values(array_unique($filesDefinedInList)); - - return $filesDefinedInList; - } - /** * Returns base directory for generated lists. * * @return string */ - private static function getChangedFilesBaseDir(): string + private function getChangedFilesBaseDir(): string { return BP . DIRECTORY_SEPARATOR . 'dev' . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'static' . DIRECTORY_SEPARATOR . 'testsuite' . DIRECTORY_SEPARATOR . 'Magento' . DIRECTORY_SEPARATOR . 'Test'; diff --git a/dev/tests/static/testsuite/Magento/Test/Php/LiveCodeTest.php b/dev/tests/static/testsuite/Magento/Test/Php/LiveCodeTest.php index 324753b4bd4ec..ad91025448579 100644 --- a/dev/tests/static/testsuite/Magento/Test/Php/LiveCodeTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Php/LiveCodeTest.php @@ -14,6 +14,8 @@ use Magento\TestFramework\CodingStandard\Tool\CopyPasteDetector; use Magento\TestFramework\CodingStandard\Tool\PhpCompatibility; use Magento\TestFramework\CodingStandard\Tool\PhpStan; +use Magento\TestFramework\Utility\AddedFiles; +use Magento\TestFramework\Utility\FilesSearch; use PHPMD\TextUI\Command; /** @@ -113,8 +115,8 @@ public static function getWhitelist( */ private static function getChangedFilesList($changedFilesBaseDir) { - return self::getFilesFromListFile( - $changedFilesBaseDir, + return FilesSearch::getFilesFromListFile( + $changedFilesBaseDir ?: self::getChangedFilesBaseDir(), 'changed_files*', function () { // if no list files, probably, this is the dev environment @@ -128,65 +130,6 @@ function () { ); } - /** - * This method loads list of added files. - * - * @param string $changedFilesBaseDir - * @return string[] - */ - private static function getAddedFilesList($changedFilesBaseDir) - { - return self::getFilesFromListFile( - $changedFilesBaseDir, - 'changed_files*.added.*', - function () { - // if no list files, probably, this is the dev environment - // phpcs:ignore Generic.PHP.NoSilencedErrors,Magento2.Security.InsecureFunction - @exec('git diff --cached --name-only --diff-filter=A', $addedFiles); - return $addedFiles; - } - ); - } - - /** - * Read files from generated lists. - * - * @param string $listsBaseDir - * @param string $listFilePattern - * @param callable $noListCallback - * @return string[] - */ - private static function getFilesFromListFile($listsBaseDir, $listFilePattern, $noListCallback) - { - $filesDefinedInList = []; - - $globFilesListPattern = ($listsBaseDir ?: self::getChangedFilesBaseDir()) - . '/_files/' . $listFilePattern; - $listFiles = glob($globFilesListPattern); - if (!empty($listFiles)) { - foreach ($listFiles as $listFile) { - // phpcs:ignore Magento2.Performance.ForeachArrayMerge.ForeachArrayMerge - $filesDefinedInList = array_merge( - $filesDefinedInList, - file($listFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) - ); - } - } else { - $filesDefinedInList = call_user_func($noListCallback); - } - - array_walk( - $filesDefinedInList, - function (&$file) { - $file = BP . '/' . $file; - } - ); - - $filesDefinedInList = array_values(array_unique($filesDefinedInList)); - - return $filesDefinedInList; - } - /** * Filter list of files. * @@ -427,7 +370,7 @@ public function testCopyPaste() */ public function testStrictTypes() { - $changedFiles = self::getAddedFilesList(''); + $changedFiles = AddedFiles::getAddedFilesList(self::getChangedFilesBaseDir()); try { $blackList = Files::init()->readLists( From 0b92de976b8c57c241672608886f87e681bcd0bd Mon Sep 17 00:00:00 2001 From: oleksandrkravchuk Date: Tue, 4 Aug 2020 22:06:46 +0200 Subject: [PATCH 10/33] community-features#252 Create static test for action controllers. Fix static tests. --- .../framework/Magento/TestFramework/Utility/AddedFiles.php | 2 +- .../Magento/TestFramework/Utility/ChildrenClassesSearch.php | 3 +++ .../Magento/TestFramework/Utility/ChildrenClassesSearch/Z.php | 2 ++ .../Magento/TestFramework/Utility/FilesSearchTest.php | 1 - 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/dev/tests/static/framework/Magento/TestFramework/Utility/AddedFiles.php b/dev/tests/static/framework/Magento/TestFramework/Utility/AddedFiles.php index 6b1184418e16e..4afeda3a035eb 100644 --- a/dev/tests/static/framework/Magento/TestFramework/Utility/AddedFiles.php +++ b/dev/tests/static/framework/Magento/TestFramework/Utility/AddedFiles.php @@ -15,7 +15,7 @@ class AddedFiles /** * Provide list of new files. * - * @param $changedFilesBaseDir + * @param string $changedFilesBaseDir * * @return string[] */ diff --git a/dev/tests/static/framework/Magento/TestFramework/Utility/ChildrenClassesSearch.php b/dev/tests/static/framework/Magento/TestFramework/Utility/ChildrenClassesSearch.php index 6905e1b4f442c..53db8ca8d0b08 100644 --- a/dev/tests/static/framework/Magento/TestFramework/Utility/ChildrenClassesSearch.php +++ b/dev/tests/static/framework/Magento/TestFramework/Utility/ChildrenClassesSearch.php @@ -17,6 +17,9 @@ class ChildrenClassesSearch */ private $classNameExtractor; + /** + * ChildrenClassesSearch constructor. + */ public function __construct() { $this->classNameExtractor = new ClassNameExtractor(); diff --git a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/Z.php b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/Z.php index 2ac48bda187b6..1ec713366dde8 100644 --- a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/Z.php +++ b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/Z.php @@ -5,6 +5,8 @@ */ namespace Magento\TestFramework\Utility\ChildrenClassesSearch; +// @codingStandardsIgnoreStar interface Z { } +// @codingStandardsIgnoreEnd diff --git a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/FilesSearchTest.php b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/FilesSearchTest.php index 8c1206c56ce8e..7b27dde3b0bf4 100644 --- a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/FilesSearchTest.php +++ b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/FilesSearchTest.php @@ -38,7 +38,6 @@ public function testGetEmptyList(): void { $pattern = 'zzz.txt'; - $files = FilesSearch::getFilesFromListFile(__DIR__, $pattern, function () { return ['1', '2', '3']; }); From a493bc5769b59b4f2635a09382b379e44dec950a Mon Sep 17 00:00:00 2001 From: oleksandrkravchuk Date: Wed, 5 Aug 2020 14:41:32 +0300 Subject: [PATCH 11/33] community-features#252 Create static test for action controllers.. Fix static tests. --- .../Magento/TestFramework/Utility/ChildrenClassesSearch/C.php | 2 +- .../Magento/TestFramework/Utility/ChildrenClassesSearch/F.php | 2 +- .../Utility/ChildrenClassesSearch/{Z.php => ZInterface.php} | 4 +--- .../TestFramework/Utility/ChildrenClassesSearchTest.php | 2 +- 4 files changed, 4 insertions(+), 6 deletions(-) rename dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/{Z.php => ZInterface.php} (70%) diff --git a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/C.php b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/C.php index 1fe77df4a7f15..e50735fcbb46c 100644 --- a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/C.php +++ b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/C.php @@ -5,6 +5,6 @@ */ namespace Magento\TestFramework\Utility\ChildrenClassesSearch; -class C implements Z +class C implements ZInterface { } diff --git a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/F.php b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/F.php index 5c7b8d8fb17af..6976ed26a0d84 100644 --- a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/F.php +++ b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/F.php @@ -5,6 +5,6 @@ */ namespace Magento\TestFramework\Utility\ChildrenClassesSearch; -class F extends E implements Z +class F extends E implements ZInterface { } diff --git a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/Z.php b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/ZInterface.php similarity index 70% rename from dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/Z.php rename to dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/ZInterface.php index 1ec713366dde8..be1b6d222519c 100644 --- a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/Z.php +++ b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearch/ZInterface.php @@ -5,8 +5,6 @@ */ namespace Magento\TestFramework\Utility\ChildrenClassesSearch; -// @codingStandardsIgnoreStar -interface Z +interface ZInterface { } -// @codingStandardsIgnoreEnd diff --git a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearchTest.php b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearchTest.php index efb073d93ed07..5b7fd47042347 100644 --- a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearchTest.php +++ b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/ChildrenClassesSearchTest.php @@ -34,7 +34,7 @@ public function testChildrenSearch(): void __DIR__ . '/ChildrenClassesSearch/D.php', __DIR__ . '/ChildrenClassesSearch/E.php', __DIR__ . '/ChildrenClassesSearch/F.php', - __DIR__ . '/ChildrenClassesSearch/Z.php', + __DIR__ . '/ChildrenClassesSearch/ZInterface.php', ]; $found = $this->childrenClassesSearch->getClassesWhichAreChildrenOf( From 8e011b65f9b969a70bb2d75428f81117ebf36247 Mon Sep 17 00:00:00 2001 From: Oleh Usik Date: Mon, 10 Aug 2020 20:16:47 +0300 Subject: [PATCH 12/33] created new action group for click button --- ...stCheckoutUsingFreeShippingAndTaxesTest.xml | 3 +-- .../AdminClickButtonAddTaxRuleActionGroup.xml | 18 ++++++++++++++++++ .../Test/AdminCreateDefaultsTaxRuleTest.xml | 3 +-- .../Test/AdminCreateTaxRateLargeRateTest.xml | 2 +- .../AdminCreateTaxRateSpecificPostcodeTest.xml | 2 +- ...AdminCreateTaxRateWiderZipCodeRangeTest.xml | 2 +- .../AdminCreateTaxRateZipCodeRangeTest.xml | 2 +- ...xRuleWithCustomerAndProductTaxClassTest.xml | 3 +-- ...axRateAndCustomerAndProductTaxClassTest.xml | 3 +-- ...eTaxRuleWithNewTaxClassesAndTaxRateTest.xml | 3 +-- .../AdminCreateTaxRuleWithZipRangeTest.xml | 3 +-- .../Test/Mftf/Test/DeleteTaxRateEntityTest.xml | 3 +-- 12 files changed, 29 insertions(+), 18 deletions(-) create mode 100644 app/code/Magento/Tax/Test/Mftf/ActionGroup/AdminClickButtonAddTaxRuleActionGroup.xml diff --git a/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontGuestCheckoutUsingFreeShippingAndTaxesTest.xml b/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontGuestCheckoutUsingFreeShippingAndTaxesTest.xml index 1ce48bd8bf408..7ace592b7ae73 100644 --- a/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontGuestCheckoutUsingFreeShippingAndTaxesTest.xml +++ b/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontGuestCheckoutUsingFreeShippingAndTaxesTest.xml @@ -120,8 +120,7 @@ - - + diff --git a/app/code/Magento/Tax/Test/Mftf/ActionGroup/AdminClickButtonAddTaxRuleActionGroup.xml b/app/code/Magento/Tax/Test/Mftf/ActionGroup/AdminClickButtonAddTaxRuleActionGroup.xml new file mode 100644 index 0000000000000..313c4c5e84af0 --- /dev/null +++ b/app/code/Magento/Tax/Test/Mftf/ActionGroup/AdminClickButtonAddTaxRuleActionGroup.xml @@ -0,0 +1,18 @@ + + + + + + + Click button for creating new tax rule. + + + + + diff --git a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateDefaultsTaxRuleTest.xml b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateDefaultsTaxRuleTest.xml index 07968c281c68b..9629740f1cd20 100644 --- a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateDefaultsTaxRuleTest.xml +++ b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateDefaultsTaxRuleTest.xml @@ -30,8 +30,7 @@ - - + diff --git a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateLargeRateTest.xml b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateLargeRateTest.xml index c8e4defc40c9f..641278d02e726 100644 --- a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateLargeRateTest.xml +++ b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateLargeRateTest.xml @@ -59,7 +59,7 @@ - + diff --git a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateSpecificPostcodeTest.xml b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateSpecificPostcodeTest.xml index c6a5a6c69e788..f454ceced7a3d 100644 --- a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateSpecificPostcodeTest.xml +++ b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateSpecificPostcodeTest.xml @@ -58,7 +58,7 @@ - + diff --git a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateWiderZipCodeRangeTest.xml b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateWiderZipCodeRangeTest.xml index ef9b66041893d..9712a605a5bf4 100644 --- a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateWiderZipCodeRangeTest.xml +++ b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateWiderZipCodeRangeTest.xml @@ -60,7 +60,7 @@ - + diff --git a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateZipCodeRangeTest.xml b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateZipCodeRangeTest.xml index 23c4ffd78a88d..2734a57aa312c 100644 --- a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateZipCodeRangeTest.xml +++ b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRateZipCodeRangeTest.xml @@ -62,7 +62,7 @@ - + diff --git a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithCustomerAndProductTaxClassTest.xml b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithCustomerAndProductTaxClassTest.xml index ba0834da7c0e7..c309db52cb194 100644 --- a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithCustomerAndProductTaxClassTest.xml +++ b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithCustomerAndProductTaxClassTest.xml @@ -40,8 +40,7 @@ - - + diff --git a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithNewAndExistingTaxRateAndCustomerAndProductTaxClassTest.xml b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithNewAndExistingTaxRateAndCustomerAndProductTaxClassTest.xml index ae37bc8a8930a..2aaebb0ca5c3e 100644 --- a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithNewAndExistingTaxRateAndCustomerAndProductTaxClassTest.xml +++ b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithNewAndExistingTaxRateAndCustomerAndProductTaxClassTest.xml @@ -41,8 +41,7 @@ - - + diff --git a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithNewTaxClassesAndTaxRateTest.xml b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithNewTaxClassesAndTaxRateTest.xml index 2a008991c2dc8..d0e9242f3618b 100644 --- a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithNewTaxClassesAndTaxRateTest.xml +++ b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithNewTaxClassesAndTaxRateTest.xml @@ -41,8 +41,7 @@ - - + diff --git a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithZipRangeTest.xml b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithZipRangeTest.xml index de55453fcabc4..0c324f137b84f 100644 --- a/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithZipRangeTest.xml +++ b/app/code/Magento/Tax/Test/Mftf/Test/AdminCreateTaxRuleWithZipRangeTest.xml @@ -41,8 +41,7 @@ - - + diff --git a/app/code/Magento/Tax/Test/Mftf/Test/DeleteTaxRateEntityTest.xml b/app/code/Magento/Tax/Test/Mftf/Test/DeleteTaxRateEntityTest.xml index 881e09e5e35f4..99d9d12d7d182 100644 --- a/app/code/Magento/Tax/Test/Mftf/Test/DeleteTaxRateEntityTest.xml +++ b/app/code/Magento/Tax/Test/Mftf/Test/DeleteTaxRateEntityTest.xml @@ -44,8 +44,7 @@ - - + From 4d65656fafe9c132bc8cd441ac2d1f7571b5a0da Mon Sep 17 00:00:00 2001 From: Vasya Tsviklinskyi Date: Wed, 12 Aug 2020 14:07:58 +0300 Subject: [PATCH 13/33] MC-35699: [Magento Cloud] HTML minification strips triple slashes from html string in phtml --- .../Magento/Framework/View/Template/Html/Minifier.php | 3 ++- .../Framework/View/Test/Unit/Template/Html/MinifierTest.php | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/internal/Magento/Framework/View/Template/Html/Minifier.php b/lib/internal/Magento/Framework/View/Template/Html/Minifier.php index 0a8db80cae349..cdbce9d102a89 100644 --- a/lib/internal/Magento/Framework/View/Template/Html/Minifier.php +++ b/lib/internal/Magento/Framework/View/Template/Html/Minifier.php @@ -3,6 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); namespace Magento\Framework\View\Template\Html; @@ -140,7 +141,7 @@ function ($match) use (&$heredocs) { . '(?:<(?>textarea|pre|script)\b|\z))#', ' ', preg_replace( - '#(?)[^\n\r]*#', + '#(?)[^\n\r]*#', '', preg_replace( '#(?)#', diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Template/Html/MinifierTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Template/Html/MinifierTest.php index 6aafa5a46cf63..3b13a2f723617 100644 --- a/lib/internal/Magento/Framework/View/Test/Unit/Template/Html/MinifierTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/Template/Html/MinifierTest.php @@ -3,6 +3,8 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Framework\View\Test\Unit\Template\Html; use PHPUnit\Framework\TestCase; @@ -139,6 +141,7 @@ public function testMinify() some text someMethod(); ?>
+