diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationFormTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationFormTest.php
index 8163628895344c1062490914cb9564b592333581..7672fbe5e9833f29c7762147a49d9d10947e97f7 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationFormTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationFormTest.php
@@ -67,7 +67,7 @@ function testEntityFormLanguage() {
     $edit["body[$langcode][0][value]"] = $this->randomName(16);
 
     $this->drupalGet('node/add/page');
-    $form_langcode = variable_get('entity_form_langcode', FALSE);
+    $form_langcode = state()->get('entity_test.form_langcode') ?: FALSE;
     $this->drupalPost(NULL, $edit, t('Save'));
 
     $node = $this->drupalGetNodeByTitle($edit["title"]);
@@ -75,14 +75,14 @@ function testEntityFormLanguage() {
 
     // Edit the node and test the form language.
     $this->drupalGet($this->langcodes[0] . '/node/' . $node->nid . '/edit');
-    $form_langcode = variable_get('entity_form_langcode', FALSE);
+    $form_langcode = state()->get('entity_test.form_langcode') ?: FALSE;
     $this->assertTrue($node->langcode == $form_langcode, 'Form language is the same as the entity language.');
 
     // Explicitly set form langcode.
     $langcode = $this->langcodes[0];
     $form_state['langcode'] = $langcode;
     entity_get_form($node, 'default', $form_state);
-    $form_langcode = variable_get('entity_form_langcode', FALSE);
+    $form_langcode = state()->get('entity_test.form_langcode') ?: FALSE;
     $this->assertTrue($langcode == $form_langcode, 'Form language is the same as the language parameter.');
 
     // Enable language selector.
@@ -117,7 +117,7 @@ function testEntityFormLanguage() {
     $node->body[$langcode2][0]['value'] = $this->randomName(16);
     $node->save();
     $this->drupalGet($langcode2 . '/node/' . $node->nid . '/edit');
-    $form_langcode = variable_get('entity_form_langcode', FALSE);
+    $form_langcode = state()->get('entity_test.form_langcode') ?: FALSE;
     $this->assertTrue($langcode2 == $form_langcode, "Node edit form language is $langcode2.");
   }
 }
diff --git a/core/modules/system/tests/modules/entity_test/entity_test.module b/core/modules/system/tests/modules/entity_test/entity_test.module
index e36e47b081225fbc0e7bcda7dc2ad4a8bb69e644..641083d5d046921def8044b9cbeb4ba734739047 100644
--- a/core/modules/system/tests/modules/entity_test/entity_test.module
+++ b/core/modules/system/tests/modules/entity_test/entity_test.module
@@ -147,7 +147,7 @@ function entity_test_menu() {
  */
 function entity_test_form_node_form_alter(&$form, &$form_state, $form_id) {
   $langcode = $form_state['controller']->getFormLangcode($form_state);
-  variable_set('entity_form_langcode', $langcode);
+  state()->set('entity_test.form_langcode', $langcode);
 }
 
 /**