3 namespace Drupal\Tests\Core\Menu;
5 use Drupal\Core\Cache\Cache;
6 use Drupal\Core\Menu\MenuLinkBase;
9 * Defines a mock implementation of a menu link used in tests only.
11 class MenuLinkMock extends MenuLinkBase {
13 protected static $defaults = [
14 'menu_name' => 'mock',
15 'route_name' => 'MUST BE PROVIDED',
16 'route_parameters' => [],
18 'title' => 'MUST BE PROVIDED',
19 'title_arguments' => [],
20 'title_context' => '',
22 'parent' => 'MUST BE PROVIDED',
27 'provider' => 'simpletest',
29 'cache_contexts' => [],
31 'cache_max_age' => Cache::PERMANENT,
33 'class' => 'Drupal\\Tests\\Core\Menu\\MenuLinkMock',
34 'form_class' => 'Drupal\\Core\\Menu\\Form\\MenuLinkDefaultForm',
35 'id' => 'MUST BE PROVIDED',
39 * Create an instance from a definition with at least id, title, route_name.
41 public static function create($definition) {
42 return new static([], $definition['id'], $definition + static::$defaults);
48 public function getTitle() {
49 return $this->pluginDefinition['title'];
55 public function getDescription() {
56 if ($this->pluginDefinition['description']) {
57 return $this->pluginDefinition['description'];
65 public function updateLink(array $new_definition_values, $persist) {
67 return $this->pluginDefinition;
73 public function getCacheContexts() {
74 return $this->pluginDefinition['metadata']['cache_contexts'];
80 public function getCacheTags() {
81 return $this->pluginDefinition['metadata']['cache_tags'];
87 public function getCacheMaxAge() {
88 return $this->pluginDefinition['metadata']['cache_max_age'];