Skip to content
Snippets Groups Projects
Commit cce3a41d authored by Matthew Hallsworth's avatar Matthew Hallsworth
Browse files

Add test to cover the fields filter option

parent cf36da37
No related tags found
No related merge requests found
{
"data": [
{
"type": "menu_link_content--menu_link_content",
"id": "jsonapi_menu_test.open",
"attributes": {
"title": "Home",
"url": "%base_pathmenu_name_test"
}
},
{
"type": "menu_link_content--menu_link_content",
"id": "menu_link_content:%uuid",
"attributes": {
"title": "%title",
"url": "%base_pathmenu_callback_title"
}
},
{
"type": "menu_link_content--menu_link_content",
"id": "jsonapi_menu_test.user.login",
"attributes": {
"title": "Login",
"url": "%base_pathuser\/login"
}
}
]
}
......@@ -126,6 +126,30 @@ class JsonapiMenuItemsTest extends BrowserTestBase {
self::assertCacheContext($headers, 'url.query_args:filter');
}
/**
* Tests the JSON:API Menu Items resource with the 'fields' filter.
*/
public function testParametersFields() {
$link_title = $this->randomMachineName();
$content_link = $this->createMenuLink($link_title, 'jsonapi_menu_test.open');
$url = Url::fromRoute('jsonapi_menu_items.menu', [
'menu' => 'jsonapi-menu-items-test',
'filter' => [
'fields' => "title,url",
],
]);
[$content] = $this->getJsonApiMenuItemsResponse($url);
$this->assertCount(3, $content['data']);
$expected_items = Json::decode(strtr(file_get_contents(dirname(__DIR__, 2) . '/fixtures/fields-expected-items.json'), [
'%uuid' => $content_link->uuid(),
'%title' => $link_title,
'%base_path' => Url::fromRoute('<front>')->toString(),
]));
$this->assertEquals($expected_items['data'], $content['data']);
}
/**
* Tests the JSON:API Menu Items resource with the 'parents' filter.
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment