public function MenuActiveTrailTest::provider in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/tests/Drupal/Tests/Core/Menu/MenuActiveTrailTest.php \Drupal\Tests\Core\Menu\MenuActiveTrailTest::provider()
Provides test data for all test methods.
Return value
array Returns a list of test data of which each is an array containing the following elements:
- request: A request object.
- links: An array of menu links keyed by ID.
- menu_name: The active menu name.
- expected_link: The expected active link for the given menu.
File
- core/
tests/ Drupal/ Tests/ Core/ Menu/ MenuActiveTrailTest.php, line 101 - Contains \Drupal\Tests\Core\Menu\MenuActiveTrailTest.
Class
- MenuActiveTrailTest
- Tests the active menu trail service.
Namespace
Drupal\Tests\Core\MenuCode
public function provider() {
$data = array();
$mock_route = new Route('');
$request = new Request();
$request->attributes
->set(RouteObjectInterface::ROUTE_NAME, 'baby_llama');
$request->attributes
->set(RouteObjectInterface::ROUTE_OBJECT, $mock_route);
$request->attributes
->set('_raw_variables', new ParameterBag(array()));
$link_1 = MenuLinkMock::create(array(
'id' => 'baby_llama_link_1',
'route_name' => 'baby_llama',
'title' => 'Baby llama',
'parent' => 'mama_llama_link',
));
$link_2 = MenuLinkMock::create(array(
'id' => 'baby_llama_link_2',
'route_name' => 'baby_llama',
'title' => 'Baby llama',
'parent' => 'papa_llama_link',
));
// @see \Drupal\Core\Menu\MenuLinkManagerInterface::getParentIds()
$link_1_parent_ids = array(
'baby_llama_link_1',
'mama_llama_link',
'',
);
$empty_active_trail = array(
'',
);
// No active link is returned when zero links match the current route.
$data[] = array(
$request,
array(),
$this
->randomMachineName(),
NULL,
$empty_active_trail,
);
// The first (and only) matching link is returned when one link matches the
// current route.
$data[] = array(
$request,
array(
'baby_llama_link_1' => $link_1,
),
$this
->randomMachineName(),
$link_1,
$link_1_parent_ids,
);
// The first of multiple matching links is returned when multiple links
// match the current route, where "first" is determined by sorting by key.
$data[] = array(
$request,
array(
'baby_llama_link_1' => $link_1,
'baby_llama_link_2' => $link_2,
),
$this
->randomMachineName(),
$link_1,
$link_1_parent_ids,
);
// No active link is returned in case of a 403.
$request = new Request();
$request->attributes
->set('_exception_statuscode', 403);
$data[] = array(
$request,
FALSE,
$this
->randomMachineName(),
NULL,
$empty_active_trail,
);
// No active link is returned when the route name is missing.
$request = new Request();
$data[] = array(
$request,
FALSE,
$this
->randomMachineName(),
NULL,
$empty_active_trail,
);
return $data;
}