', $body);
// Verify the password check box is not checked
- $expectedString = <<
-EXPECTED_HTML;
- $this->assertStringContainsString($expectedString, $body);
+ $checkboxXpath = '//input[@type="checkbox"][@name="change_password"][@id="change-password"][not (@checked)]' .
+ '[@data-role="change-password"][@value="1"][@title="Change Password"][@class="checkbox"]';
+
+ $this->assertEquals(1, Xpath::getElementsCountForXpath($checkboxXpath, $body));
}
/**
* @magentoDataFixture Magento/Customer/_files/customer.php
*/
- public function testChangePasswordEditAction()
+ public function testChangePasswordEditAction(): void
{
$this->login(1);
@@ -425,12 +424,11 @@ public function testChangePasswordEditAction()
$this->assertEquals(200, $this->getResponse()->getHttpResponseCode(), $body);
$this->assertStringContainsString('
', $body);
// Verify the password check box is checked
- $expectedString = <<
-EXPECTED_HTML;
- $this->assertStringContainsString($expectedString, $body);
+ $checkboxXpath = '//input[@type="checkbox"][@name="change_password"][@id="change-password"]' .
+ '[@data-role="change-password"][@value="1"][@title="Change Password"][@checked="checked"]' .
+ '[@class="checkbox"]';
+
+ $this->assertEquals(1, Xpath::getElementsCountForXpath($checkboxXpath, $body));
}
/**
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..4afeda3a035eb
--- /dev/null
+++ b/dev/tests/static/framework/Magento/TestFramework/Utility/AddedFiles.php
@@ -0,0 +1,35 @@
+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/Magento/TestFramework/Utility/FilesSearch.php b/dev/tests/static/framework/Magento/TestFramework/Utility/FilesSearch.php
new file mode 100644
index 0000000000000..0ec8124496d1d
--- /dev/null
+++ b/dev/tests/static/framework/Magento/TestFramework/Utility/FilesSearch.php
@@ -0,0 +1,48 @@
+childrenClassesSearch = new ChildrenClassesSearch();
+ }
+
+ public function testChildrenSearch(): void
+ {
+ $files = [
+ __DIR__ . '/ChildrenClassesSearch/A.php',
+ __DIR__ . '/ChildrenClassesSearch/B.php',
+ __DIR__ . '/ChildrenClassesSearch/C.php',
+ __DIR__ . '/ChildrenClassesSearch/D.php',
+ __DIR__ . '/ChildrenClassesSearch/E.php',
+ __DIR__ . '/ChildrenClassesSearch/F.php',
+ __DIR__ . '/ChildrenClassesSearch/ZInterface.php',
+ ];
+
+ $found = $this->childrenClassesSearch->getClassesWhichAreChildrenOf(
+ $files,
+ A::class,
+ false
+ );
+
+ $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..7b27dde3b0bf4
--- /dev/null
+++ b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/FilesSearchTest.php
@@ -0,0 +1,53 @@
+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/_files/changed_files_some_name_test.txt b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/_files/changed_files_some_name_test.txt
new file mode 100644
index 0000000000000..816f4b32c9361
--- /dev/null
+++ b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Utility/_files/changed_files_some_name_test.txt
@@ -0,0 +1,3 @@
+app/code/Magento/Cms/Block/Block.php
+app/code/Magento/Cms/Api/BlockRepositoryInterface.php
+app/code/Magento/Cms/Observer/NoCookiesObserver.php
diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/Magento/Framework/App/Action/AbstractActionTest.php b/dev/tests/static/testsuite/Magento/Test/Legacy/Magento/Framework/App/Action/AbstractActionTest.php
new file mode 100644
index 0000000000000..69050c3c51895
--- /dev/null
+++ b/dev/tests/static/testsuite/Magento/Test/Legacy/Magento/Framework/App/Action/AbstractActionTest.php
@@ -0,0 +1,85 @@
+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 = $this->childrenClassesSearch->getClassesWhichAreChildrenOf($files, AbstractAction::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 = AddedFiles::getAddedFilesList($this->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));
+ }
+
+ /**
+ * Returns base directory for generated lists.
+ *
+ * @return 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(
diff --git a/lib/internal/Magento/Framework/App/ResourceConnection.php b/lib/internal/Magento/Framework/App/ResourceConnection.php
index 00dc88dcd7b17..3ba50fb396a4c 100644
--- a/lib/internal/Magento/Framework/App/ResourceConnection.php
+++ b/lib/internal/Magento/Framework/App/ResourceConnection.php
@@ -178,7 +178,7 @@ public function getTableName($modelEntity, $connectionName = self::DEFAULT_CONNE
list($modelEntity, $tableSuffix) = $modelEntity;
}
- $tableName = $modelEntity;
+ $tableName = (string)$modelEntity;
$mappedTableName = $this->getMappedTableName($tableName);
if ($mappedTableName) {
diff --git a/lib/internal/Magento/Framework/Test/Unit/App/ResourceConnectionTest.php b/lib/internal/Magento/Framework/Test/Unit/App/ResourceConnectionTest.php
index 1b12d68e683a3..67d5e303c6896 100644
--- a/lib/internal/Magento/Framework/Test/Unit/App/ResourceConnectionTest.php
+++ b/lib/internal/Magento/Framework/Test/Unit/App/ResourceConnectionTest.php
@@ -84,7 +84,7 @@ public function testGetTablePrefixWithInjectedPrefix()
public function testGetTablePrefix()
{
- $this->deploymentConfigMock->expects(self::once())
+ $this->deploymentConfigMock->expects($this->once())
->method('get')
->with(ConfigOptionsListConstants::CONFIG_PATH_DB_PREFIX)
->willReturn('pref_');
@@ -93,10 +93,10 @@ public function testGetTablePrefix()
public function testGetConnectionByName()
{
- $this->deploymentConfigMock->expects(self::once())->method('get')
+ $this->deploymentConfigMock->expects($this->once())->method('get')
->with(ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTIONS . '/default')
->willReturn(['config']);
- $this->connectionFactoryMock->expects(self::once())->method('create')
+ $this->connectionFactoryMock->expects($this->once())->method('create')
->with(['config'])
->willReturn('connection');
@@ -112,15 +112,38 @@ public function testGetExistingConnectionByName()
'connections' => ['default_process_' . getmypid() => 'existing_connection']
]
);
- $this->deploymentConfigMock->expects(self::never())->method('get');
+ $this->deploymentConfigMock->expects($this->never())->method('get');
self::assertEquals('existing_connection', $unit->getConnectionByName('default'));
}
public function testCloseConnection()
{
- $this->configMock->expects(self::once())->method('getConnectionName')->with('default');
+ $this->configMock->expects($this->once())->method('getConnectionName')->with('default');
$this->unit->closeConnection('default');
}
+
+ public function testGetTableNameWithBoolParam()
+ {
+ $this->deploymentConfigMock->expects($this->at(0))
+ ->method('get')
+ ->with(ConfigOptionsListConstants::CONFIG_PATH_DB_PREFIX)
+ ->willReturn('pref_');
+ $this->deploymentConfigMock->expects($this->at(1))->method('get')
+ ->with('db/connection/default')
+ ->willReturn(['config']);
+ $this->configMock->expects($this->atLeastOnce())
+ ->method('getConnectionName')
+ ->with('default')
+ ->willReturn('default');
+
+ $connection = $this->getMockBuilder(\Magento\Framework\DB\Adapter\AdapterInterface::class)->getMock();
+ $connection->expects($this->once())->method('getTableName')->with('pref_1');
+ $this->connectionFactoryMock->expects($this->once())->method('create')
+ ->with(['config'])
+ ->willReturn($connection);
+
+ $this->unit->getTableName(true);
+ }
}
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()
someMethod(); ?>
+