diff --git a/tests/src/Functional/RedirectTest.php b/tests/src/Functional/RedirectTest.php new file mode 100644 index 0000000..75fc3b4 --- /dev/null +++ b/tests/src/Functional/RedirectTest.php @@ -0,0 +1,74 @@ +config('turnstile.settings') + ->set('site_key', '1x00000000000000000000AA') + ->set('secret_key', '1x0000000000000000000000000000000AA') + ->save(); + + $config = $this->config('turnstile_protect.settings') + ->set('routes', ["entity.node.canonical"]) + ->set('bots', []) + ->set('rate_limit', TRUE) + ->set('window', 86400) + ->set('threshold', 1) + ->set('history_enabled', FALSE) + ->save(); + + $this->assertEquals("entity.node.canonical", $config->get('routes')[0], 'Routes configuration is set to node.entity.canonical.'); + \Drupal::service('cache.config')->deleteAll(); + + } + + /** + * Tests redirection from node to /challenge. + */ + public function testNodeRedirect() { + $node = $this->drupalCreateNode(['type' => 'page']); + $nodeUrl = $node->toUrl()->toString(); + $this->drupalGet($nodeUrl); + + $url = $this->getSession()->getCurrentUrl(); + $components = parse_url($url); + $this->assertEquals($nodeUrl, $components['path'], 'User is not redirected to /challenge.'); + + $this->drupalGet($nodeUrl); + $url = $this->getSession()->getCurrentUrl(); + $components = parse_url($url); + $this->assertEquals('/challenge', $components['path'], 'User is redirected to /challenge.'); + } + +} diff --git a/tests/src/Kernel/TurnstileProtectTest.php b/tests/src/Kernel/TurnstileProtectTest.php index 50797d5..3803206 100644 --- a/tests/src/Kernel/TurnstileProtectTest.php +++ b/tests/src/Kernel/TurnstileProtectTest.php @@ -5,7 +5,7 @@ use Drupal\KernelTests\KernelTestBase; /** - * Tests basic functionality of the YourModule module. + * Tests basic functionality of the turnstile_protect module. * * @group turnstile_protect */