diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml
new file mode 100644
index 0000000..0c48d65
--- /dev/null
+++ b/.gitea/workflows/ci.yaml
@@ -0,0 +1,133 @@
+name: CI
+
+on:
+ push:
+ pull_request:
+ workflow_dispatch:
+
+jobs:
+ testsuite:
+ runs-on: ubuntu-latest
+ strategy:
+ fail-fast: false
+ matrix:
+ php-version: ['8.2', '8.4']
+# db-type: ['mysql']
+ db-type: ['sqlite', 'mysql', 'pgsql']
+ prefer-lowest: ['']
+ include:
+ - php-version: '8.2'
+ db-type: 'sqlite'
+ prefer-lowest: 'prefer-lowest'
+
+ services:
+ mysql8:
+ image: mysql:8.0
+ env:
+ MYSQL_ALLOW_EMPTY_PASSWORD: yes
+ MYSQL_DATABASE: cakephp
+# services:
+# postgres:
+# image: postgres
+# ports:
+# - 5432:5432
+# env:
+# POSTGRES_PASSWORD: postgres
+
+ steps:
+ - uses: actions/checkout@v4
+ - name: Setup PHP
+ uses: shivammathur/setup-php@v2
+ with:
+ php-version: ${{ matrix.php-version }}
+ extensions: mbstring, intl, sqlite, pdo_${{ matrix.db-type }}
+ coverage: pcov
+
+ - name: Get composer cache directory
+ id: composercache
+ run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
+
+ - name: Cache dependencies
+ uses: actions/cache@v4
+ with:
+ path: ${{ steps.composercache.outputs.dir }}
+ key: ${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }}
+
+ - name: Composer install
+ run: |
+ composer --version
+ if ${{ matrix.prefer-lowest == 'prefer-lowest' }}
+ then
+ composer update --prefer-lowest --prefer-stable
+ composer require --dev dereuromark/composer-prefer-lowest:dev-master
+ else
+ composer install --no-progress --prefer-dist --optimize-autoloader
+ fi
+
+ - name: Setup problem matchers for PHPUnit
+ if: matrix.db-type == 'mysql'
+ run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
+
+
+ - name: Run PHPUnit tests
+ env:
+ TEST_MYSQL_HOST: mysql8
+ TEST_MYSQL_CHARSET: utf8mb4
+ TEST_MYSQL_DBNAME: cakephp
+ TEST_MYSQL_USERNAME: root
+ TEST_MYSQL_PASSWORD:
+ run: |
+ if [[ ${{ matrix.php-version }} == '8.2' ]]; then
+ vendor/bin/phpunit --coverage-clover=coverage.xml
+ else
+ vendor/bin/phpunit
+ fi
+
+ - name: Validate prefer-lowest
+ if: matrix.prefer-lowest == 'prefer-lowest'
+ run: vendor/bin/validate-prefer-lowest -m
+
+# - name: Upload coverage reports to Codecov
+# if: success() && matrix.php-version == '8.2'
+# uses: codecov/codecov-action@v4
+# with:
+# token: ${{ secrets.CODECOV_TOKEN }}
+
+ validation:
+ name: Coding Standard & Static Analysis
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+ - name: Setup PHP
+ uses: shivammathur/setup-php@v2
+ with:
+ php-version: '8.2'
+ extensions: mbstring, intl, sqlite
+ coverage: none
+
+ - name: Get composer cache directory
+ id: composercache
+ run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
+
+ - name: Cache dependencies
+ uses: actions/cache@v4
+ with:
+ path: ${{ steps.composercache.outputs.dir }}
+ key: ${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }}
+
+ - name: Composer install
+ run: |
+ composer --version
+ if ${{ matrix.prefer-lowest == 'prefer-lowest' }}
+ then
+ composer update --prefer-lowest --prefer-stable
+ composer require --dev dereuromark/composer-prefer-lowest:dev-master
+ else
+ composer install --no-progress --prefer-dist --optimize-autoloader
+ fi
+
+ - name: Run phpstan
+ run: vendor/bin/phpstan analyse src --error-format=github
+
+ - name: Run phpcs
+ run: composer cs-check
diff --git a/.gitea/workflows/release.yaml b/.gitea/workflows/release.yaml
new file mode 100644
index 0000000..77787fb
--- /dev/null
+++ b/.gitea/workflows/release.yaml
@@ -0,0 +1,17 @@
+name: Release
+
+on:
+ push:
+ tags:
+ - "v*.*.*"
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v4
+ - name: Release
+ uses: softprops/action-gh-release@v2
+
+
diff --git a/.gitea/workflows/status.yaml b/.gitea/workflows/status.yaml
new file mode 100644
index 0000000..c703766
--- /dev/null
+++ b/.gitea/workflows/status.yaml
@@ -0,0 +1,31 @@
+---
+name: CI Build Status
+
+on:
+ workflow_run:
+ workflows:
+ - CI
+ types:
+ - completed
+jobs:
+ on-success:
+ runs-on: ubuntu-latest
+ if: ${{ github.event.workflow_run.conclusion == 'success' }}
+ steps:
+ - name: Webhook
+ uses: zzzze/webhook-trigger@master
+ with:
+ data: "{\"text\":\"${{ gitea.repository }} build succeeded 🎉\"}"
+ webhook_url: ${{ secrets.BUILD_STATUS_NOTIFY_WEBHOOK_URL }}
+ options: "-H \"Content-Type: application/json\""
+
+ on-failure:
+ runs-on: ubuntu-latest
+ if: ${{ github.event.workflow_run.conclusion == 'failure' }}
+ steps:
+ - name: Webhook
+ uses: zzzze/webhook-trigger@master
+ with:
+ data: "{\"text\":\"${{ gitea.repository }} build failed 🔎\"}"
+ webhook_url: ${{ secrets.BUILD_STATUS_NOTIFY_WEBHOOK_URL }}
+ options: "-H \"Content-Type: application/json\""
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
new file mode 100644
index 0000000..84a1672
--- /dev/null
+++ b/.github/workflows/ci.yml
@@ -0,0 +1,127 @@
+name: CI
+
+on:
+ push:
+ pull_request:
+ workflow_dispatch:
+
+jobs:
+ testsuite:
+ runs-on: ubuntu-22.04
+ strategy:
+ fail-fast: false
+ matrix:
+ php-version: ['8.1', '8.4']
+ db-type: ['sqlite', 'mysql', 'pgsql']
+ prefer-lowest: ['']
+ include:
+ - php-version: '8.1'
+ db-type: 'sqlite'
+ prefer-lowest: 'prefer-lowest'
+
+ services:
+ postgres:
+ image: postgres
+ ports:
+ - 5432:5432
+ env:
+ POSTGRES_PASSWORD: postgres
+
+ steps:
+ - uses: actions/checkout@v4
+
+ - name: Setup Service
+ if: matrix.db-type == 'mysql'
+ run: |
+ sudo service mysql start
+ mysql -h 127.0.0.1 -u root -proot -e 'CREATE DATABASE cakephp;'
+
+ - name: Setup PHP
+ uses: shivammathur/setup-php@v2
+ with:
+ php-version: ${{ matrix.php-version }}
+ extensions: mbstring, intl, bcmath, pdo_${{ matrix.db-type }}
+ coverage: pcov
+
+ - name: Get composer cache directory
+ id: composercache
+ run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
+
+ - name: Cache dependencies
+ uses: actions/cache@v4
+ with:
+ path: ${{ steps.composercache.outputs.dir }}
+ key: ${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }}
+
+ - name: Composer install
+ run: |
+ composer --version
+ if ${{ matrix.prefer-lowest == 'prefer-lowest' }}
+ then
+ composer update --prefer-lowest --prefer-stable
+ composer require --dev dereuromark/composer-prefer-lowest:dev-master
+ else
+ composer install --no-progress --prefer-dist --optimize-autoloader
+ fi
+
+ - name: Setup problem matchers for PHPUnit
+ if: matrix.db-type == 'mysql'
+ run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
+
+ - name: Wait for MySQL
+ if: matrix.db-type == 'mysql'
+ run: while ! `mysqladmin ping -h 127.0.0.1 --silent`; do printf 'Waiting for MySQL...\n'; sleep 2; done;
+
+ - name: Run PHPUnit
+ run: |
+ if [[ ${{ matrix.db-type }} == 'sqlite' ]]; then export DB_URL='sqlite:///:memory:'; fi
+ if [[ ${{ matrix.db-type }} == 'mysql' ]]; then export DB_URL='mysql://root:root@127.0.0.1/cakephp?encoding=utf8'; fi
+ if [[ ${{ matrix.db-type }} == 'pgsql' ]]; then export DB_URL='postgres://postgres:postgres@127.0.0.1/postgres'; fi
+ if [[ ${{ matrix.php-version }} == '8.1' ]]; then
+ vendor/bin/phpunit --coverage-clover=coverage.xml
+ else
+ vendor/bin/phpunit
+ fi
+
+ - name: Validate prefer-lowest
+ if: matrix.prefer-lowest == 'prefer-lowest'
+ run: vendor/bin/validate-prefer-lowest -m
+
+# - name: Upload coverage reports to Codecov
+# if: success() && matrix.php-version == '8.1'
+# uses: codecov/codecov-action@v4
+# with:
+# token: ${{ secrets.CODECOV_TOKEN }}
+
+ validation:
+ name: Coding Standard & Static Analysis
+ runs-on: ubuntu-22.04
+
+ steps:
+ - uses: actions/checkout@v4
+
+ - name: Setup PHP
+ uses: shivammathur/setup-php@v2
+ with:
+ php-version: '8.1'
+ extensions: mbstring, intl
+ coverage: none
+
+ - name: Get composer cache directory
+ id: composercache
+ run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
+
+ - name: Cache dependencies
+ uses: actions/cache@v4
+ with:
+ path: ${{ steps.composercache.outputs.dir }}
+ key: ${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }}
+
+ - name: Composer phpstan setup
+ run: composer stan-setup
+
+ - name: Run phpstan
+ run: vendor/bin/phpstan analyse --error-format=github
+
+ - name: Run phpcs
+ run: composer cs-check
\ No newline at end of file
diff --git a/README.md b/README.md
index afd50e3..9d73642 100644
--- a/README.md
+++ b/README.md
@@ -7,6 +7,6 @@ You can install this plugin into your CakePHP application using [composer](https
The recommended way to install composer packages is:
```
-composer require hi-powereddev/cake-contact-us
+composer require hi-powered-dev/cake-contact-us
```
diff --git a/composer.json b/composer.json
index 16e4384..c2d719c 100644
--- a/composer.json
+++ b/composer.json
@@ -4,7 +4,7 @@
"type": "cakephp-plugin",
"license": "MIT",
"require": {
- "php": ">=8.1",
+ "php": ">=8.2",
"cakephp/cakephp": "^5.0.1"
},
"require-dev": {
diff --git a/config/Migrations/20250103091420_CreateContactUsFormSubmissions.php b/config/Migrations/20250103091420_CreateContactUsFormSubmissions.php
index e9bec0f..1a90eb7 100644
--- a/config/Migrations/20250103091420_CreateContactUsFormSubmissions.php
+++ b/config/Migrations/20250103091420_CreateContactUsFormSubmissions.php
@@ -28,17 +28,22 @@ class CreateContactUsFormSubmissions extends AbstractMigration {
'limit' => 45,
'null' => true,
]);
- $table->addColumn('name', 'string', [
+ $table->addColumn('first_name', 'string', [
'default' => null,
'limit' => 255,
- 'null' => false,
+ 'null' => true,
+ ]);
+ $table->addColumn('last_name', 'string', [
+ 'default' => null,
+ 'limit' => 255,
+ 'null' => true,
]);
$table->addColumn('email', 'string', [
'default' => null,
'limit' => 255,
'null' => true,
]);
- $table->addColumn('subject', 'string', [
+ $table->addColumn('contact_subject', 'string', [
'default' => null,
'limit' => 255,
'null' => true,
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index d4da298..69da4f4 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -8,11 +8,12 @@
+
-
+
tests/TestCase/
diff --git a/src/Controller/Component/ContactUsComponent.php b/src/Controller/Component/ContactUsComponent.php
index 2c9cea5..ba5b5dc 100644
--- a/src/Controller/Component/ContactUsComponent.php
+++ b/src/Controller/Component/ContactUsComponent.php
@@ -90,7 +90,6 @@ class ContactUsComponent extends Component {
'contactUsFormSubmission' => $contactUsFormSubmission,
], $this->getController());
$result = $event->getResult();
-
Log::debug(print_r('$result', true));
Log::debug(print_r($result, true));
if ($result instanceof EntityInterface) {
@@ -104,15 +103,13 @@ class ContactUsComponent extends Component {
if ($contactUsFormSubmissionSaved) {
return $this->_afterFormSaved($contactUsFormSubmissionSaved);
}
-
// @TODO contact us form submission failed - handle here
}
if ($event->isStopped()) {
return $this->getController()->redirect($event->getResult());
}
-
- if (!$this->getController()->getRequest()->is('post')) {
+ if (!$postData) {
return;
}
diff --git a/src/Mailer/ContactUsFormSubmissionsMailer.php b/src/Mailer/ContactUsFormSubmissionsMailer.php
index f80d85e..4ff4f35 100644
--- a/src/Mailer/ContactUsFormSubmissionsMailer.php
+++ b/src/Mailer/ContactUsFormSubmissionsMailer.php
@@ -45,7 +45,7 @@ class ContactUsFormSubmissionsMailer extends Mailer {
*/
protected function backend(ContactUsFormSubmission $contactUsFormSubmission, array $options = []) {
$subject = __d('cake_contact_us', 'Contact Us Form Submitted');
- $name = isset($contactUsFormSubmission->name) ? ' by ' . $contactUsFormSubmission->name : '';
+ $name = isset($contactUsFormSubmission->full_name) ? ' by ' . $contactUsFormSubmission->full_name : '';
$to = Configure::readOrFail('ContactUs.email.backend.to');
$cc = Configure::read('ContactUs.email.backend.cc', []);
@@ -62,7 +62,7 @@ class ContactUsFormSubmissionsMailer extends Mailer {
if ($cc) {
$cc = !is_array($cc) ? [$cc] : $cc;
- $this->setCc($to);
+ $this->setCc($cc);
}
if ($bcc) {
$bcc = !is_array($bcc) ? [$bcc] : $bcc;
diff --git a/src/Model/Entity/ContactUsFormSubmission.php b/src/Model/Entity/ContactUsFormSubmission.php
index 9a72bca..0260521 100644
--- a/src/Model/Entity/ContactUsFormSubmission.php
+++ b/src/Model/Entity/ContactUsFormSubmission.php
@@ -11,9 +11,10 @@ use Cake\ORM\Entity;
* @property string $id
* @property \Cake\I18n\DateTime $submitted_at
* @property string $client_ip
- * @property string $name
+ * @property string|null $first_name
+ * @property string|null $last_name
* @property string|null $email
- * @property string|null $subject
+ * @property string|null $contact_subject
* @property string $message
* @property \Cake\I18n\DateTime|null $confirm_email_sent
* @property \Cake\I18n\DateTime|null $backend_email_sent
@@ -32,12 +33,20 @@ class ContactUsFormSubmission extends Entity {
protected array $_accessible = [
'submitted_at' => true,
'client_ip' => true,
- 'name' => true,
+ 'first_name' => true,
+ 'last_name' => true,
'email' => true,
- 'subject' => true,
+ 'contact_subject' => true,
'message' => true,
'confirm_email_sent' => true,
'backend_email_sent' => true,
];
+ /**
+ * @return string
+ */
+ protected function _getFullName(): string {
+ return $this->get('first_name') . ' ' . $this->get('last_name');
+ }
+
}
diff --git a/src/Model/Table/ContactUsFormSubmissionsTable.php b/src/Model/Table/ContactUsFormSubmissionsTable.php
index 93f7be2..6b930c5 100644
--- a/src/Model/Table/ContactUsFormSubmissionsTable.php
+++ b/src/Model/Table/ContactUsFormSubmissionsTable.php
@@ -46,7 +46,7 @@ class ContactUsFormSubmissionsTable extends Table {
parent::initialize($config);
$this->setTable('contact_us_form_submissions');
- $this->setDisplayField('name');
+ $this->setDisplayField('email');
$this->setPrimaryKey('id');
}
@@ -69,10 +69,15 @@ class ContactUsFormSubmissionsTable extends Table {
->allowEmptyString('client_ip');
$validator
- ->scalar('name')
- ->maxLength('name', 255)
- ->requirePresence('name', 'create')
- ->notEmptyString('name');
+ ->scalar('first_name')
+ ->maxLength('first_name', 255)
+ ->requirePresence('first_name', 'create')
+ ->notEmptyString('first_name');
+
+ $validator
+ ->scalar('last_name')
+ ->maxLength('last_name', 255)
+ ->allowEmptyString('last_name');
// email
$validator->email('email');
@@ -82,14 +87,14 @@ class ContactUsFormSubmissionsTable extends Table {
$validator->allowEmptyString('email');
}
- // subject
+ // contact_subject
$validator
- ->scalar('subject')
- ->maxLength('subject', 255);
+ ->scalar('contact_subject')
+ ->maxLength('contact_subject', 255);
if ($fields['subject'] ?? false) {
- $validator->notEmptyString('subject');
+ $validator->notEmptyString('contact_subject');
} else {
- $validator->allowEmptyString('subject');
+ $validator->allowEmptyString('contact_subject');
}
$validator
diff --git a/templates/Admin/ContactUsFormSubmissions/edit.php b/templates/Admin/ContactUsFormSubmissions/edit.php
index f288a22..c289c1c 100644
--- a/templates/Admin/ContactUsFormSubmissions/edit.php
+++ b/templates/Admin/ContactUsFormSubmissions/edit.php
@@ -24,9 +24,10 @@
Form->control('submitted_at');
echo $this->Form->control('client_ip');
- echo $this->Form->control('name');
+ echo $this->Form->control('first_name');
+ echo $this->Form->control('last_name');
echo $this->Form->control('email');
- echo $this->Form->control('subject');
+ echo $this->Form->control('contact_subject');
echo $this->Form->control('message');
echo $this->Form->control('confirm_email_sent', ['empty' => true]);
echo $this->Form->control('backend_email_sent', ['empty' => true]);
diff --git a/templates/Admin/ContactUsFormSubmissions/index.php b/templates/Admin/ContactUsFormSubmissions/index.php
index 3606b9a..23a49ad 100644
--- a/templates/Admin/ContactUsFormSubmissions/index.php
+++ b/templates/Admin/ContactUsFormSubmissions/index.php
@@ -13,9 +13,9 @@
= $this->Paginator->sort('id') ?> |
= $this->Paginator->sort('submitted_at') ?> |
= $this->Paginator->sort('client_ip') ?> |
- = $this->Paginator->sort('name') ?> |
+ = $this->Paginator->sort('first_name') . ' ' . $this->Paginator->sort('last_name'); ?> |
= $this->Paginator->sort('email') ?> |
- = $this->Paginator->sort('subject') ?> |
+ = $this->Paginator->sort('contact_subject') ?> |
= $this->Paginator->sort('confirm_email_sent') ?> |
= $this->Paginator->sort('backend_email_sent') ?> |
= __('Actions') ?> |
@@ -27,9 +27,9 @@
= h($contactUsFormSubmission->id) ?> |
= h($contactUsFormSubmission->submitted_at) ?> |
= h($contactUsFormSubmission->client_ip) ?> |
- = h($contactUsFormSubmission->name) ?> |
+ = h($contactUsFormSubmission->full_name) ?> |
= h($contactUsFormSubmission->email) ?> |
- = h($contactUsFormSubmission->subject) ?> |
+ = h($contactUsFormSubmission->contact_subject) ?> |
= h($contactUsFormSubmission->confirm_email_sent) ?> |
= h($contactUsFormSubmission->backend_email_sent) ?> |
diff --git a/templates/Admin/ContactUsFormSubmissions/view.php b/templates/Admin/ContactUsFormSubmissions/view.php
index f6815c9..206d43c 100644
--- a/templates/Admin/ContactUsFormSubmissions/view.php
+++ b/templates/Admin/ContactUsFormSubmissions/view.php
@@ -15,7 +15,7 @@
- = h($contactUsFormSubmission->name) ?>
+ = h($contactUsFormSubmission->email) ?>
| = __('Id') ?> |
@@ -27,7 +27,7 @@
| = __('Name') ?> |
- = h($contactUsFormSubmission->name) ?> |
+ = h($contactUsFormSubmission->full_name) ?> |
| = __('Email') ?> |
@@ -35,7 +35,7 @@
| = __('Subject') ?> |
- = h($contactUsFormSubmission->subject) ?> |
+ = h($contactUsFormSubmission->contact_subject) ?> |
| = __('Submitted At') ?> |
diff --git a/templates/ContactUsFormSubmissions/add.php b/templates/ContactUsFormSubmissions/add.php
index d633cee..17e8219 100644
--- a/templates/ContactUsFormSubmissions/add.php
+++ b/templates/ContactUsFormSubmissions/add.php
@@ -5,10 +5,6 @@
*/
?>
-
= $this->Form->create($contactUsFormSubmission) ?>
diff --git a/templates/element/ContactUsFormSubmissions/form.php b/templates/element/ContactUsFormSubmissions/form.php
index 8e9a642..22c779f 100644
--- a/templates/element/ContactUsFormSubmissions/form.php
+++ b/templates/element/ContactUsFormSubmissions/form.php
@@ -7,10 +7,10 @@
$fields = \Cake\Core\Configure::readOrFail('ContactUs.fields');
?>
Form->control('name');
+echo $this->Form->control('first_name');
+echo $this->Form->control('last_name');
echo isset($fields['email']) && $fields['email'] ? $this->Form->control('email', ['required' => true]) : '';
echo isset($fields['subject']) && $fields['subject'] ? $this->Form->control('subject', ['required' => true]) : '';
echo $this->Form->control('message');
echo isset($fields['captcha']) && $fields['captcha'] ? $this->Captcha->render(['placeholder' => __('Please solve the riddle')]) : '';
-
?>
diff --git a/templates/email/html/backend.php b/templates/email/html/backend.php
index 2dd8476..23fe650 100644
--- a/templates/email/html/backend.php
+++ b/templates/email/html/backend.php
@@ -11,7 +11,7 @@ use Cake\Core\Configure;
= __d('cake_contact_us', "A contact us form submission was received at {0}", $contactUsFormSubmission->submitted_at) ?>,
- = h($contactUsFormSubmission->name); ?>
+ = h($contactUsFormSubmission->full_name); ?>
email)) : ?>
@@ -20,13 +20,13 @@ use Cake\Core\Configure;
-subject)) : ?>
+contact_subject)) : ?>
= __d('cake_contact_us', 'Subject: ') ?>
- = h($contactUsFormSubmission->subject); ?>
+ = h($contactUsFormSubmission->contact_subject); ?>
= __d('cake_contact_us', 'Message: ') ?>
= h($contactUsFormSubmission->message); ?>
-
\ No newline at end of file
+
diff --git a/tests/Fixture/ContactUsFormSubmissionsFixture.php b/tests/Fixture/ContactUsFormSubmissionsFixture.php
index 9e2e53b..0d42546 100644
--- a/tests/Fixture/ContactUsFormSubmissionsFixture.php
+++ b/tests/Fixture/ContactUsFormSubmissionsFixture.php
@@ -3,13 +3,17 @@ declare(strict_types=1);
namespace CakeContactUs\Test\Fixture;
+use Cake\I18n\FrozenTime;
use Cake\TestSuite\Fixture\TestFixture;
+use Cake\Utility\Text;
/**
* ContactUsFormSubmissionsFixture
*/
class ContactUsFormSubmissionsFixture extends TestFixture {
+ public string $table = 'contact_us_form_submissions';
+
/**
* Init method
*
@@ -18,17 +22,19 @@ class ContactUsFormSubmissionsFixture extends TestFixture {
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',
+ 'id' => Text::uuid(),
+ 'submitted_at' => new FrozenTime(),
+ 'client_ip' => 'cli',
+ 'first_name' => 'test',
+ 'last_name' => 'test',
+ 'email' => 'test@test.com',
+ 'contact_subject' => 'subject',
+ 'message' => 'what are your business hours?',
+ 'confirm_email_sent' => true,
+ 'backend_email_sent' => true,
],
];
+
parent::init();
}
diff --git a/tests/TestCase/Controller/Component/ContactUsComponentTest.php b/tests/TestCase/Controller/Component/ContactUsComponentTest.php
index 4304849..2f8793b 100644
--- a/tests/TestCase/Controller/Component/ContactUsComponentTest.php
+++ b/tests/TestCase/Controller/Component/ContactUsComponentTest.php
@@ -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
*/
- 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,35 @@ 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(), [
+ '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);
+ }
+
}
diff --git a/tests/TestCase/Controller/ContactUsFormSubmissionsControllerTest.php b/tests/TestCase/Controller/ContactUsFormSubmissionsControllerTest.php
index 4fb2b04..86e0dcb 100644
--- a/tests/TestCase/Controller/ContactUsFormSubmissionsControllerTest.php
+++ b/tests/TestCase/Controller/ContactUsFormSubmissionsControllerTest.php
@@ -105,7 +105,7 @@ class ContactUsFormSubmissionsControllerTest extends TestCase {
'action' => 'add',
];
$data = [
- 'name' => 'valid name',
+ 'first_name' => 'valid name',
'email' => 'valid_email@test.com',
'message' => 'valid message goes here',
];
@@ -156,7 +156,7 @@ class ContactUsFormSubmissionsControllerTest extends TestCase {
'action' => 'add',
];
$data = [
- 'name' => 'valid name',
+ 'first_name' => 'valid name',
'email' => 'valid_email@test.com',
'message' => 'valid message goes here',
];
@@ -203,7 +203,7 @@ class ContactUsFormSubmissionsControllerTest extends TestCase {
'action' => 'add',
];
$data = [
- 'name' => 'valid name',
+ 'first_name' => 'valid name',
'email' => 'valid_email@test.com',
'message' => 'valid message goes here',
];
@@ -251,7 +251,7 @@ class ContactUsFormSubmissionsControllerTest extends TestCase {
'action' => 'add',
];
$data = [
- 'name' => 'valid name',
+ 'first_name' => 'valid name',
'email' => 'valid_email@test.com',
'message' => 'valid message goes here',
];
@@ -290,7 +290,7 @@ class ContactUsFormSubmissionsControllerTest extends TestCase {
'action' => 'add',
];
$data = [
- 'name' => 'valid name',
+ 'first_name' => 'valid name',
'email' => 'not_valid_email',
'message' => 'this is a valid message ',
];
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index aa07675..fc0e90b 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -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'],
+]);
|