5c3905c6b31f23db596e6002d2a8c87e3c4a71a5
[yaffs-website] / MenuLinkMock.php
1 <?php
2
3 namespace Drupal\Tests\Core\Menu;
4
5 use Drupal\Core\Cache\Cache;
6 use Drupal\Core\Menu\MenuLinkBase;
7
8 /**
9  * Defines a mock implementation of a menu link used in tests only.
10  */
11 class MenuLinkMock extends MenuLinkBase {
12
13   protected static $defaults = [
14     'menu_name' => 'mock',
15     'route_name' => 'MUST BE PROVIDED',
16     'route_parameters' => [],
17     'url' => '',
18     'title' => 'MUST BE PROVIDED',
19     'title_arguments' => [],
20     'title_context' => '',
21     'description' => '',
22     'parent' => 'MUST BE PROVIDED',
23     'weight' => '0',
24     'options' => [],
25     'expanded' => '0',
26     'enabled' => '1',
27     'provider' => 'simpletest',
28     'metadata' => [
29       'cache_contexts' => [],
30       'cache_tags' => [],
31       'cache_max_age' => Cache::PERMANENT,
32     ],
33     'class' => 'Drupal\\Tests\\Core\Menu\\MenuLinkMock',
34     'form_class' => 'Drupal\\Core\\Menu\\Form\\MenuLinkDefaultForm',
35     'id' => 'MUST BE PROVIDED',
36   ];
37
38   /**
39    * Create an instance from a definition with at least id, title, route_name.
40    */
41   public static function create($definition) {
42     return new static([], $definition['id'], $definition + static::$defaults);
43   }
44
45   /**
46    * {@inheritdoc}
47    */
48   public function getTitle() {
49     return $this->pluginDefinition['title'];
50   }
51
52   /**
53    * {@inheritdoc}
54    */
55   public function getDescription() {
56     if ($this->pluginDefinition['description']) {
57       return $this->pluginDefinition['description'];
58     }
59     return '';
60   }
61
62   /**
63    * {@inheritdoc}
64    */
65   public function updateLink(array $new_definition_values, $persist) {
66     // No-op.
67     return $this->pluginDefinition;
68   }
69
70   /**
71    * {@inheritdoc}
72    */
73   public function getCacheContexts() {
74     return $this->pluginDefinition['metadata']['cache_contexts'];
75   }
76
77   /**
78    * {@inheritdoc}
79    */
80   public function getCacheTags() {
81     return $this->pluginDefinition['metadata']['cache_tags'];
82   }
83
84   /**
85    * {@inheritdoc}
86    */
87   public function getCacheMaxAge() {
88     return $this->pluginDefinition['metadata']['cache_max_age'];
89   }
90
91 }