Files
cake-contact-us/tests/TestCase/Controller/Component/ContactUsComponentTest.php
Brandon Shipley 1be025aa22
Some checks failed
CI / testsuite (mysql, 8.2, ) (push) Failing after 4m30s
CI / testsuite (pgsql, 8.2, ) (push) Failing after 8m57s
CI / testsuite (mysql, 8.4, ) (push) Has started running
CI / testsuite (pgsql, 8.4, ) (push) Has started running
CI / testsuite (sqlite, 8.2, ) (push) Has started running
CI / testsuite (sqlite, 8.2, prefer-lowest) (push) Has been cancelled
CI / testsuite (sqlite, 8.4, ) (push) Has been cancelled
CI / Coding Standard & Static Analysis (push) Has been cancelled
tests should be working / build should suceed now
2026-01-28 01:23:58 -08:00

88 lines
2.2 KiB
PHP

<?php
declare(strict_types=1);
namespace CakeContactUs\Test\TestCase\Controller\Component;
use Cake\Controller\ComponentRegistry;
use Cake\Controller\Controller;
use Cake\Http\ServerRequest;
use Cake\TestSuite\TestCase;
use CakeContactUs\Controller\Component\ContactUsComponent;
use CakeContactUs\Model\Entity\ContactUsFormSubmission;
use CakeContactUs\Test\Fixture\ContactUsFormSubmissionsFixture;
/**
* CakeContactUs\Controller\Component\ContactUsComponent Test Case
*/
class ContactUsComponentTest extends TestCase {
protected ContactUsComponent $component;
protected Controller $controller;
/**
* Fixtures
*
* @var array<string>
*/
protected array $fixtures = [
ContactUsFormSubmissionsFixture::class,
];
/**
* setUp method
*
* @return void
*/
protected function setUp(): void {
parent::setUp();
$request = new ServerRequest();
$this->controller = new Controller($request);
$registry = new ComponentRegistry($this->controller);
$this->component = new ContactUsComponent($registry);
}
/**
* tearDown method
*
* @return void
*/
protected function tearDown(): void {
unset($this->component);
parent::tearDown();
}
/**
* @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();
$result = $this->component->processContactUsForm($this->component->newContactUsForm(), [
'first_name' => 'Jane Doe',
'email' => 'test@example.com',
'message' => 'contact us message',
]);
$this->assertNotInstanceOf(ContactUsFormSubmission::class, $result);
$numSubmissionsAfter = $this->fetchTable('CakeContactUs.ContactUsFormSubmissions')->find()->count();
$this->assertEquals($numSubmissionsBefore + 1, $numSubmissionsAfter);
}
}