Commit 759c27ce authored by alexpott's avatar alexpott

Issue #2827748 by faline, felribeiro, tstoeckler: UuidItem should implement generateSampleValue

parent 14afb776
......@@ -3,6 +3,7 @@
namespace Drupal\Core\Field\Plugin\Field\FieldType;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
/**
* Defines the 'uuid' entity field type.
......@@ -48,4 +49,12 @@ public static function schema(FieldStorageDefinitionInterface $field_definition)
return $schema;
}
/**
* {@inheritdoc}
*/
public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
$values['value'] = \Drupal::service('uuid')->generate();
return $values;
}
}
<?php
namespace Drupal\Tests\field\Kernel\String;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\Tests\field\Kernel\FieldKernelTestBase;
use Drupal\Component\Uuid\Uuid;
/**
* Tests the UUID field.
*
* @group field
*/
class UuidItemTest extends FieldKernelTestBase {
/**
* Tests 'uuid' random values.
*/
public function testSampleValue() {
$entity = EntityTest::create([]);
$entity->save();
$uuid_field = $entity->get('uuid');
// Test the generateSampleValue() method.
$uuid_field->generateSampleItems();
$this->assertTrue(Uuid::isValid($uuid_field->value));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment