diff --git a/core/modules/text/src/Plugin/Field/FieldType/TextItemBase.php b/core/modules/text/src/Plugin/Field/FieldType/TextItemBase.php
index 83cea4f..c3987c3 100644
--- a/core/modules/text/src/Plugin/Field/FieldType/TextItemBase.php
+++ b/core/modules/text/src/Plugin/Field/FieldType/TextItemBase.php
@@ -79,13 +79,14 @@ public static function generateSampleValue(FieldDefinitionInterface $field_defin
     }
     else {
       // Textfield handling.
-      $value = substr($random->sentences(mt_rand(1, $settings['max_length'] / 3), FALSE), 0, $settings['max_length']);
+      $max = ceil($settings['max_length'] / 3);
+      $value = substr($random->sentences(mt_rand(1, $max), FALSE), 0, $settings['max_length']);
     }
 
     $values = array(
       'value' => $value,
       'summary' => $value,
-      'format' => filter_fallback_format(),
+      'format' => \Drupal::config('filter.settings')->get('fallback_format'),
     );
     return $values;
   }
diff --git a/core/modules/text/tests/src/Unit/TextItemTest.php b/core/modules/text/tests/src/Unit/TextItemTest.php
new file mode 100644
index 0000000..4c12f19
--- /dev/null
+++ b/core/modules/text/tests/src/Unit/TextItemTest.php
@@ -0,0 +1,60 @@
+<?php
+namespace Drupal\Tests\text\Unit;
+
+use Drupal\Component\Utility\Unicode;
+use Drupal\Core\DependencyInjection\ContainerBuilder;
+use Drupal\Core\Field\BaseFieldDefinition;
+use Drupal\Core\Field\FieldTypePluginManager;
+use Drupal\Tests\UnitTestCase;
+use Drupal\text\Plugin\Field\FieldType\TextItemBase;
+
+/**
+ * @coversDefaultClass \Drupal\text\Plugin\Field\FieldType\TextItemBase
+ * @group text
+ */
+class TextItemTest extends UnitTestCase {
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function setUp() {
+    // Set up a mock plugin manager.
+    $plugin_manager = new FieldTypePluginManager(
+      new \ArrayObject(),
+      $this->getMock('Drupal\Core\Cache\CacheBackendInterface'),
+      $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface'),
+      $this->getMock('Drupal\Core\TypedData\TypedDataManagerInterface')
+    );
+
+    // Set up a configfactory for the filter settings fallback format.
+    $configs = array(
+      'filter.settings' => array(
+        'fallback_format' => 'plain_text',
+      ),
+    );
+    $configFactoryStub = $this->getConfigFactoryStub($configs);
+
+    $container = new ContainerBuilder();
+    $container->set('plugin.manager.field.field_type', $plugin_manager);
+    $container->set('config.factory', $configFactoryStub);
+    \Drupal::setContainer($container);
+
+  }
+
+  /**
+   * Tests creation of sample values.
+   *
+   * @covers ::generateSampleValue
+   */
+  public function testTextFieldSampleValue() {
+
+    $field_definition = BaseFieldDefinition::create('text')
+      ->setSetting('max_length', 1);
+
+    $sample_value = TextItemBase::generateSampleValue($field_definition);
+
+    $this->assertEquals(1, Unicode::strlen($sample_value['value']), 'Sample value is correct');
+
+  }
+
+}
