2025-01-09 23:47:18 -08:00
|
|
|
<?php
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace CakeContactUs\Test\TestCase\Controller\Component;
|
|
|
|
|
|
|
|
|
|
use Cake\Controller\ComponentRegistry;
|
2026-01-24 01:20:17 -08:00
|
|
|
use Cake\Controller\Controller;
|
|
|
|
|
use Cake\Http\ServerRequest;
|
2025-01-09 23:47:18 -08:00
|
|
|
use Cake\TestSuite\TestCase;
|
|
|
|
|
use CakeContactUs\Controller\Component\ContactUsComponent;
|
2026-01-24 01:20:17 -08:00
|
|
|
use CakeContactUs\Model\Entity\ContactUsFormSubmission;
|
2025-01-09 23:47:18 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* CakeContactUs\Controller\Component\ContactUsComponent Test Case
|
|
|
|
|
*/
|
2026-01-24 01:20:17 -08:00
|
|
|
class ContactUsComponentTest extends TestCase {
|
|
|
|
|
|
|
|
|
|
protected ContactUsComponent $component;
|
|
|
|
|
protected Controller $controller;
|
|
|
|
|
|
2025-01-09 23:47:18 -08:00
|
|
|
/**
|
2026-01-24 01:20:17 -08:00
|
|
|
* Fixtures
|
2025-01-09 23:47:18 -08:00
|
|
|
*
|
2026-01-24 01:20:17 -08:00
|
|
|
* @var array<string>
|
2025-01-09 23:47:18 -08:00
|
|
|
*/
|
2026-01-24 01:20:17 -08:00
|
|
|
protected array $fixtures = [
|
|
|
|
|
'plugin.CakeContactUs.ContactUsFormSubmissions',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/**
|
2025-01-09 23:47:18 -08:00
|
|
|
* setUp method
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2026-01-24 01:20:17 -08:00
|
|
|
protected function setUp(): void {
|
|
|
|
|
parent::setUp();
|
|
|
|
|
$request = new ServerRequest();
|
|
|
|
|
$this->controller = new Controller($request);
|
|
|
|
|
$registry = new ComponentRegistry($this->controller);
|
|
|
|
|
|
|
|
|
|
$this->component = new ContactUsComponent($registry);
|
|
|
|
|
}
|
2025-01-09 23:47:18 -08:00
|
|
|
|
2026-01-24 01:20:17 -08:00
|
|
|
/**
|
2025-01-09 23:47:18 -08:00
|
|
|
* tearDown method
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2026-01-24 01:20:17 -08:00
|
|
|
protected function tearDown(): void {
|
|
|
|
|
unset($this->component);
|
|
|
|
|
|
|
|
|
|
parent::tearDown();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testNewContactUsFormWithoutCaptcha()
|
|
|
|
|
{
|
|
|
|
|
$this->assertInstanceOf(ContactUsFormSubmission::class, $this->component->newContactUsForm());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testNewContactUsFormWithCaptcha()
|
2025-01-09 23:47:18 -08:00
|
|
|
{
|
2026-01-24 01:20:17 -08:00
|
|
|
$this->component->setConfig('requireCaptcha', true);
|
|
|
|
|
$this->assertInstanceOf(ContactUsFormSubmission::class, $this->component->newContactUsForm());
|
|
|
|
|
}
|
2025-01-09 23:47:18 -08:00
|
|
|
|
2026-01-24 01:20:17 -08:00
|
|
|
public function testProcessContactUsFormSaved()
|
|
|
|
|
{
|
|
|
|
|
$numSubmissionsBefore = $this->fetchTable('CakeContactUs/ContactUsFormSubmissions')->find()->count();
|
|
|
|
|
$result = $this->component->processContactUsForm($this->component->newContactUsForm(), [
|
|
|
|
|
'name' => 'Jane Doe',
|
|
|
|
|
'email' => 'test@example.com',
|
|
|
|
|
]);
|
|
|
|
|
$this->assertNotInstanceOf(ContactUsFormSubmission::class, $result);
|
|
|
|
|
$numSubmissionsAfter = $this->fetchTable('CakeContactUs/ContactUsFormSubmissions')->find()->count();
|
|
|
|
|
$this->assertEquals($numSubmissionsBefore + 1, $numSubmissionsAfter);
|
2025-01-09 23:47:18 -08:00
|
|
|
}
|
|
|
|
|
}
|