Commit 39457444 authored by alexpott's avatar alexpott

Issue #2400543 by Nitesh Pawar, abhishek.kumar, hugronaphor, jibran, dawehner,...

Issue #2400543 by Nitesh Pawar, abhishek.kumar, hugronaphor, jibran, dawehner, PieterJanPut, wuinfo, cilefen, alexpott, ameymudras, lauriii, pec, ashutoshsngh, Truptti, JmOkay: Breadcrumb should be term name instead of term id on term edit and delete page
parent 0eceb0ce
......@@ -551,4 +551,38 @@ function testReSavingTags() {
$this->assertRaw($term->getName(), 'Term is displayed after saving the node with no changes.');
}
/**
* Check the breadcrumb on edit and delete a term page.
*/
public function testTermBreadcrumbs() {
$edit = [
'name[0][value]' => $this->randomMachineName(14),
'description[0][value]' => $this->randomMachineName(100),
'parent[]' => [0],
];
// Create the term.
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add', $edit, t('Save'));
$terms = taxonomy_term_load_multiple_by_name($edit['name[0][value]']);
$term = reset($terms);
$this->assertNotNull($term, 'Term found in database.');
// Check the breadcrumb on the term edit page.
$this->drupalGet('taxonomy/term/' . $term->id() . '/edit');
$breadcrumbs = $this->cssSelect('nav.breadcrumb ol li a');
$this->assertIdentical(count($breadcrumbs), 2, 'The breadcrumbs are present on the page.');
$this->assertIdentical((string) $breadcrumbs[0], 'Home', 'First breadcrumb text is Home');
$this->assertIdentical((string) $breadcrumbs[1], $term->label(), 'Second breadcrumb text is term name on term edit page.');
$this->assertEscaped((string) $breadcrumbs[1], 'breadcrumbs displayed and escaped.');
// Check the breadcrumb on the term delete page.
$this->drupalGet('taxonomy/term/' . $term->id() . '/delete');
$breadcrumbs = $this->cssSelect('nav.breadcrumb ol li a');
$this->assertIdentical(count($breadcrumbs), 2, 'The breadcrumbs are present on the page.');
$this->assertIdentical((string) $breadcrumbs[0], 'Home', 'First breadcrumb text is Home');
$this->assertIdentical((string) $breadcrumbs[1], $term->label(), 'Second breadcrumb text is term name on term delete page.');
$this->assertEscaped((string) $breadcrumbs[1], 'breadcrumbs displayed and escaped.');
}
}
......@@ -270,6 +270,10 @@ public function alterRoutes(RouteCollection $collection) {
// that parameter conversion options is carried over.
$route->setOptions($route->getOptions() + $original_route->getOptions());
if ($original_route->hasDefault('_title_callback')) {
$route->setDefault('_title_callback', $original_route->getDefault('_title_callback'));
}
// Set the corrected path and the mapping to the route object.
$route->setOption('_view_argument_map', $argument_map);
$route->setPath($path);
......
......@@ -260,6 +260,44 @@ public function testAlterRoute() {
$this->assertSame($collection->get('test_route_2'), $route_2);
}
/**
* Tests the alter route method with preexisting title callback.
*/
public function testAlterRouteWithAlterCallback() {
$collection = new RouteCollection();
$collection->add('test_route', new Route('test_route', array('_controller' => 'Drupal\Tests\Core\Controller\TestController::content', '_title_callback' => '\Drupal\Tests\views\Unit\Plugin\display\TestController::testTitle')));
$route_2 = new Route('test_route/example', array('_controller' => 'Drupal\Tests\Core\Controller\TestController::content'));
$collection->add('test_route_2', $route_2);
list($view) = $this->setupViewExecutableAccessPlugin();
$display = array();
$display['display_plugin'] = 'page';
$display['id'] = 'page_1';
$display['display_options'] = array(
'path' => 'test_route',
);
$this->pathPlugin->initDisplay($view, $display);
$view_route_names = $this->pathPlugin->alterRoutes($collection);
$this->assertEquals(array('test_id.page_1' => 'test_route'), $view_route_names);
// Ensure that the test_route is overridden.
$route = $collection->get('test_route');
$this->assertTrue($route instanceof Route);
$this->assertEquals('test_id', $route->getDefault('view_id'));
$this->assertEquals('\Drupal\Tests\views\Unit\Plugin\display\TestController::testTitle', $route->getDefault('_title_callback'));
$this->assertEquals('page_1', $route->getDefault('display_id'));
$this->assertEquals('my views title', $route->getDefault('_title'));
// Ensure that the test_route_2 is not overridden.
$route = $collection->get('test_route_2');
$this->assertTrue($route instanceof Route);
$this->assertFalse($route->hasDefault('view_id'));
$this->assertFalse($route->hasDefault('display_id'));
$this->assertSame($collection->get('test_route_2'), $route_2);
}
/**
* Tests the collectRoutes method with a path containing named parameters.
*
......@@ -457,3 +495,20 @@ protected function setupViewExecutableAccessPlugin() {
}
}
/**
* A page controller for use by tests in this file.
*/
class TestController {
/**
* A page title callback.
*
* @return string
* The page title.
*/
public function testTitle() {
return 'Test title';
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment