Files

88 lines
2.2 KiB
PHP
Raw Permalink Normal View History

2025-01-09 23:47:18 -08:00
<?php
declare(strict_types=1);
namespace CakeContactUs\Test\TestCase\Controller\Component;
use Cake\Controller\ComponentRegistry;
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;
use CakeContactUs\Model\Entity\ContactUsFormSubmission;
use CakeContactUs\Test\Fixture\ContactUsFormSubmissionsFixture;
2025-01-09 23:47:18 -08:00
/**
* CakeContactUs\Controller\Component\ContactUsComponent Test Case
*/
class ContactUsComponentTest extends TestCase {
2026-01-24 11:11:04 -08:00
protected ContactUsComponent $component;
protected Controller $controller;
/**
* Fixtures
2025-01-09 23:47:18 -08:00
*
* @var array<string>
2025-01-09 23:47:18 -08:00
*/
2026-01-24 11:11:04 -08:00
protected array $fixtures = [
2026-01-28 02:02:30 -08:00
ContactUsFormSubmissionsFixture::class,
2026-01-24 11:11:04 -08:00
];
/**
2025-01-09 23:47:18 -08:00
* setUp method
*
* @return void
*/
protected function setUp(): void {
parent::setUp();
2026-01-24 11:11:04 -08:00
$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
/**
2025-01-09 23:47:18 -08:00
* tearDown method
*
* @return void
*/
protected function tearDown(): void {
unset($this->component);
parent::tearDown();
}
2025-01-09 23:47:18 -08:00
2026-01-24 11:11:04 -08:00
/**
* @return void
*/
public function testNewContactUsFormWithoutCaptcha() {
$this->assertInstanceOf(ContactUsFormSubmission::class, $this->component->newContactUsForm());
}
/**
* @return void
*/
public function testNewContactUsFormWithCaptcha() {
$this->component->setConfig('requireCaptcha', true);
$this->assertInstanceOf(ContactUsFormSubmission::class, $this->component->newContactUsForm());
}
/**
* @return void
*/
public function testProcessContactUsFormSaved() {
$numSubmissionsBefore = $this->fetchTable('CakeContactUs.ContactUsFormSubmissions')->find()->count();
2026-01-24 11:11:04 -08:00
$result = $this->component->processContactUsForm($this->component->newContactUsForm(), [
'first_name' => 'Jane Doe',
2026-01-24 11:11:04 -08:00
'email' => 'test@example.com',
'message' => 'contact us message',
2026-01-24 11:11:04 -08:00
]);
$this->assertNotInstanceOf(ContactUsFormSubmission::class, $result);
$numSubmissionsAfter = $this->fetchTable('CakeContactUs.ContactUsFormSubmissions')->find()->count();
2026-01-24 11:11:04 -08:00
$this->assertEquals($numSubmissionsBefore + 1, $numSubmissionsAfter);
}
2025-01-09 23:47:18 -08:00
}