fixtures suck
This commit is contained in:
@@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
class AlterContactUsFormSubmissionsKeywords extends AbstractMigration {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* up Method.
|
||||||
|
*
|
||||||
|
* More information on this method is available here:
|
||||||
|
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up(): void {
|
||||||
|
$table = $this->table('contact_us_form_submissions');
|
||||||
|
if ($table->hasColumn('subject')) {
|
||||||
|
$table->renameColumn('subject', 'contact_subject');
|
||||||
|
}
|
||||||
|
if ($table->hasColumn('name')) {
|
||||||
|
$table->renameColumn('name', 'first_name');
|
||||||
|
}
|
||||||
|
$table->addColumn('last_name', 'string', [
|
||||||
|
'limit' => 255,
|
||||||
|
'default' => null,
|
||||||
|
'null' => true,
|
||||||
|
]);
|
||||||
|
$table->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* down Method.
|
||||||
|
*
|
||||||
|
* More information on this method is available here:
|
||||||
|
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down(): void {
|
||||||
|
$table = $this->table('contact_us_form_submissions');
|
||||||
|
if ($table->hasColumn('contact_subject')) {
|
||||||
|
$table->renameColumn('contact_subject', 'subject');
|
||||||
|
}
|
||||||
|
if ($table->hasColumn('fist_name')) {
|
||||||
|
$table->renameColumn('fist_name', 'name');
|
||||||
|
}
|
||||||
|
$table->removeColumn('last_name');
|
||||||
|
$table->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -8,11 +8,12 @@
|
|||||||
<php>
|
<php>
|
||||||
<ini name="memory_limit" value="-1"/>
|
<ini name="memory_limit" value="-1"/>
|
||||||
<ini name="apc.enable_cli" value="1"/>
|
<ini name="apc.enable_cli" value="1"/>
|
||||||
|
<env name="FIXTURE_SCHEMA_METADATA" value="tests/schema.php"/>
|
||||||
</php>
|
</php>
|
||||||
|
|
||||||
<!-- Add any additional test suites you want to run here -->
|
<!-- Add any additional test suites you want to run here -->
|
||||||
<testsuites>
|
<testsuites>
|
||||||
<testsuite name="CakeContactUs">
|
<testsuite name="CakeConctactUs">
|
||||||
<directory>tests/TestCase/</directory>
|
<directory>tests/TestCase/</directory>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
</testsuites>
|
</testsuites>
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ use Cake\ORM\Entity;
|
|||||||
* @property string $client_ip
|
* @property string $client_ip
|
||||||
* @property string $name
|
* @property string $name
|
||||||
* @property string|null $email
|
* @property string|null $email
|
||||||
* @property string|null $subject
|
* @property string|null $contact_subject
|
||||||
* @property string $message
|
* @property string $message
|
||||||
* @property \Cake\I18n\DateTime|null $confirm_email_sent
|
* @property \Cake\I18n\DateTime|null $confirm_email_sent
|
||||||
* @property \Cake\I18n\DateTime|null $backend_email_sent
|
* @property \Cake\I18n\DateTime|null $backend_email_sent
|
||||||
@@ -34,7 +34,7 @@ class ContactUsFormSubmission extends Entity {
|
|||||||
'client_ip' => true,
|
'client_ip' => true,
|
||||||
'name' => true,
|
'name' => true,
|
||||||
'email' => true,
|
'email' => true,
|
||||||
'subject' => true,
|
'contact_subject' => true,
|
||||||
'message' => true,
|
'message' => true,
|
||||||
'confirm_email_sent' => true,
|
'confirm_email_sent' => true,
|
||||||
'backend_email_sent' => true,
|
'backend_email_sent' => true,
|
||||||
|
|||||||
@@ -82,14 +82,14 @@ class ContactUsFormSubmissionsTable extends Table {
|
|||||||
$validator->allowEmptyString('email');
|
$validator->allowEmptyString('email');
|
||||||
}
|
}
|
||||||
|
|
||||||
// subject
|
// contact_subject
|
||||||
$validator
|
$validator
|
||||||
->scalar('subject')
|
->scalar('contact_subject')
|
||||||
->maxLength('subject', 255);
|
->maxLength('contact_subject', 255);
|
||||||
if ($fields['subject'] ?? false) {
|
if ($fields['subject'] ?? false) {
|
||||||
$validator->notEmptyString('subject');
|
$validator->notEmptyString('contact_subject');
|
||||||
} else {
|
} else {
|
||||||
$validator->allowEmptyString('subject');
|
$validator->allowEmptyString('contact_subject');
|
||||||
}
|
}
|
||||||
|
|
||||||
$validator
|
$validator
|
||||||
|
|||||||
@@ -10,25 +10,15 @@ use Cake\TestSuite\Fixture\TestFixture;
|
|||||||
*/
|
*/
|
||||||
class ContactUsFormSubmissionsFixture extends TestFixture {
|
class ContactUsFormSubmissionsFixture extends TestFixture {
|
||||||
|
|
||||||
|
public string $table = 'contact_us_form_submissions';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Init method
|
* Init method
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function init(): void {
|
public function init(): void {
|
||||||
$this->records = [
|
$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',
|
|
||||||
],
|
|
||||||
];
|
|
||||||
parent::init();
|
parent::init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,17 +15,18 @@ use CakeContactUs\Model\Entity\ContactUsFormSubmission;
|
|||||||
*/
|
*/
|
||||||
class ContactUsComponentTest extends TestCase {
|
class ContactUsComponentTest extends TestCase {
|
||||||
|
|
||||||
protected ContactUsComponent $component;
|
protected ContactUsComponent $component;
|
||||||
protected Controller $controller;
|
|
||||||
|
|
||||||
/**
|
protected Controller $controller;
|
||||||
|
|
||||||
|
/**
|
||||||
* Fixtures
|
* Fixtures
|
||||||
*
|
*
|
||||||
* @var array<string>
|
* @var array<string>
|
||||||
*/
|
*/
|
||||||
protected array $fixtures = [
|
protected array $fixtures = [
|
||||||
'plugin.CakeContactUs.ContactUsFormSubmissions',
|
'plugin.CakeContactUs.ContactUsFormSubmissions',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* setUp method
|
* setUp method
|
||||||
@@ -34,11 +35,11 @@ class ContactUsComponentTest extends TestCase {
|
|||||||
*/
|
*/
|
||||||
protected function setUp(): void {
|
protected function setUp(): void {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$request = new ServerRequest();
|
$request = new ServerRequest();
|
||||||
$this->controller = new Controller($request);
|
$this->controller = new Controller($request);
|
||||||
$registry = new ComponentRegistry($this->controller);
|
$registry = new ComponentRegistry($this->controller);
|
||||||
|
|
||||||
$this->component = new ContactUsComponent($registry);
|
$this->component = new ContactUsComponent($registry);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -52,26 +53,33 @@ class ContactUsComponentTest extends TestCase {
|
|||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNewContactUsFormWithoutCaptcha()
|
/**
|
||||||
{
|
* @return void
|
||||||
$this->assertInstanceOf(ContactUsFormSubmission::class, $this->component->newContactUsForm());
|
*/
|
||||||
}
|
public function testNewContactUsFormWithoutCaptcha() {
|
||||||
|
$this->assertInstanceOf(ContactUsFormSubmission::class, $this->component->newContactUsForm());
|
||||||
|
}
|
||||||
|
|
||||||
public function testNewContactUsFormWithCaptcha()
|
/**
|
||||||
{
|
* @return void
|
||||||
$this->component->setConfig('requireCaptcha', true);
|
*/
|
||||||
$this->assertInstanceOf(ContactUsFormSubmission::class, $this->component->newContactUsForm());
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -141,6 +141,7 @@ ConnectionManager::setConfig('test', [
|
|||||||
'timezone' => 'UTC',
|
'timezone' => 'UTC',
|
||||||
'quoteIdentifiers' => false,
|
'quoteIdentifiers' => false,
|
||||||
'cacheMetadata' => true,
|
'cacheMetadata' => true,
|
||||||
|
'log' => true,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -156,16 +157,20 @@ ConnectionManager::setConfig('test', [
|
|||||||
// Load a schema dump file.
|
// Load a schema dump file.
|
||||||
//(new SchemaLoader())->loadSqlFiles('tests/schema.sql', 'test');
|
//(new SchemaLoader())->loadSqlFiles('tests/schema.sql', 'test');
|
||||||
if (!defined('SECOND')) {
|
if (!defined('SECOND')) {
|
||||||
define('SECOND', 1);
|
define('SECOND', 1);
|
||||||
define('MINUTE', 60);
|
define('MINUTE', 60);
|
||||||
define('HOUR', 3600);
|
define('HOUR', 3600);
|
||||||
define('DAY', 86400);
|
define('DAY', 86400);
|
||||||
define('WEEK', 604800);
|
define('WEEK', 604800);
|
||||||
define('MONTH', 2592000);
|
define('MONTH', 2592000);
|
||||||
define('YEAR', 31536000);
|
define('YEAR', 31536000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$migrator = new Migrator();
|
$migrator = new Migrator();
|
||||||
$migrator->run(['plugin' => 'CakeContactUs']);
|
$migrator->runMany([
|
||||||
$migrator->run(['plugin' => 'Captcha']);
|
// Run app migrations on test connection.
|
||||||
|
['connection' => 'test'],
|
||||||
|
// Run plugin migrations on test connection.
|
||||||
|
['plugin' => 'CakeContactUs'],
|
||||||
|
['plugin' => 'Captcha'],
|
||||||
|
]);
|
||||||
|
|||||||
Reference in New Issue
Block a user