Files
cake-contact-us/tests/TestCase/View/Helper/TurnstileHelperTest.php
T
2026-11-14 01:54:14 -08:00

101 lines
2.4 KiB
PHP

<?php
declare(strict_types=1);
namespace CakeContactUs\Test\TestCase\View\Helper;
use CakeContactUs\View\Helper\TurnstileHelper;
use Cake\TestSuite\TestCase;
use Cake\View\View;
/**
* App\View\Helper\TurnstileHelper Test Case
*/
class TurnstileHelperTest extends TestCase
{
/**
* Test subject
*
* @var \CakeContactUs\View\Helper\TurnstileHelper
*/
protected $Turnstile;
/**
* setUp method
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();
$view = new View();
$this->Turnstile = new TurnstileHelper($view);
}
/**
* tearDown method
*
* @return void
*/
protected function tearDown(): void
{
unset($this->Turnstile);
parent::tearDown();
}
/**
* @return void
*/
public function testPreConnect(): void
{
$this->assertStringContainsString(
'<link rel="preconnect" href="https://challenges.cloudflare.com" />',
$this->Turnstile->preConnect()
);
}
/**
* @return void
*/
public function testScriptNoEventListener(): void
{
$result = $this->Turnstile->script();
$this->assertStringContainsString(
'<script src="https://challenges.cloudflare.com/turnstile/v0/api.js"',
$result
);
$this->assertStringNotContainsString('console.log(', $result);
}
/**
* @return void
*/
public function testScriptWithEventListener(): void
{
$result = $this->Turnstile->script([
'eventListeners' => [
'dynamicButton' => true,
'log' => true,
],
]);
$this->assertStringContainsString(
'<script src="https://challenges.cloudflare.com/turnstile/v0/api.js"',
$result
);
$this->assertStringContainsString('console.log(', $result);
$this->assertStringContainsString('document.getElementById("submit-btn")?.disabled = false;', $result);
$this->assertStringContainsString('document.getElementById("submit-btn")?.disabled = true;', $result);
}
/**
* @return void
*/
public function testRender(): void
{
$this->assertStringContainsString(
'<script src="https://challenges.cloudflare.com/turnstile/v0/api.js"',
$this->Turnstile->script()
);
}
}