class GotoActionTest
Tests Goto Action.
Attributes
#[CoversClass(GotoAction::class)]
#[Group('Action')]
#[RunTestsInSeparateProcesses]
Hierarchy
- class \Drupal\KernelTests\KernelTestBase implements \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\KernelTests\Core\Action\GotoActionTest extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of GotoActionTest
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Action/ GotoActionTest.php, line 21
Namespace
Drupal\KernelTests\Core\ActionView source
class GotoActionTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'system',
];
/**
* Tests goto action.
*/
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);
}
/**
* Data provider for ::testGotoAction().
*/
public static function providerGotoAction() : array {
return [
'<front>' => [
'<front>',
'/',
],
'empty string' => [
'',
'/',
],
'internal path' => [
'/user',
'/user',
],
'internal path with query and fragment' => [
'/user?foo=bar#baz',
'/user?foo=bar#baz',
],
'external URL' => [
'https://example.com',
'https://example.com',
],
];
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.