function GotoActionTest::testGotoAction
Tests goto action.
Attributes
#[DataProvider('providerGotoAction')]
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Action/ GotoActionTest.php, line 34
Class
- GotoActionTest
- Tests Goto Action.
Namespace
Drupal\KernelTests\Core\ActionCode
public function testGotoAction(string $url, string $expected) : void {
$entity = $this->createMock(EntityInterface::class);
$action = Action::create([
'id' => 'goto',
'plugin' => 'action_goto_action',
'configuration' => [
'url' => $url,
],
]);
$action->save();
$action->execute([
$entity,
]);
// Simulate a request to trigger the redirect.
$request = Request::create('');
$response = $this->container
->get('http_kernel')
->handle($request);
$location = $response->headers
->get('Location');
// Convert to relative path.
$base = rtrim(Url::fromRoute('<front>')->setAbsolute()
->toString(), '/');
if (str_starts_with($location, $base)) {
$location = substr($location, strlen($base));
}
$this->assertSame(302, $response->getStatusCode());
$this->assertSame($expected, $location);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.