From d955f8d6ceea551c655cd8ef26a243728bafe2b8 Mon Sep 17 00:00:00 2001 From: Luke Rodgers Date: Thu, 8 Feb 2024 20:33:22 +0000 Subject: [PATCH 1/2] Do not strip knockout comments from `.html` files This would have been introduced as part of https://github.com/AmpersandHQ/ampersand-magento2-upgrade-patch-helper/compare/v1.18.1...v1.19.0 ChatGPT may have assisted with the regex --- .../Checks/WebTemplateHtmlTest.php | 47 +++++++++++++++++++ .../web/templates/grid/knockout.html | 1 + .../checks/WebTemplateHtml/vendor.patch | 10 ++++ .../base/web/templates/grid/knockout.html | 5 ++ .../base/web/templates/grid/knockout.html | 5 ++ .../PatchHelper/Patchfile/Sanitiser.php | 2 +- 6 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 dev/phpunit/unit/resources/checks/WebTemplateHtml/app/design/frontend/Ampersand/theme/Magento_Ui/web/templates/grid/knockout.html create mode 100644 dev/phpunit/unit/resources/checks/WebTemplateHtml/vendor/magento/module-ui/view/base/web/templates/grid/knockout.html create mode 100644 dev/phpunit/unit/resources/checks/WebTemplateHtml/vendor_orig/magento/module-ui/view/base/web/templates/grid/knockout.html diff --git a/dev/phpunit/unit/Ampersand/PatchHelper/Checks/WebTemplateHtmlTest.php b/dev/phpunit/unit/Ampersand/PatchHelper/Checks/WebTemplateHtmlTest.php index 452e35b7..e36d975a 100644 --- a/dev/phpunit/unit/Ampersand/PatchHelper/Checks/WebTemplateHtmlTest.php +++ b/dev/phpunit/unit/Ampersand/PatchHelper/Checks/WebTemplateHtmlTest.php @@ -188,4 +188,51 @@ public function testWebTemplateHtmlVendorFileNonMeaningfulChange() ]; $this->assertEquals($expected, $ignored); } + + /** + * + */ + public function testWebTemplateHtmlKnockout() + { + $this->m2->expects($this->any()) + ->method('getListOfHtmlFiles') + ->willReturn( + [ + 'app/design/frontend/Ampersand/theme/Magento_Ui/web/templates/grid/knockout.html', + 'vendor/magento/module-ui/view/base/web/templates/grid/knockout.html', + ] + ); + + $reader = new Reader( + $this->testResourcesDir . 'vendor.patch' + ); + + $entries = $reader->getFiles(); + $this->assertNotEmpty($entries, 'We should have a patch file to read'); + + $entry = $entries[3]; + + $appCodeGetter = new GetAppCodePathFromVendorPath($this->m2, $entry); + $appCodeFilePath = $appCodeGetter->getAppCodePathFromVendorPath(); + $this->assertEquals( + 'app/code/Magento/Ui/view/base/web/templates/grid/knockout.html', + $appCodeFilePath + ); + + $warnings = $infos = $ignored = []; + + $check = new WebTemplateHtml($this->m2, $entry, $appCodeFilePath, $warnings, $infos, $ignored); + $this->assertTrue($check->canCheck(), 'Check should be checkable'); + $check->check(); + + $this->assertEmpty($ignored, 'We should have no ignore level items'); + $this->assertEmpty($infos, 'We should have no info level items'); + $this->assertNotEmpty($warnings, 'We should have a warning'); + $expectedWarnings = [ + 'Override (phtml/js/html)' => [ + 'app/design/frontend/Ampersand/theme/Magento_Ui/web/templates/grid/knockout.html' + ] + ]; + $this->assertEquals($expectedWarnings, $warnings); + } } diff --git a/dev/phpunit/unit/resources/checks/WebTemplateHtml/app/design/frontend/Ampersand/theme/Magento_Ui/web/templates/grid/knockout.html b/dev/phpunit/unit/resources/checks/WebTemplateHtml/app/design/frontend/Ampersand/theme/Magento_Ui/web/templates/grid/knockout.html new file mode 100644 index 00000000..62bc0511 --- /dev/null +++ b/dev/phpunit/unit/resources/checks/WebTemplateHtml/app/design/frontend/Ampersand/theme/Magento_Ui/web/templates/grid/knockout.html @@ -0,0 +1 @@ +

some override

\ No newline at end of file diff --git a/dev/phpunit/unit/resources/checks/WebTemplateHtml/vendor.patch b/dev/phpunit/unit/resources/checks/WebTemplateHtml/vendor.patch index 9ee5fdaf..e35e6dcb 100644 --- a/dev/phpunit/unit/resources/checks/WebTemplateHtml/vendor.patch +++ b/dev/phpunit/unit/resources/checks/WebTemplateHtml/vendor.patch @@ -70,3 +70,13 @@ diff -ur -N vendor_orig/magento/module-ui/view/base/web/templates/grid/some_noop - \ No newline at end of file + +diff -ur -N vendor_orig/magento/module-ui/view/base/web/templates/grid/knockout.html vendor/magento/module-ui/view/base/web/templates/grid/knockout.html +--- vendor_orig/magento/module-ui/view/base/web/templates/grid/knockout.html 2024-02-08 20:13:23.000000000 +0000 ++++ vendor/magento/module-ui/view/base/web/templates/grid/knockout.html 2024-02-08 20:13:23.000000000 +0000 +@@ -1,5 +1,5 @@ +

hello

+

goodbye

+- ++ + + diff --git a/dev/phpunit/unit/resources/checks/WebTemplateHtml/vendor/magento/module-ui/view/base/web/templates/grid/knockout.html b/dev/phpunit/unit/resources/checks/WebTemplateHtml/vendor/magento/module-ui/view/base/web/templates/grid/knockout.html new file mode 100644 index 00000000..6761478d --- /dev/null +++ b/dev/phpunit/unit/resources/checks/WebTemplateHtml/vendor/magento/module-ui/view/base/web/templates/grid/knockout.html @@ -0,0 +1,5 @@ +

hello

+

goodbye

+ + + diff --git a/dev/phpunit/unit/resources/checks/WebTemplateHtml/vendor_orig/magento/module-ui/view/base/web/templates/grid/knockout.html b/dev/phpunit/unit/resources/checks/WebTemplateHtml/vendor_orig/magento/module-ui/view/base/web/templates/grid/knockout.html new file mode 100644 index 00000000..1884e00f --- /dev/null +++ b/dev/phpunit/unit/resources/checks/WebTemplateHtml/vendor_orig/magento/module-ui/view/base/web/templates/grid/knockout.html @@ -0,0 +1,5 @@ +

hello

+

goodbye

+ + + diff --git a/src/Ampersand/PatchHelper/Patchfile/Sanitiser.php b/src/Ampersand/PatchHelper/Patchfile/Sanitiser.php index cc607a77..a6ae9ee5 100644 --- a/src/Ampersand/PatchHelper/Patchfile/Sanitiser.php +++ b/src/Ampersand/PatchHelper/Patchfile/Sanitiser.php @@ -178,6 +178,6 @@ public static function stripCommentsFromHtml($contents) { // This regular expression will match and remove both single-line comments and multi-line comments // spanning multiple lines. The s flag is used to make the dot (.) match any character, including newlines. - return preg_replace('//s', '', $contents); + return preg_replace('//s', '', $contents); } } From db9743a16fd2568e11af7a1f703c18d2443352b6 Mon Sep 17 00:00:00 2001 From: Luke Rodgers Date: Fri, 9 Feb 2024 09:07:30 +0000 Subject: [PATCH 2/2] Update Sanitiser.php --- src/Ampersand/PatchHelper/Patchfile/Sanitiser.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Ampersand/PatchHelper/Patchfile/Sanitiser.php b/src/Ampersand/PatchHelper/Patchfile/Sanitiser.php index a6ae9ee5..eb01d72a 100644 --- a/src/Ampersand/PatchHelper/Patchfile/Sanitiser.php +++ b/src/Ampersand/PatchHelper/Patchfile/Sanitiser.php @@ -178,6 +178,7 @@ public static function stripCommentsFromHtml($contents) { // This regular expression will match and remove both single-line comments and multi-line comments // spanning multiple lines. The s flag is used to make the dot (.) match any character, including newlines. + // This does not include knockout templates, as logic is embedded in comments return preg_replace('//s', '', $contents); } }