Files
cake-contact-us/tests/TestCase/View/Helper/TurnstileHelperTest.php
T

96 lines
2.1 KiB
PHP
Raw Normal View History

2026-11-14 01:54:14 -08:00
<?php
declare(strict_types=1);
namespace CakeContactUs\Test\TestCase\View\Helper;
use Cake\TestSuite\TestCase;
use Cake\View\View;
use CakeContactUs\View\Helper\TurnstileHelper;
2026-11-14 01:54:14 -08:00
/**
* App\View\Helper\TurnstileHelper Test Case
*/
class TurnstileHelperTest extends TestCase {
/**
2026-11-14 01:54:14 -08:00
* Test subject
*
* @var \CakeContactUs\View\Helper\TurnstileHelper
*/
protected $Turnstile;
2026-11-14 01:54:14 -08:00
/**
2026-11-14 01:54:14 -08:00
* setUp method
*
* @return void
*/
protected function setUp(): void {
parent::setUp();
$view = new View();
$this->Turnstile = new TurnstileHelper($view);
}
2026-11-14 01:54:14 -08:00
/**
2026-11-14 01:54:14 -08:00
* tearDown method
*
* @return void
*/
protected function tearDown(): void {
unset($this->Turnstile);
2026-11-14 01:54:14 -08:00
parent::tearDown();
}
2026-11-14 01:54:14 -08:00
/**
2026-11-14 01:54:14 -08:00
* @return void
*/
public function testPreConnect(): void {
$this->assertStringContainsString(
'<link rel="preconnect" href="https://challenges.cloudflare.com" />',
$this->Turnstile->preConnect(),
);
}
2026-11-14 01:54:14 -08:00
/**
2026-11-14 01:54:14 -08:00
* @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);
}
2026-11-14 01:54:14 -08:00
/**
2026-11-14 01:54:14 -08:00
* @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);
}
2026-11-14 01:54:14 -08:00
/**
2026-11-14 01:54:14 -08:00
* @return void
*/
public function testRender(): void {
$this->assertStringContainsString(
'<script src="https://challenges.cloudflare.com/turnstile/v0/api.js"',
$this->Turnstile->script(),
);
}
2026-11-14 01:54:14 -08:00
}