From d528da6f9861f73ccaff8a9eff578a1fee3337c1 Mon Sep 17 00:00:00 2001 From: Elisea Cornejo Date: Mon, 13 Sep 2021 12:29:54 +0200 Subject: [PATCH 1/2] AC-666: Static check for CopyrightTest for another extensions files --- .../CopyrightAnotherExtensionsFilesSniff.php | 52 +++++++++++++++++++ .../Legacy/AbstractJsSniffUnitTestCase.php | 33 ++++++++++++ ...yrightAnotherExtensionsFilesUnitTest.1.xml | 10 ++++ ...pyrightAnotherExtensionsFilesUnitTest.2.js | 10 ++++ ...pyrightAnotherExtensionsFilesUnitTest.4.js | 10 ++++ ...opyrightAnotherExtensionsFilesUnitTest.php | 41 +++++++++++++++ ...opyrightAnotherExtensionsFilesUnitTest.xml | 10 ++++ 7 files changed, 166 insertions(+) create mode 100644 Magento2/Sniffs/Legacy/CopyrightAnotherExtensionsFilesSniff.php create mode 100644 Magento2/Tests/Legacy/AbstractJsSniffUnitTestCase.php create mode 100644 Magento2/Tests/Legacy/CopyrightAnotherExtensionsFilesUnitTest.1.xml create mode 100644 Magento2/Tests/Legacy/CopyrightAnotherExtensionsFilesUnitTest.2.js create mode 100644 Magento2/Tests/Legacy/CopyrightAnotherExtensionsFilesUnitTest.4.js create mode 100644 Magento2/Tests/Legacy/CopyrightAnotherExtensionsFilesUnitTest.php create mode 100644 Magento2/Tests/Legacy/CopyrightAnotherExtensionsFilesUnitTest.xml diff --git a/Magento2/Sniffs/Legacy/CopyrightAnotherExtensionsFilesSniff.php b/Magento2/Sniffs/Legacy/CopyrightAnotherExtensionsFilesSniff.php new file mode 100644 index 00000000..1455ee58 --- /dev/null +++ b/Magento2/Sniffs/Legacy/CopyrightAnotherExtensionsFilesSniff.php @@ -0,0 +1,52 @@ + 0) { + return; + } + + $fileText = $phpcsFile->getTokensAsString($stackPtr, count($phpcsFile->getTokens())); + $adobeCopyrightFound = preg_match(self::COPYRIGHT_ADOBE, $fileText); + + if (strpos($fileText, self::COPYRIGHT_MAGENTO_TEXT) !== false || $adobeCopyrightFound) { + return; + } + + $phpcsFile->addWarningOnLine( + 'Copyright is missing or has wrong format', + null, + self::WARNING_CODE + ); + } +} diff --git a/Magento2/Tests/Legacy/AbstractJsSniffUnitTestCase.php b/Magento2/Tests/Legacy/AbstractJsSniffUnitTestCase.php new file mode 100644 index 00000000..4b891a3c --- /dev/null +++ b/Magento2/Tests/Legacy/AbstractJsSniffUnitTestCase.php @@ -0,0 +1,33 @@ +extensions = array_merge( + $config->extensions, + [ + 'js' => 'PHP' + ] + ); + + $GLOBALS['PHP_CODESNIFFER_CONFIG'] = $config; + } +} diff --git a/Magento2/Tests/Legacy/CopyrightAnotherExtensionsFilesUnitTest.1.xml b/Magento2/Tests/Legacy/CopyrightAnotherExtensionsFilesUnitTest.1.xml new file mode 100644 index 00000000..5bbf8807 --- /dev/null +++ b/Magento2/Tests/Legacy/CopyrightAnotherExtensionsFilesUnitTest.1.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/Magento2/Tests/Legacy/CopyrightAnotherExtensionsFilesUnitTest.2.js b/Magento2/Tests/Legacy/CopyrightAnotherExtensionsFilesUnitTest.2.js new file mode 100644 index 00000000..511f7b94 --- /dev/null +++ b/Magento2/Tests/Legacy/CopyrightAnotherExtensionsFilesUnitTest.2.js @@ -0,0 +1,10 @@ +/** + * Copyright Adobe. + * See COPYING.txt for license details. + */ + +define([ + 'jquery' +], function (){ + +}); \ No newline at end of file diff --git a/Magento2/Tests/Legacy/CopyrightAnotherExtensionsFilesUnitTest.4.js b/Magento2/Tests/Legacy/CopyrightAnotherExtensionsFilesUnitTest.4.js new file mode 100644 index 00000000..2eb60f49 --- /dev/null +++ b/Magento2/Tests/Legacy/CopyrightAnotherExtensionsFilesUnitTest.4.js @@ -0,0 +1,10 @@ +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +define([ + 'jquery' +], function (){ + +}); \ No newline at end of file diff --git a/Magento2/Tests/Legacy/CopyrightAnotherExtensionsFilesUnitTest.php b/Magento2/Tests/Legacy/CopyrightAnotherExtensionsFilesUnitTest.php new file mode 100644 index 00000000..8796abb9 --- /dev/null +++ b/Magento2/Tests/Legacy/CopyrightAnotherExtensionsFilesUnitTest.php @@ -0,0 +1,41 @@ + 1, + ]; + } + if ($testFile === 'CopyrightAnotherExtensionsFilesUnitTest.2.js') { + return [ + null => 1, + ]; + } + if ($testFile === 'CopyrightAnotherExtensionsFilesUnitTest.3.xml') { + return []; + } + if ($testFile === 'CopyrightAnotherExtensionsFilesUnitTest.4.js') { + return []; + } + return []; + } +} diff --git a/Magento2/Tests/Legacy/CopyrightAnotherExtensionsFilesUnitTest.xml b/Magento2/Tests/Legacy/CopyrightAnotherExtensionsFilesUnitTest.xml new file mode 100644 index 00000000..d1dcf359 --- /dev/null +++ b/Magento2/Tests/Legacy/CopyrightAnotherExtensionsFilesUnitTest.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file From 6a735c15d4ace82b9ee224fd36174cd05d0da42e Mon Sep 17 00:00:00 2001 From: Elisea Cornejo Date: Mon, 13 Sep 2021 12:30:05 +0200 Subject: [PATCH 2/2] AC-666: Static check for CopyrightTest for another extensions files --- Magento2/ruleset.xml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Magento2/ruleset.xml b/Magento2/ruleset.xml index 1e247a2f..ac130d68 100644 --- a/Magento2/ruleset.xml +++ b/Magento2/ruleset.xml @@ -3,7 +3,7 @@ Magento Coding Standard - + @@ -629,6 +629,10 @@ */Test/* *Test.php + + 5 + warning + 0