fixtures suck

This commit is contained in:
2026-01-24 11:11:04 -08:00
parent 37b7bca3be
commit ea1cb8cd29
7 changed files with 121 additions and 67 deletions

View File

@@ -10,25 +10,15 @@ use Cake\TestSuite\Fixture\TestFixture;
*/
class ContactUsFormSubmissionsFixture extends TestFixture {
public string $table = 'contact_us_form_submissions';
/**
* Init method
*
* @return void
*/
public function init(): void {
$this->records = [
[
'id' => '76fbe7fb-1949-4670-a3d2-c0b48eb98e8d',
'submitted_at' => '2025-01-03 09:16:50',
'client_ip' => 'Lorem ipsum dolor sit amet',
'name' => 'Lorem ipsum dolor sit amet',
'email' => 'Lorem ipsum dolor sit amet',
'subject' => 'Lorem ipsum dolor sit amet',
'message' => 'Lorem ipsum dolor sit amet, aliquet feugiat. Convallis morbi fringilla gravida, phasellus feugiat dapibus velit nunc, pulvinar eget sollicitudin venenatis cum nullam, vivamus ut a sed, mollitia lectus. Nulla vestibulum massa neque ut et, id hendrerit sit, feugiat in taciti enim proin nibh, tempor dignissim, rhoncus duis vestibulum nunc mattis convallis.',
'confirm_email_sent' => '2025-01-03 09:16:50',
'backend_email_sent' => '2025-01-03 09:16:50',
],
];
$this->records = [];
parent::init();
}

View File

@@ -14,19 +14,20 @@ use CakeContactUs\Model\Entity\ContactUsFormSubmission;
* CakeContactUs\Controller\Component\ContactUsComponent Test Case
*/
class ContactUsComponentTest extends TestCase {
protected ContactUsComponent $component;
protected Controller $controller;
/**
protected ContactUsComponent $component;
protected Controller $controller;
/**
* Fixtures
*
* @var array<string>
*/
protected array $fixtures = [
'plugin.CakeContactUs.ContactUsFormSubmissions',
];
protected array $fixtures = [
'plugin.CakeContactUs.ContactUsFormSubmissions',
];
/**
* setUp method
*
@@ -34,11 +35,11 @@ class ContactUsComponentTest extends TestCase {
*/
protected function setUp(): void {
parent::setUp();
$request = new ServerRequest();
$this->controller = new Controller($request);
$registry = new ComponentRegistry($this->controller);
$this->component = new ContactUsComponent($registry);
$request = new ServerRequest();
$this->controller = new Controller($request);
$registry = new ComponentRegistry($this->controller);
$this->component = new ContactUsComponent($registry);
}
/**
@@ -51,27 +52,34 @@ class ContactUsComponentTest extends TestCase {
parent::tearDown();
}
public function testNewContactUsFormWithoutCaptcha()
{
$this->assertInstanceOf(ContactUsFormSubmission::class, $this->component->newContactUsForm());
}
public function testNewContactUsFormWithCaptcha()
{
$this->component->setConfig('requireCaptcha', true);
$this->assertInstanceOf(ContactUsFormSubmission::class, $this->component->newContactUsForm());
}
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);
}
/**
* @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(), [
'name' => 'Jane Doe',
'email' => 'test@example.com',
]);
$this->assertNotInstanceOf(ContactUsFormSubmission::class, $result);
$numSubmissionsAfter = $this->fetchTable('CakeContactUs/ContactUsFormSubmissions')->find()->count();
$this->assertEquals($numSubmissionsBefore + 1, $numSubmissionsAfter);
}
}

View File

@@ -141,6 +141,7 @@ ConnectionManager::setConfig('test', [
'timezone' => 'UTC',
'quoteIdentifiers' => false,
'cacheMetadata' => true,
'log' => true,
]);
/**
@@ -156,16 +157,20 @@ ConnectionManager::setConfig('test', [
// Load a schema dump file.
//(new SchemaLoader())->loadSqlFiles('tests/schema.sql', 'test');
if (!defined('SECOND')) {
define('SECOND', 1);
define('MINUTE', 60);
define('HOUR', 3600);
define('DAY', 86400);
define('WEEK', 604800);
define('MONTH', 2592000);
define('YEAR', 31536000);
define('SECOND', 1);
define('MINUTE', 60);
define('HOUR', 3600);
define('DAY', 86400);
define('WEEK', 604800);
define('MONTH', 2592000);
define('YEAR', 31536000);
}
$migrator = new Migrator();
$migrator->run(['plugin' => 'CakeContactUs']);
$migrator->run(['plugin' => 'Captcha']);
$migrator->runMany([
// Run app migrations on test connection.
['connection' => 'test'],
// Run plugin migrations on test connection.
['plugin' => 'CakeContactUs'],
['plugin' => 'Captcha'],
]);