diff --git a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
index f58e1de..579d678 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
@@ -939,4 +939,23 @@ abstract class TestBase {
     }
     return $all_permutations;
   }
+
+  /*
+   * Sets the current URL path of the page being viewed.
+   *
+   * Useful for tests that rely on functions that require current_path() to
+   * return a path other than 'batch' during a test run in a browser.
+   *
+   * @param string $path
+   *   The path to set.
+   */
+  protected function setPath($path) {
+    if (drupal_container()->has('request')) {
+      drupal_container()->get('request')->attributes->set('system_path', $path);
+    }
+    else {
+      _current_path($path);
+    }
+  }
+
 }
diff --git a/core/modules/system/lib/Drupal/system/Tests/Theme/FunctionsTest.php b/core/modules/system/lib/Drupal/system/Tests/Theme/FunctionsTest.php
index 4e94e37..5ae8dbb 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Theme/FunctionsTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Theme/FunctionsTest.php
@@ -98,8 +98,8 @@ class FunctionsTest extends WebTestBase {
     // Required to verify the "active" class in expected links below, and
     // because the current path is different when running tests manually via
     // simpletest.module ('batch') and via the testing framework ('').
-    _current_path(config('system.site')->get('page.front'));
-
+    $original_path = current_path();
+    $this->setPath(config('system.site')->get('page.front'));
     // Verify that a list of links is properly rendered.
     $variables = array();
     $variables['attributes'] = array('id' => 'somelinks');
@@ -141,6 +141,9 @@ class FunctionsTest extends WebTestBase {
     $expected_heading = '<h3 id="heading">Links heading</h3>';
     $expected = $expected_heading . $expected_links;
     $this->assertThemeOutput('links', $variables, $expected);
+
+    // Set path back to not annoy the batch runner.
+    $this->setPath($original_path);
   }
 
   /**
diff --git a/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeTest.php b/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeTest.php
index 29bfee1..127cba0 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeTest.php
@@ -86,10 +86,10 @@ class ThemeTest extends WebTestBase {
     // Set the current path to node because theme_get_suggestions() will query
     // it to see if we are on the front page.
     config('system.site')->set('page.front', 'node')->save();
-    _current_path('node');
+    $this->setPath('node');
     $suggestions = theme_get_suggestions(array('node'), 'page');
     // Set it back to not annoy the batch runner.
-    _current_path($original_path);
+    $this->setPath($original_path);
     $this->assertTrue(in_array('page__front', $suggestions), t('Front page template was suggested.'));
   }
 
