Issue #2944215 by jeqq, alexpott: Aliases generated by PathItem::generateSampleValue() should start with a slash

8.6.x
Alex Pott 2018-02-13 14:15:17 +00:00
parent a819fdbb51
commit b5a5c68129
2 changed files with 13 additions and 1 deletions

View File

@ -89,7 +89,7 @@ class PathItem extends FieldItemBase {
*/ */
public static function generateSampleValue(FieldDefinitionInterface $field_definition) { public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
$random = new Random(); $random = new Random();
$values['alias'] = str_replace(' ', '-', strtolower($random->sentences(3))); $values['alias'] = '/' . str_replace(' ', '-', strtolower($random->sentences(3)));
return $values; return $values;
} }

View File

@ -189,6 +189,18 @@ class PathItemTest extends KernelTestBase {
// Change the alias for the second node to a different one and try again. // Change the alias for the second node to a different one and try again.
$second_node->get('path')->alias = '/foobar'; $second_node->get('path')->alias = '/foobar';
$this->assertFalse($node->get('path')->equals($second_node->get('path'))); $this->assertFalse($node->get('path')->equals($second_node->get('path')));
// Test the generateSampleValue() method.
$node = Node::create([
'title' => $this->randomString(),
'type' => 'foo',
'path' => ['alias' => '/foo'],
]);
$node->save();
$path_field = $node->get('path');
$path_field->generateSampleItems();
$node->save();
$this->assertStringStartsWith('/', $node->get('path')->alias);
} }
} }