function MenuLinksTest::testCreateLink
Same name in other branches
- 9 core/modules/menu_link_content/tests/src/Kernel/MenuLinksTest.php \Drupal\Tests\menu_link_content\Kernel\MenuLinksTest::testCreateLink()
- 8.9.x core/modules/menu_link_content/tests/src/Kernel/MenuLinksTest.php \Drupal\Tests\menu_link_content\Kernel\MenuLinksTest::testCreateLink()
- 10 core/modules/menu_link_content/tests/src/Kernel/MenuLinksTest.php \Drupal\Tests\menu_link_content\Kernel\MenuLinksTest::testCreateLink()
Assert that a link entity's created timestamp is set.
File
-
core/
modules/ menu_link_content/ tests/ src/ Kernel/ MenuLinksTest.php, line 141
Class
- MenuLinksTest
- Tests handling of menu links hierarchies.
Namespace
Drupal\Tests\menu_link_content\KernelCode
public function testCreateLink() : void {
$options = [
'menu_name' => 'menu-test',
'bundle' => 'menu_link_content',
'link' => [
[
'uri' => 'internal:/',
],
],
'title' => 'Link test',
];
$link = MenuLinkContent::create($options);
$link->save();
// Make sure the changed timestamp is set.
$this->assertGreaterThanOrEqual(\Drupal::time()->getRequestTime(), $link->getChangedTime(), 'Creating a menu link sets the "changed" timestamp.');
$options = [
'title' => 'Test Link',
];
$link->link->options = $options;
$link->changed->value = 0;
$link->save();
// Make sure the changed timestamp is updated.
$this->assertGreaterThanOrEqual(\Drupal::time()->getRequestTime(), $link->getChangedTime(), 'Changing a menu link sets "changed" timestamp.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.