diff --git a/core/lib/Drupal/Core/Ajax/OpenDialogCommand.php b/core/lib/Drupal/Core/Ajax/OpenDialogCommand.php
index 45115df..73d7c2f 100644
--- a/core/lib/Drupal/Core/Ajax/OpenDialogCommand.php
+++ b/core/lib/Drupal/Core/Ajax/OpenDialogCommand.php
@@ -124,7 +124,7 @@ public function setDialogTitle($title) {
    */
   public function render() {
     // Add the library for handling the dialog in the response.
-    drupal_add_library('system', 'drupal.dialog.ajax');
+    $this->drupalAddLibrary('system', 'drupal.dialog.ajax');
 
     // For consistency ensure the modal option is set to TRUE or FALSE.
     $this->dialogOptions['modal'] = isset($this->dialogOptions['modal']) && $this->dialogOptions['modal'];
@@ -136,4 +136,12 @@ public function render() {
       'dialogOptions' => $this->dialogOptions,
     );
   }
+
+  /**
+   * Wraps drupal_add_library.
+   */
+  protected function drupalAddLibrary($module, $name, $every_page = NULL) {
+    return drupal_add_library($module, $name, $every_page);
+  }
+
 }
diff --git a/core/modules/views/lib/Drupal/views/Controller/ViewAjaxController.php b/core/modules/views/lib/Drupal/views/Controller/ViewAjaxController.php
index 307d63f..55f07e6 100644
--- a/core/modules/views/lib/Drupal/views/Controller/ViewAjaxController.php
+++ b/core/modules/views/lib/Drupal/views/Controller/ViewAjaxController.php
@@ -131,7 +131,7 @@ public function ajaxView(Request $request) {
         $view->dom_id = $dom_id;
 
         $preview = $view->preview($display_id, $args);
-        $response->addCommand(new ReplaceCommand(".view-dom-id-$dom_id", drupal_render($preview)));
+        $response->addCommand(new ReplaceCommand(".view-dom-id-$dom_id", $this->drupalRender($preview)));
         return $response;
       }
       else {
@@ -143,4 +143,17 @@ public function ajaxView(Request $request) {
     }
   }
 
+  /**
+   * Wraps drupal_render.
+   *
+   * @param array $elements
+   *   The structured array describing the data to be rendered.
+   *
+   * @return string
+   *   The rendered HTML.
+   */
+  protected function drupalRender(array $elements) {
+    return drupal_render($elements);
+  }
+
 }
diff --git a/core/modules/views/tests/Drupal/views/Tests/Controller/ViewAjaxControllerTest.php b/core/modules/views/tests/Drupal/views/Tests/Controller/ViewAjaxControllerTest.php
index 4ec3af9..186390a 100644
--- a/core/modules/views/tests/Drupal/views/Tests/Controller/ViewAjaxControllerTest.php
+++ b/core/modules/views/tests/Drupal/views/Tests/Controller/ViewAjaxControllerTest.php
@@ -58,7 +58,7 @@ protected function setUp() {
       ->disableOriginalConstructor()
       ->getMock();
 
-    $this->viewAjaxController = new ViewAjaxController($this->viewStorage, $this->executableFactory);
+    $this->viewAjaxController = new TestViewAjaxController($this->viewStorage, $this->executableFactory);
   }
 
   /**
@@ -172,6 +172,15 @@ protected function setupValidMocks() {
 
 }
 
+class TestViewAjaxController extends ViewAjaxController {
+
+  // @todo Remove once drupal_render is converted to autoloadable code.
+  protected function drupalRender(array $elements) {
+    return isset($array['#markup']) ? $array['#markup'] : '';
+  }
+
+}
+
 }
 
 namespace {
@@ -182,11 +191,4 @@ function &drupal_static($key) {
     }
   }
 
-  // @todo Remove once drupal_render is converted to autoloadable code.
-  if (!function_exists('drupal_render')) {
-    function drupal_render($array) {
-      return isset($array['#markup']) ? $array['#markup'] : '';
-    }
-  }
-
 }
diff --git a/core/tests/Drupal/Tests/Core/Ajax/AjaxCommandsTest.php b/core/tests/Drupal/Tests/Core/Ajax/AjaxCommandsTest.php
index 188c042..d8b9989 100644
--- a/core/tests/Drupal/Tests/Core/Ajax/AjaxCommandsTest.php
+++ b/core/tests/Drupal/Tests/Core/Ajax/AjaxCommandsTest.php
@@ -1,11 +1,13 @@
 <?php
+use Drupal\Core\Ajax\OpenDialogCommand;
+use Drupal\Core\Ajax\OpenModalDialogCommand;
 
 /**
  * @file
  * Contains \Drupal\Tests\Core\Ajax\AjaxCommandsTest.
  */
 
-namespace Drupal\Tests\Core\Ajax {
+namespace Drupal\Tests\Core\Ajax;
 
 use Drupal\Tests\UnitTestCase;
 use Drupal\Core\Ajax\AddCssCommand;
@@ -308,7 +310,7 @@ public function testSettingsCommand() {
    * Tests that OpenDialogCommand objects can be constructed and rendered.
    */
   public function testOpenDialogCommand() {
-    $command = new OpenDialogCommand('#some-dialog', 'Title', '<p>Text!</p>', array(
+    $command = new TestOpenDialogCommand('#some-dialog', 'Title', '<p>Text!</p>', array(
       'url' => FALSE,
       'width' => 500,
     ));
@@ -332,7 +334,7 @@ public function testOpenDialogCommand() {
    * Tests that OpenModalDialogCommand objects can be constructed and rendered.
    */
   public function testOpenModalDialogCommand() {
-    $command = new OpenModalDialogCommand('Title', '<p>Text!</p>', array(
+    $command = new TestOpenModalDialogCommand('Title', '<p>Text!</p>', array(
       'url' => 'example',
       'width' => 500,
     ));
@@ -425,12 +427,16 @@ public function testRedirectCommand() {
 
 }
 
+class TestOpenModalDialogCommand extends OpenModalDialogCommand {
+
+  protected function drupalAddLibrary($module, $name, $every_page = NULL) {
+  }
+
 }
 
-namespace {
-  if (!function_exists('drupal_add_library')) {
-    function drupal_add_library() {
-      return TRUE;
-    }
+class TestOpenDialogCommand extends OpenDialogCommand {
+
+  protected function drupalAddLibrary($module, $name, $every_page = NULL) {
   }
+
 }
