Commit e6fdb5fc authored by willzyx's avatar willzyx

Issue #2809073 by chipway, willzyx, Eric Heydrich, michaellenahan:...

Issue #2809073 by chipway, willzyx, Eric Heydrich, michaellenahan: DevelRebuildMenus class name is misleading and not describe what the class really does
parent 22a8f0e1
......@@ -19,8 +19,8 @@ devel.reinstall:
devel.menu_rebuild:
path: '/devel/menu/reset'
defaults:
_form: '\Drupal\devel\Form\DevelRebuildMenus'
_title: 'Rebuild menus'
_form: '\Drupal\devel\Form\RouterRebuildConfirmForm'
_title: 'Rebuild router'
options:
_admin_route: TRUE
requirements:
......
......@@ -11,7 +11,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides confirmation form for rebuilding the routes.
*/
class DevelRebuildMenus extends ConfirmFormBase {
class RouterRebuildConfirmForm extends ConfirmFormBase {
/**
* The route builder service.
......@@ -21,7 +21,7 @@ class DevelRebuildMenus extends ConfirmFormBase {
protected $routeBuilder;
/**
* Constructs a new DevelRebuildMenus object.
* Constructs a new RouterRebuildConfirmForm object.
*
* @param \Drupal\Core\Routing\RouteBuilderInterface $route_builder
* The route builder service.
......@@ -50,7 +50,7 @@ class DevelRebuildMenus extends ConfirmFormBase {
* {@inheritdoc}
*/
public function getQuestion() {
return $this->t('Are you sure you want to rebuild menus?');
return $this->t('Are you sure you want to rebuild the router?');
}
/**
......@@ -64,7 +64,7 @@ class DevelRebuildMenus extends ConfirmFormBase {
* {@inheritdoc}
*/
public function getDescription() {
return $this->t('Rebuild menu based on hook_menu() and revert any custom changes. All menu items return to their default settings.');
return $this->t('Rebuilds the routes information gathering all routing data from .routing.yml files and from classes which subscribe to the route build events. This action cannot be undone.');
}
/**
......@@ -79,7 +79,7 @@ class DevelRebuildMenus extends ConfirmFormBase {
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->routeBuilder->rebuild();
drupal_set_message($this->t('The menu router has been rebuilt.'));
drupal_set_message($this->t('The router has been rebuilt.'));
$form_state->setRedirect('<front>');
}
......
<?php
namespace Drupal\devel\Tests;
use Drupal\simpletest\WebTestBase;
/**
* Tests routes rebuild.
*
* @group devel
*/
class DevelRebuildMenusTest extends WebTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('devel');
/**
* Set up test.
*/
protected function setUp() {
parent::setUp();
$web_user = $this->drupalCreateUser(array('administer site configuration'));
$this->drupalLogin($web_user);
}
/**
* Test routes rebuild.
*/
public function testDevelRebuildMenus() {
$this->drupalGet('devel/menu/reset');
$this->assertResponse(200);
$this->drupalPostForm('devel/menu/reset', array(), t('Rebuild'));
$this->assertText(t('The menu router has been rebuilt.'));
}
}
services:
devel_test.test_route_subscriber:
class: Drupal\devel_test\Routing\TestRouteSubscriber
tags:
- { name: event_subscriber }
<?php
namespace Drupal\devel_test\Routing;
use Drupal\Core\Routing\RouteSubscriberBase;
use Symfony\Component\Routing\RouteCollection;
/**
* Router subscriber class for testing purpose.
*/
class TestRouteSubscriber extends RouteSubscriberBase {
/**
* {@inheritdoc}
*/
protected function alterRoutes(RouteCollection $collection) {
\Drupal::state()->set('devel_test_route_rebuild','Router rebuild fired');
}
}
<?php
namespace Drupal\Tests\devel\Functional;
use Drupal\Tests\BrowserTestBase;
/**
* Tests routes rebuild.
*
* @group devel
*/
class DevelRouterRebuildTest extends BrowserTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['devel', 'devel_test'];
/**
* Test routes rebuild.
*/
public function testRouterRebuildConfirmForm() {
// Reset the state flag.
\Drupal::state()->set('devel_test_route_rebuild', NULL);
$this->drupalGet('devel/menu/reset');
$this->assertSession()->statusCodeEquals(403);
$web_user = $this->drupalCreateUser(['administer site configuration']);
$this->drupalLogin($web_user);
$this->drupalGet('devel/menu/reset');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextContains('Are you sure you want to rebuild the router?');
$route_rebuild_state = \Drupal::state()->get('devel_test_route_rebuild');
$this->assertEmpty($route_rebuild_state);
$this->drupalPostForm('devel/menu/reset', [], t('Rebuild'));
$this->assertSession()->pageTextContains('The router has been rebuilt.');
$route_rebuild_state = \Drupal::state()->get('devel_test_route_rebuild');
$this->assertEquals('Router rebuild fired', $route_rebuild_state);
}
}
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