1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Drupal\Tests\graphql_core\Kernel\Menu; |
4
|
|
|
|
5
|
|
|
use Drupal\Core\Menu\MenuTreeParameters; |
|
|
|
|
6
|
|
|
use Drupal\menu_link_content\Entity\MenuLinkContent; |
|
|
|
|
7
|
|
|
use Drupal\Tests\graphql_core\Kernel\GraphQLCoreTestBase; |
8
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
|
|
|
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Test access to menu items. |
12
|
|
|
* |
13
|
|
|
* @group graphql_core |
14
|
|
|
*/ |
15
|
|
|
class MenuTest extends GraphQLCoreTestBase { |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* {@inheritdoc} |
19
|
|
|
*/ |
20
|
|
|
public static $modules = [ |
21
|
|
|
'menu_link_content', |
22
|
|
|
'link', |
23
|
|
|
'graphql_test_menu', |
24
|
|
|
]; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* {@inheritdoc} |
28
|
|
|
*/ |
29
|
|
|
protected function setUp(): void { |
30
|
|
|
parent::setUp(); |
31
|
|
|
$this->installEntitySchema('menu_link_content'); |
32
|
|
|
$this->installConfig('menu_link_content'); |
33
|
|
|
$this->installConfig('graphql_test_menu'); |
34
|
|
|
|
35
|
|
|
$externalLink = MenuLinkContent::create([ |
36
|
|
|
'title' => 'Drupal', |
37
|
|
|
'link' => ['uri' => 'http://www.drupal.org'], |
38
|
|
|
'menu_name' => 'test', |
39
|
|
|
'external' => 1, |
40
|
|
|
'enabled' => 1, |
41
|
|
|
'weight' => 5, |
42
|
|
|
]); |
43
|
|
|
|
44
|
|
|
$externalLink->save(); |
45
|
|
|
|
46
|
|
|
/** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menuLinkManager */ |
47
|
|
|
$menuLinkManager = $this->container->get('plugin.manager.menu.link'); |
48
|
|
|
$menuLinkManager->rebuild(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Test if the test setup itself is successful. |
53
|
|
|
*/ |
54
|
|
|
public function testTestSetup() { |
55
|
|
|
/** @var \Drupal\Core\Menu\MenuTreeStorageInterface $menuStorage */ |
56
|
|
|
$menuStorage = $this->container->get('entity_type.manager')->getStorage('menu'); |
57
|
|
|
$menu = $menuStorage->load('test'); |
58
|
|
|
$this->assertIsObject($menu); |
59
|
|
|
|
60
|
|
|
/** @var \Drupal\Core\Menu\MenuLinkTreeInterface $menuTree */ |
61
|
|
|
$menuTree = $this->container->get('menu.link_tree'); |
62
|
|
|
$this->assertEquals(count($menuTree->load('test', new MenuTreeParameters())), 3); |
63
|
|
|
|
64
|
|
|
/** @var \Symfony\Component\HttpKernel\HttpKernelInterface $httpKernel */ |
65
|
|
|
$httpKernel = $this->container->get('http_kernel'); |
66
|
|
|
|
67
|
|
|
$this->assertEquals($httpKernel->handle(Request::create('/graphql/test/accessible'))->getStatusCode(), 200); |
68
|
|
|
$this->assertEquals($httpKernel->handle(Request::create('/graphql/test/inaccessible'))->getStatusCode(), 403); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Test menu tree data retrieval. |
73
|
|
|
*/ |
74
|
|
|
public function testMenuTree() { |
75
|
|
|
$metadata = $this->defaultCacheMetaData(); |
76
|
|
|
$metadata->addCacheTags(['config:system.menu.test']); |
77
|
|
|
|
78
|
|
|
$this->assertResults( |
79
|
|
|
$this->getQueryFromFile('menu.gql'), |
80
|
|
|
[], |
81
|
|
|
[ |
82
|
|
|
'info' => [ |
83
|
|
|
'name' => 'Test menu', |
84
|
|
|
'description' => 'Menu for testing GraphQL menu access.', |
85
|
|
|
], |
86
|
|
|
'menu' => [ |
87
|
|
|
'links' => [ |
88
|
|
|
0 => [ |
89
|
|
|
'label' => 'Accessible', |
90
|
|
|
'route' => [ |
91
|
|
|
'path' => '/graphql/test/accessible', |
92
|
|
|
'routed' => TRUE, |
93
|
|
|
], |
94
|
|
|
'attribute' => NULL, |
95
|
|
|
'links' => [ |
96
|
|
|
0 => [ |
97
|
|
|
'label' => 'Nested A', |
98
|
|
|
'attribute' => NULL, |
99
|
|
|
'route' => [ |
100
|
|
|
'path' => '/graphql/test/accessible', |
101
|
|
|
'routed' => TRUE, |
102
|
|
|
], |
103
|
|
|
], |
104
|
|
|
1 => [ |
105
|
|
|
'label' => 'Nested B', |
106
|
|
|
'route' => [ |
107
|
|
|
'path' => '/graphql/test/accessible', |
108
|
|
|
'routed' => TRUE, |
109
|
|
|
], |
110
|
|
|
'attribute' => NULL, |
111
|
|
|
], |
112
|
|
|
], |
113
|
|
|
], |
114
|
|
|
1 => [ |
115
|
|
|
'label' => 'Drupal', |
116
|
|
|
'route' => [ |
117
|
|
|
'path' => 'http://www.drupal.org', |
118
|
|
|
'routed' => FALSE, |
119
|
|
|
], |
120
|
|
|
'attribute' => NULL, |
121
|
|
|
'links' => [], |
122
|
|
|
], |
123
|
|
|
], |
124
|
|
|
], |
125
|
|
|
], |
126
|
|
|
$metadata |
127
|
|
|
); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
} |
131
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths