From 0bed3aeeef1d875a7a63a2ec8e99d7f30fb0a06b Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Fri, 24 Sep 2021 18:28:15 +0100
Subject: [PATCH] Issue #3229734 by quietone, danflanagan8, Kristen Pol:
 Improve test and add comments to ContentEntityTest

---
 .../Plugin/migrate/source/ContentEntityTest.php   | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php b/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php
index 321293c26bfa..34a486053512 100644
--- a/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php
+++ b/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php
@@ -127,6 +127,7 @@ protected function setUp(): void {
       ['target_bundles' => [$this->vocabulary]],
       FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED
     );
+
     // Create a term reference field on user.
     $this->createEntityReferenceField(
       'user',
@@ -139,7 +140,8 @@ protected function setUp(): void {
       FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED
     );
 
-    // Create some data.
+    // Create a node, with data in a term reference field, and then add a French
+    // translation of the node.
     $this->user = User::create([
       'name' => 'user123',
       'uid' => 1,
@@ -147,11 +149,12 @@ protected function setUp(): void {
     ]);
     $this->user->save();
 
-    $this->anon = User::create([
+    // Add the anonymous user so we can test later that it is not provided in a
+    // source row.
+    User::create([
       'name' => 'anon',
       'uid' => 0,
-    ]);
-    $this->anon->save();
+    ])->save();
 
     $term = Term::create([
       'vid' => $this->vocabulary,
@@ -216,7 +219,9 @@ public function testUserSource(array $configuration) {
     $user_source = $migration->getSourcePlugin();
     $this->assertSame('users', $user_source->__toString());
     if (!$configuration['include_translations']) {
-      // Confirm that the query does not return a row for the anonymous user.
+      // Confirm that the anonymous user is in the source database but not
+      // included in the rows returned by the content_entity.
+      $this->assertNotNull(User::load(0));
       $this->assertEquals(1, $user_source->count());
     }
     $this->assertIds($user_source, $configuration);
-- 
GitLab