function PathChangedHelperTest::testPathChangedHelper
Tests creating a PathChangedHelper object and getting paths.
@covers ::__construct
      
    
@covers ::oldPath
      
    
@covers ::newPath
      
    
@covers ::redirect
      
    
File
- 
              core/
tests/ Drupal/ KernelTests/ Core/ Routing/ PathChangedHelperTest.php, line 35  
Class
- PathChangedHelperTest
 - Tests the PathChangedHelper class.
 
Namespace
Drupal\KernelTests\Core\RoutingCode
public function testPathChangedHelper() : void {
  $route = \Drupal::service('router.route_provider')->getRouteByName('path.changed.bc');
  $raw_parameters = [
    'block_type' => 'test_block_type',
  ];
  $query = [
    'destination' => 'admin/structure/block',
    'plugin_id' => 'some_block_config',
  ];
  $helper = new PathChangedHelper(new RouteMatch('path.changed.bc', $route, [], $raw_parameters), new Request($query));
  // Assert that oldPath() returns the internal path for path.changed.bc.
  $this->assertEquals('old/path/test_block_type', $helper->oldPath());
  // Assert that newPath() returns the internal path for path.changed.
  $this->assertEquals('new/path/test_block_type', $helper->newPath());
  // Assert that redirect() returns a RedirectResponse for the absolute URL of
  // path.changed, and the query string comes from the Request object with the
  // destination parameter removed.
  $redirect = $helper->redirect();
  $this->assertInstanceOf(RedirectResponse::class, $redirect);
  $this->assertEquals(301, $redirect->getStatusCode());
  $base_path = Url::fromRoute('<front>', [], [
    'absolute' => TRUE,
  ])->toString();
  $this->assertEquals($base_path . 'new/path/test_block_type?plugin_id=some_block_config', $redirect->getTargetUrl());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.