From 6bbb08f95eea9d7a682741abc129e4229284536f Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Tue, 7 Mar 2023 23:36:18 +0000 Subject: [PATCH] Issue #3210064 by mfb, TanujJain-TJ, maosmurf, smustgrave, xjm, samuel.mortenson: EntityChangedTrait return type mismatch --- .../Drupal/Core/Entity/EntityChangedTrait.php | 8 ++- .../Kernel/Migrate/d7/MigrateCommentTest.php | 8 +-- .../src/Kernel/Migrate/d7/MigrateFileTest.php | 2 +- .../Migrate/d7/MigratePrivateFileTest.php | 2 +- .../Migrate/d6/MigrateNodeCompleteTest.php | 60 +++++++++---------- .../src/Kernel/Migrate/d7/MigrateNodeTest.php | 4 +- .../Migrate/d7/MigrateTaxonomyTermTest.php | 4 +- 7 files changed, 45 insertions(+), 43 deletions(-) diff --git a/core/lib/Drupal/Core/Entity/EntityChangedTrait.php b/core/lib/Drupal/Core/Entity/EntityChangedTrait.php index f94441bab64f..44f46f0d521e 100644 --- a/core/lib/Drupal/Core/Entity/EntityChangedTrait.php +++ b/core/lib/Drupal/Core/Entity/EntityChangedTrait.php @@ -26,11 +26,13 @@ public function getChangedTimeAcrossTranslations() { /** * Gets the timestamp of the last entity change for the current translation. * - * @return int - * The timestamp of the last entity save operation. + * @return int|null + * The timestamp of the last entity save operation. Some entities allow a + * NULL value indicating the changed time is unknown. */ public function getChangedTime() { - return $this->get('changed')->value; + $value = $this->get('changed')->value; + return isset($value) ? (int) $value : NULL; } /** diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentTest.php index 295e3623daf2..5d26cf2547c9 100644 --- a/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentTest.php +++ b/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentTest.php @@ -69,7 +69,7 @@ public function testMigration() { $this->assertInstanceOf(Comment::class, $comment); $this->assertSame('Subject field in English', $comment->getSubject()); $this->assertSame('1421727536', $comment->getCreatedTime()); - $this->assertSame('1421727536', $comment->getChangedTime()); + $this->assertSame(1421727536, $comment->getChangedTime()); $this->assertTrue($comment->isPublished()); $this->assertSame('admin', $comment->getAuthorName()); $this->assertSame('admin@local.host', $comment->getAuthorEmail()); @@ -111,7 +111,7 @@ public function testMigration() { $this->assertInstanceOf(Comment::class, $comment); $this->assertSame('Comment without language', $comment->getSubject()); $this->assertSame('1426781880', $comment->getCreatedTime()); - $this->assertSame('1426781880', $comment->getChangedTime()); + $this->assertSame(1426781880, $comment->getChangedTime()); $this->assertTrue($comment->isPublished()); $this->assertSame('Bob', $comment->getAuthorName()); $this->assertSame('bob@local.host', $comment->getAuthorEmail()); @@ -147,7 +147,7 @@ public function testMigration() { $this->assertSame('en', $metadata_fr->getSource()); $this->assertSame('1', $metadata_fr->getAuthor()->uid->value); $this->assertSame('1531837764', $metadata_fr->getCreatedTime()); - $this->assertSame('1531837764', $metadata_fr->getChangedTime()); + $this->assertSame(1531837764, $metadata_fr->getChangedTime()); $this->assertFalse($metadata_fr->isOutdated()); // Test that the Icelandic translation metadata is correctly migrated. @@ -156,7 +156,7 @@ public function testMigration() { $this->assertSame('en', $metadata_is->getSource()); $this->assertSame('2', $metadata_is->getAuthor()->uid->value); $this->assertSame('1531838064', $metadata_is->getCreatedTime()); - $this->assertSame('1531838064', $metadata_is->getChangedTime()); + $this->assertSame(1531838064, $metadata_is->getChangedTime()); $this->assertTrue($metadata_is->isOutdated()); } diff --git a/core/modules/file/tests/src/Kernel/Migrate/d7/MigrateFileTest.php b/core/modules/file/tests/src/Kernel/Migrate/d7/MigrateFileTest.php index 90e021cf32a2..97b6002c75d2 100644 --- a/core/modules/file/tests/src/Kernel/Migrate/d7/MigrateFileTest.php +++ b/core/modules/file/tests/src/Kernel/Migrate/d7/MigrateFileTest.php @@ -43,7 +43,7 @@ protected function getFileMigrationInfo() { * Tests that all expected files are migrated. */ public function testFileMigration() { - $this->assertEntity(1, 'cube.jpeg', 'public://cube.jpeg', 'image/jpeg', 3620, 1421727515, '1421727515', '1'); + $this->assertEntity(1, 'cube.jpeg', 'public://cube.jpeg', 'image/jpeg', 3620, 1421727515, 1421727515, '1'); // Ensure temporary file was not migrated. $this->assertNull(File::load(4)); } diff --git a/core/modules/file/tests/src/Kernel/Migrate/d7/MigratePrivateFileTest.php b/core/modules/file/tests/src/Kernel/Migrate/d7/MigratePrivateFileTest.php index 6244efaa5a48..90c6b322ccd8 100644 --- a/core/modules/file/tests/src/Kernel/Migrate/d7/MigratePrivateFileTest.php +++ b/core/modules/file/tests/src/Kernel/Migrate/d7/MigratePrivateFileTest.php @@ -53,7 +53,7 @@ public function register(ContainerBuilder $container) { * Tests that all expected files are migrated. */ public function testFileMigration() { - $this->assertEntity(3, 'Babylon5.txt', 'private://Babylon5.txt', 'text/plain', 3, 1486104045, '1486104045', '1'); + $this->assertEntity(3, 'Babylon5.txt', 'private://Babylon5.txt', 'text/plain', 3, 1486104045, 1486104045, '1'); } } diff --git a/core/modules/node/tests/src/Kernel/Migrate/d6/MigrateNodeCompleteTest.php b/core/modules/node/tests/src/Kernel/Migrate/d6/MigrateNodeCompleteTest.php index 1630f2f2164b..dc2a349ba462 100644 --- a/core/modules/node/tests/src/Kernel/Migrate/d6/MigrateNodeCompleteTest.php +++ b/core/modules/node/tests/src/Kernel/Migrate/d6/MigrateNodeCompleteTest.php @@ -1052,210 +1052,210 @@ protected function expectedRevisionEntityData() { [ 'log' => NULL, 'created' => '1390095702', - 'changed' => '1390095702', + 'changed' => 1390095702, ], // Node 2, revision 3, und. 1 => [ 'log' => NULL, 'created' => '1420718386', - 'changed' => '1420718386', + 'changed' => 1420718386, ], // Node 3, revision 4, und. 2 => [ 'log' => NULL, 'created' => '1390095701', - 'changed' => '1390095701', + 'changed' => 1390095701, ], // Node 1, revision 5, und. 3 => [ 'log' => 'modified rev 2', 'created' => '1390095703', - 'changed' => '1390095703', + 'changed' => 1390095703, ], // Node 4, revision 6, und. 4 => [ 'log' => NULL, 'created' => '1390095701', - 'changed' => '1390095701', + 'changed' => 1390095701, ], // Node 5, revision 7, und. 5 => [ 'log' => NULL, 'created' => '1390095701', - 'changed' => '1390095701', + 'changed' => 1390095701, ], // Node 6, revision 8, und. 6 => [ 'log' => NULL, 'created' => '1390095701', - 'changed' => '1390095701', + 'changed' => 1390095701, ], // Node 7, revision 9, und. 7 => [ 'log' => NULL, 'created' => '1390095701', - 'changed' => '1390095701', + 'changed' => 1390095701, ], // Node 8, revision 10, und. 8 => [ 'log' => NULL, 'created' => '1390095701', - 'changed' => '1390095701', + 'changed' => 1390095701, ], // Node 9, revision 11, und. 9 => [ 'log' => NULL, 'created' => '1390095701', - 'changed' => '1390095701', + 'changed' => 1390095701, ], // Node 9, revision 12, und. 10 => [ 'log' => NULL, 'created' => '1444671588', - 'changed' => '1444671588', + 'changed' => 1444671588, ], // Node 10, revision 13, en. 11 => [ 'log' => NULL, 'created' => '1444238808', - 'changed' => '1444238808', + 'changed' => 1444238808, ], // Node 10, revision 14, en. 12 => [ 'log' => NULL, 'created' => '1444239050', - 'changed' => '1444238808', + 'changed' => 1444238808, ], // Node 10, revision 14, fr. 13 => [ 'log' => NULL, 'created' => '1444239050', - 'changed' => '1444239050', + 'changed' => 1444239050, ], // Node 12, revision 15, zu. 14 => [ 'log' => NULL, 'created' => '1444238808', - 'changed' => '1444238808', + 'changed' => 1444238808, ], // Node 12, revision 16, en. 15 => [ 'log' => NULL, 'created' => '1444239050', - 'changed' => '1444239050', + 'changed' => 1444239050, ], // Node 12, revision 16, zu. 16 => [ 'log' => NULL, 'created' => '1444239050', - 'changed' => '1444238808', + 'changed' => 1444238808, ], // Node 14, revision 17, und. 17 => [ 'log' => NULL, 'created' => '1493066668', - 'changed' => '1493066668', + 'changed' => 1493066668, ], // Node 15, revision 18, und. 18 => [ 'log' => NULL, 'created' => '1493066677', - 'changed' => '1493066677', + 'changed' => 1493066677, ], // Node 16, revision 19, und. 19 => [ 'log' => NULL, 'created' => '1493066684', - 'changed' => '1493066684', + 'changed' => 1493066684, ], // Node 17, revision 20, und. 20 => [ 'log' => NULL, 'created' => '1493066693', - 'changed' => '1493066693', + 'changed' => 1493066693, ], // Node 18, revision 21, und. 21 => [ 'log' => NULL, 'created' => '1494966544', - 'changed' => '1494966544', + 'changed' => 1494966544, ], // Node 19, revision 22, und. 22 => [ 'log' => NULL, 'created' => '1501955771', - 'changed' => '1501955771', + 'changed' => 1501955771, ], // Node 12, revision 23, en. 23 => [ 'log' => NULL, 'created' => '1520613305', - 'changed' => '1444239050', + 'changed' => 1444239050, ], // Node 12, revision 23, fr. 24 => [ 'log' => NULL, 'created' => '1520613305', - 'changed' => '1520613305', + 'changed' => 1520613305, ], // Node 12, revision 23, zu. 25 => [ 'log' => NULL, 'created' => '1520613305', - 'changed' => '1444238808', + 'changed' => 1444238808, ], // Node 1, revision 2001, und. 26 => [ 'log' => 'modified rev 3', 'created' => '1420861423', - 'changed' => '1420861423', + 'changed' => 1420861423, ], // Node 21, revision 2002, en. 27 => [ 'log' => NULL, 'created' => '1534014650', - 'changed' => '1534014650', + 'changed' => 1534014650, ], // Node 21, revision 2003, en. 28 => [ 'log' => NULL, 'created' => '1534014687', - 'changed' => '1534014650', + 'changed' => 1534014650, ], // Node 21, revision 2003, fr. 29 => [ 'log' => NULL, 'created' => '1534014687', - 'changed' => '1534014687', + 'changed' => 1534014687, ], ], ]; diff --git a/core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeTest.php b/core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeTest.php index f91b9f720796..3947f11ef82e 100644 --- a/core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeTest.php +++ b/core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeTest.php @@ -277,7 +277,7 @@ public function testNode() { $this->assertTrue($metadata_fr->isOutdated()); $this->assertSame('2', $node_fr->getOwnerId()); $this->assertSame('1529615802', $node_fr->getCreatedTime()); - $this->assertSame('1529615802', $node_fr->getChangedTime()); + $this->assertSame(1529615802, $node_fr->getChangedTime()); $this->assertTrue($node_fr->isPublished()); // Test that the Icelandic translation metadata is correctly migrated. @@ -286,7 +286,7 @@ public function testNode() { $this->assertFalse($metadata_is->isOutdated()); $this->assertSame('1', $node_is->getOwnerId()); $this->assertSame('1529615813', $node_is->getCreatedTime()); - $this->assertSame('1529615813', $node_is->getChangedTime()); + $this->assertSame(1529615813, $node_is->getChangedTime()); $this->assertFalse($node_is->isPublished()); } diff --git a/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php b/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php index 3a26b1bfca8b..d5d0b9c6b773 100644 --- a/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php +++ b/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php @@ -186,7 +186,7 @@ public function testTaxonomyTerms() { $this->assertSame('en', $metadata_fr->getSource()); $this->assertSame('2', $metadata_fr->getAuthor()->uid->value); $this->assertSame('1531922267', $metadata_fr->getCreatedTime()); - $this->assertSame('1531922268', $metadata_fr->getChangedTime()); + $this->assertSame(1531922268, $metadata_fr->getChangedTime()); $this->assertTrue($metadata_fr->isOutdated()); // Test that the Icelandic translation metadata is correctly migrated. @@ -195,7 +195,7 @@ public function testTaxonomyTerms() { $this->assertSame('en', $metadata_is->getSource()); $this->assertSame('1', $metadata_is->getAuthor()->uid->value); $this->assertSame('1531922278', $metadata_is->getCreatedTime()); - $this->assertSame('1531922279', $metadata_is->getChangedTime()); + $this->assertSame(1531922279, $metadata_is->getChangedTime()); $this->assertFalse($metadata_is->isOutdated()); // Test that untranslatable properties are the same as the source language. -- GitLab