diff --git a/core/modules/migrate/src/Plugin/migrate/source/SqlBase.php b/core/modules/migrate/src/Plugin/migrate/source/SqlBase.php
index a008568..e77bb7b 100644
--- a/core/modules/migrate/src/Plugin/migrate/source/SqlBase.php
+++ b/core/modules/migrate/src/Plugin/migrate/source/SqlBase.php
@@ -207,6 +207,15 @@ public function getIterator() {
     return $this->iterator;
   }
 
+  /**
+   * Check if we can join against the map table.
+   *
+   * This function specifically catches issues when we're migrating with
+   * unique sets of credentials for the source and destination database.
+   *
+   * @return bool
+   *   TRUE if we can join against the map table otherwise FALSE.
+   */
   protected function mapJoinable() {
     if (!$this->getIds()) {
       return FALSE;
@@ -226,4 +235,5 @@ protected function mapJoinable() {
     }
     return TRUE;
   }
+
 }
diff --git a/core/modules/migrate/tests/src/Unit/SqlBaseTest.php b/core/modules/migrate/tests/src/Unit/SqlBaseTest.php
new file mode 100644
index 0000000..57f36fd
--- /dev/null
+++ b/core/modules/migrate/tests/src/Unit/SqlBaseTest.php
@@ -0,0 +1,170 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Tests\migrate\Unit\SqlBaseTest.
+ */
+
+namespace Drupal\Tests\migrate\Unit;
+
+/**
+ * Tests the SqlBase class.
+ *
+ * @group migrate
+ */
+class SqlBaseTest extends MigrateTestCase {
+
+  /**
+   * Test the mapJoinable() check.
+   */
+  public function testMapJoinable() {
+
+    // Source ids are empty so mapJoinable() is false.
+    $sql_base = $this->getSqlBase(FALSE, FALSE);
+    $this->assertEquals($sql_base->mapJoinable(), FALSE);
+
+    // Still false because getIdMap() is not a subclass of Sql.
+    $sql_base = $this->getSqlBase(FALSE, TRUE);
+    $this->assertEquals($sql_base->mapJoinable(), FALSE);
+
+    // Test mapJoinable() returns false when source and id connection options
+    // differ.
+    $sql_base = $this->getSqlBase(TRUE, TRUE, ['username' => 'different_from_map', 'password' => 'different_from_map'], ['username' => 'different_from_source', 'password' => 'different_from_source']);
+    $this->assertEquals($sql_base->mapJoinable(), FALSE);
+
+    // Returns true because source and id map connection options are the same.
+    $options = ['username' => 'same_value', 'password' => 'same_value'];
+    $sql_base = $this->getSqlBase(TRUE, TRUE, $options, $options);
+    $this->assertEquals($sql_base->mapJoinable(), TRUE);
+  }
+
+  /**
+   * @param bool $id_map_is_sql
+   *   TRUE if we want getIdMap() to return an instance of Sql.
+   * @param bool $with_id_map
+   *   TRUE if we want the id map to have a valid map of ids.
+   * @param array $source_options
+   *   An array of connection options for the source connection.
+   * @param array $idmap_options
+   *   An array of connection options for the id map connection.
+   *
+   * @return \Drupal\Tests\migrate\Unit\TestSqlBase
+   *   The sql base class for testing.
+   */
+  protected function getSqlBase($id_map_is_sql, $with_id_map, $source_options = [], $idmap_options= []) {
+    // Setup a connection object.
+    $source_connection = $this->getMockBuilder('Drupal\Core\Database\Connection')
+      ->disableOriginalConstructor()
+      ->getMock();
+    $source_connection->expects($id_map_is_sql && $with_id_map ? $this->once() : $this->never())
+      ->method('getConnectionOptions')
+      ->willReturn($source_options);
+
+    // Setup the id map connection.
+    $idmap_connection = $this->getMockBuilder('Drupal\Core\Database\Connection')
+      ->disableOriginalConstructor()
+      ->getMock();
+    $idmap_connection->expects($id_map_is_sql && $with_id_map ? $this->once() : $this->never())
+      ->method('getConnectionOptions')
+      ->willReturn($idmap_options);
+
+    // Setup the Sql object.
+    $sql = $this->getMockBuilder('Drupal\migrate\Plugin\migrate\id_map\Sql')
+      ->disableOriginalConstructor()
+      ->getMock();
+    $sql->expects($id_map_is_sql && $with_id_map ? $this->once() : $this->never())
+      ->method('getDatabase')
+      ->willReturn($idmap_connection);
+
+    // Setup a migration entity.
+    $migration = $this->getMock('Drupal\migrate\Entity\MigrationInterface');
+    $migration->expects($with_id_map ? $this->once() : $this->never())
+      ->method('getIdMap')
+      ->willReturn($id_map_is_sql ? $sql : NULL);
+
+    // Create our SqlBase test class.
+    $sql_base = new TestSqlBase();
+    $sql_base->setMigration($migration);
+    $sql_base->setDatabase($source_connection);
+
+    // Configure the idMap to make the check in mapJoinable() pass.
+    if ($with_id_map) {
+      $sql_base->setIds([
+        'uid' => ['type' => 'integer', 'alias' => 'u'],
+      ]);
+    }
+
+    return $sql_base;
+  }
+
+}
+
+class TestSqlBase extends \Drupal\migrate\Plugin\migrate\source\SqlBase {
+
+  protected $database;
+  protected $ids;
+
+  /**
+   * Override the constructor so we can create one easily.
+   */
+  public function __construct() {}
+
+  /**
+   * Allows us to set the database during tests.
+   *
+   * @param mixed $database
+   *   The database mock object.
+   */
+  public function setDatabase($database) {
+    $this->database = $database;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getDatabase() {
+    return $this->database;
+  }
+
+  /**
+   * Allows us to set the migration during the test.
+   *
+   * @param mixed $migration
+   *   The migration mock.
+   */
+  public function setMigration($migration) {
+    $this->migration = $migration;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function mapJoinable() {
+    return parent::mapJoinable();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getIds() {
+    return $this->ids;
+  }
+
+  /**
+   * Allows us to set the ids during a test.
+   */
+  public function setIds($ids) {
+    $this->ids = $ids;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function fields() {}
+
+  /**
+   * {@inheritdoc}
+   */
+  public function query() {}
+
+}
