Issue #2944215 by jeqq, alexpott: Aliases generated by PathItem::generateSampleValue() should start with a slash
parent
a819fdbb51
commit
b5a5c68129
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue