diff --git a/composer.json b/composer.json
index 987605b..16e4384 100644
--- a/composer.json
+++ b/composer.json
@@ -9,7 +9,12 @@
},
"require-dev": {
"phpunit/phpunit": "^10.1",
- "cakephp/migrations": "^4.0.0"
+ "cakephp/migrations": "^4.0.0",
+ "phpstan/phpstan": "^2.1",
+ "dereuromark/composer-prefer-lowest": "^0.1.10",
+ "cakedc/cakephp-phpstan": "^4.1",
+ "dereuromark/cakephp-captcha": "^2.0",
+ "fig-r/psr2r-sniffer": "^2.7"
},
"suggest": {
"dereuromark/cakephp-captcha": "^2.0"
@@ -25,5 +30,17 @@
"Cake\\Test\\": "vendor/cakephp/cakephp/tests/",
"TestApp\\": "tests/test_app/src/"
}
+ },
+ "scripts": {
+ "cs-check": "vendor/bin/phpcs --colors --parallel=16",
+ "cs-fix": "vendor/bin/phpcbf --colors --parallel=16",
+ "lowest": "validate-prefer-lowest",
+ "lowest-setup": "composer update --prefer-lowest --prefer-stable --prefer-dist --no-interaction && cp composer.json composer.backup && composer require --dev dereuromark/composer-prefer-lowest && mv composer.backup composer.json",
+ "stan": "phpstan analyze"
+ },
+ "config": {
+ "allow-plugins": {
+ "dealerdirect/phpcodesniffer-composer-installer": false
+ }
}
}
diff --git a/config/Migrations/20250103091420_CreateContactUsFormSubmissions.php b/config/Migrations/20250103091420_CreateContactUsFormSubmissions.php
index a5f936b..e9bec0f 100644
--- a/config/Migrations/20250103091420_CreateContactUsFormSubmissions.php
+++ b/config/Migrations/20250103091420_CreateContactUsFormSubmissions.php
@@ -3,59 +3,59 @@ declare(strict_types=1);
use Migrations\AbstractMigration;
-class CreateContactUsFormSubmissions extends AbstractMigration
-{
- /**
+class CreateContactUsFormSubmissions extends AbstractMigration {
+
+ /**
* Change 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 change(): void
- {
- $table = $this->table('contact_us_form_submissions', ['id' => false, 'primary_key' => ['id']]);
+ public function change(): void {
+ $table = $this->table('contact_us_form_submissions', ['id' => false, 'primary_key' => ['id']]);
+
+ $table->addColumn('id', 'uuid', [
+ 'default' => null,
+ 'null' => false,
+ ]);
+ $table->addColumn('submitted_at', 'datetime', [
+ 'default' => null,
+ 'null' => false,
+ ]);
+ $table->addColumn('client_ip', 'string', [
+ 'default' => null,
+ 'limit' => 45,
+ 'null' => true,
+ ]);
+ $table->addColumn('name', 'string', [
+ 'default' => null,
+ 'limit' => 255,
+ 'null' => false,
+ ]);
+ $table->addColumn('email', 'string', [
+ 'default' => null,
+ 'limit' => 255,
+ 'null' => true,
+ ]);
+ $table->addColumn('subject', 'string', [
+ 'default' => null,
+ 'limit' => 255,
+ 'null' => true,
+ ]);
+ $table->addColumn('message', 'text', [
+ 'default' => null,
+ 'null' => false,
+ ]);
+ $table->addColumn('confirm_email_sent', 'datetime', [
+ 'default' => null,
+ 'null' => true,
+ ]);
+ $table->addColumn('backend_email_sent', 'datetime', [
+ 'default' => null,
+ 'null' => true,
+ ]);
+ $table->create();
+ }
- $table->addColumn('id', 'uuid', [
- 'default' => null,
- 'null' => false,
- ]);
- $table->addColumn('submitted_at', 'datetime', [
- 'default' => null,
- 'null' => false,
- ]);
- $table->addColumn('client_ip', 'string', [
- 'default' => null,
- 'limit' => 45,
- 'null' => true,
- ]);
- $table->addColumn('name', 'string', [
- 'default' => null,
- 'limit' => 255,
- 'null' => false,
- ]);
- $table->addColumn('email', 'string', [
- 'default' => null,
- 'limit' => 255,
- 'null' => true,
- ]);
- $table->addColumn('subject', 'string', [
- 'default' => null,
- 'limit' => 255,
- 'null' => true,
- ]);
- $table->addColumn('message', 'text', [
- 'default' => null,
- 'null' => false,
- ]);
- $table->addColumn('confirm_email_sent', 'datetime', [
- 'default' => null,
- 'null' => true,
- ]);
- $table->addColumn('backend_email_sent', 'datetime', [
- 'default' => null,
- 'null' => true,
- ]);
- $table->create();
- }
}
diff --git a/config/app.example.php b/config/app.example.php
index 6333e65..cbcf10d 100644
--- a/config/app.example.php
+++ b/config/app.example.php
@@ -3,28 +3,28 @@
return [
'ContactUs' => [
- 'fields' => [
- 'subject' => true,
- 'email' => true,
- 'captcha' => true,
- ],
- 'clientIpHeader' => '',
- 'email' => [
- 'mailerClass' => 'CakeContactUs.ContactUsFormSubmissions',
- 'confirmation' => true, // true or false
- 'backend' => [ // array with enabled and the to/cc/bcc/ fields as strings or arrays
- 'enabled' => true,
- 'to' => 'bshipley@hipowered.dev',
- 'cc' => '', // email string or array of emails
- 'bcc' => '', // email string or array of emails
- ],
- ],
- 'addIdToRedirect' => true,
- 'redirectUrl' => [
- 'prefix' => 'Admin',
- 'plugin' => 'CakeContactUs',
- 'controller' => 'ContactUsFormSubmissions',
- 'action' => 'view',
- ],
+ 'fields' => [
+ 'subject' => true,
+ 'email' => true,
+ 'captcha' => true,
+ ],
+ 'clientIpHeader' => '',
+ 'email' => [
+ 'mailerClass' => 'CakeContactUs.ContactUsFormSubmissions',
+ 'confirmation' => true, // true or false
+ 'backend' => [ // array with enabled and the to/cc/bcc/ fields as strings or arrays
+ 'enabled' => true,
+ 'to' => 'bshipley@hipowered.dev',
+ 'cc' => '', // email string or array of emails
+ 'bcc' => '', // email string or array of emails
+ ],
+ ],
+ 'addIdToRedirect' => true,
+ 'redirectUrl' => [
+ 'prefix' => 'Admin',
+ 'plugin' => 'CakeContactUs',
+ 'controller' => 'ContactUsFormSubmissions',
+ 'action' => 'view',
+ ],
],
];
diff --git a/phpcs.xml b/phpcs.xml
new file mode 100644
index 0000000..689bfe3
--- /dev/null
+++ b/phpcs.xml
@@ -0,0 +1,21 @@
+
+
+
+
+ src/
+ config/
+ tests/
+
+ /tests/test_files/
+ /tests/test_app/
+
+
+
+
+ */config/Migrations/*
+
+
+ */config/Migrations/*
+
+
+
diff --git a/phpstan.neon b/phpstan.neon
new file mode 100644
index 0000000..b251d7d
--- /dev/null
+++ b/phpstan.neon
@@ -0,0 +1,10 @@
+includes:
+ - vendor/cakedc/cakephp-phpstan/extension.neon
+
+parameters:
+ level: 4
+ paths:
+ - src
+ bootstrapFiles:
+ - tests/bootstrap.php
+ treatPhpDocTypesAsCertain: false
diff --git a/src/CakeContactUsPlugin.php b/src/CakeContactUsPlugin.php
index 13a7214..07e6b41 100644
--- a/src/CakeContactUsPlugin.php
+++ b/src/CakeContactUsPlugin.php
@@ -13,12 +13,23 @@ use Cake\Routing\RouteBuilder;
/**
* Plugin for CakeContactUs
*/
-class CakeContactUsPlugin extends BasePlugin
-{
- public const EVENT_BEFORE_CONTACT_US_FORM_SAVED = 'ContactUs.Global.beforeRegister';
- public const EVENT_AFTER_CONTACT_US_FORM_SAVED = 'ContactUs.Global.afterRegister';
- public const CAKE_CONTACT_US_MYSQL_DATETIME = 'Y-m-d H:i:s';
- /**
+class CakeContactUsPlugin extends BasePlugin {
+
+ /**
+ * @var string
+ */
+ public const EVENT_BEFORE_CONTACT_US_FORM_SAVED = 'ContactUs.Global.beforeRegister';
+
+ /**
+ * @var string
+ */
+ public const EVENT_AFTER_CONTACT_US_FORM_SAVED = 'ContactUs.Global.afterRegister';
+
+ /**
+ * @var string
+ */
+ public const CAKE_CONTACT_US_MYSQL_DATETIME = 'Y-m-d H:i:s';
+ /**
* Load all the plugin configuration and bootstrap logic.
*
* The host application is provided as an argument. This allows you to load
@@ -27,11 +38,10 @@ class CakeContactUsPlugin extends BasePlugin
* @param \Cake\Core\PluginApplicationInterface $app The host application
* @return void
*/
- public function bootstrap(PluginApplicationInterface $app): void
- {
- }
+ public function bootstrap(PluginApplicationInterface $app): void {
+ }
- /**
+ /**
* Add routes for the plugin.
*
* If your plugin has many routes and you would like to isolate them into a separate file,
@@ -40,59 +50,56 @@ class CakeContactUsPlugin extends BasePlugin
* @param \Cake\Routing\RouteBuilder $routes The route builder to update.
* @return void
*/
- public function routes(RouteBuilder $routes): void
- {
- $routes->prefix('Admin', function (RouteBuilder $routes): void {
- $routes->plugin('CakeContactUs', function (RouteBuilder $routes): void {
- $routes->connect('/', ['controller' => 'ContactUsFormSubmissions', 'action' => 'index']);
+ public function routes(RouteBuilder $routes): void {
+ $routes->prefix('Admin', function (RouteBuilder $routes): void {
+ $routes->plugin('CakeContactUs', function (RouteBuilder $routes): void {
+ $routes->connect('/', ['controller' => 'ContactUsFormSubmissions', 'action' => 'index']);
- $routes->fallbacks();
- });
- });
- $routes->plugin('CakeContactUs', ['path' => '/contact-us'], function (RouteBuilder $routes): void {
- $routes->connect('/', ['controller' => 'ContactUsFormSubmissions', 'action' => 'add']);
- });
+ $routes->fallbacks();
+ });
+ });
+ $routes->plugin('CakeContactUs', ['path' => '/contact-us'], function (RouteBuilder $routes): void {
+ $routes->connect('/', ['controller' => 'ContactUsFormSubmissions', 'action' => 'add']);
+ });
- parent::routes($routes);
- }
+ parent::routes($routes);
+ }
- /**
+ /**
* Add middleware for the plugin.
*
* @param \Cake\Http\MiddlewareQueue $middlewareQueue The middleware queue to update.
* @return \Cake\Http\MiddlewareQueue
*/
- public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue
- {
- // Add your middlewares here
+ public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue {
+ // Add your middlewares here
- return $middlewareQueue;
- }
+ return $middlewareQueue;
+ }
- /**
+ /**
* Add commands for the plugin.
*
* @param \Cake\Console\CommandCollection $commands The command collection to update.
* @return \Cake\Console\CommandCollection
*/
- public function console(CommandCollection $commands): CommandCollection
- {
- // Add your commands here
+ public function console(CommandCollection $commands): CommandCollection {
+ // Add your commands here
- $commands = parent::console($commands);
+ $commands = parent::console($commands);
- return $commands;
- }
+ return $commands;
+ }
- /**
+ /**
* Register application container services.
*
+ * @link https://book.cakephp.org/4/en/development/dependency-injection.html#dependency-injection
* @param \Cake\Core\ContainerInterface $container The Container to update.
* @return void
- * @link https://book.cakephp.org/4/en/development/dependency-injection.html#dependency-injection
*/
- public function services(ContainerInterface $container): void
- {
- // Add your services here
- }
+ public function services(ContainerInterface $container): void {
+ // Add your services here
+ }
+
}
diff --git a/src/Controller/Admin/ContactUsFormSubmissionsController.php b/src/Controller/Admin/ContactUsFormSubmissionsController.php
index 6a94f51..b2c2989 100644
--- a/src/Controller/Admin/ContactUsFormSubmissionsController.php
+++ b/src/Controller/Admin/ContactUsFormSubmissionsController.php
@@ -10,79 +10,74 @@ use App\Controller\AppController;
*
* @property \CakeContactUs\Model\Table\ContactUsFormSubmissionsTable $ContactUsFormSubmissions
*/
-class ContactUsFormSubmissionsController extends AppController
-{
- public function initialize(): void
- {
- parent::initialize(); // TODO: Change the autogenerated stub
- }
+class ContactUsFormSubmissionsController extends AppController {
- /**
+ public function initialize(): void {
+ parent::initialize(); // TODO: Change the autogenerated stub
+ }
+
+ /**
* Index method
*
* @return \Cake\Http\Response|null|void Renders view
*/
- public function index()
- {
- $query = $this->ContactUsFormSubmissions->find();
- $contactUsFormSubmissions = $this->paginate($query);
+ public function index() {
+ $query = $this->ContactUsFormSubmissions->find();
+ $contactUsFormSubmissions = $this->paginate($query);
- $this->set(compact('contactUsFormSubmissions'));
- }
+ $this->set(compact('contactUsFormSubmissions'));
+ }
- /**
+ /**
* View method
*
* @param string|null $id Contact Us Form Submission id.
- * @return \Cake\Http\Response|null|void Renders view
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
+ * @return \Cake\Http\Response|null|void Renders view
*/
- public function view($id = null)
- {
- $contactUsFormSubmission = $this->ContactUsFormSubmissions->get($id, contain: []);
- $this->set(compact('contactUsFormSubmission'));
- }
+ public function view($id = null) {
+ $contactUsFormSubmission = $this->ContactUsFormSubmissions->get($id, contain: []);
+ $this->set(compact('contactUsFormSubmission'));
+ }
-
- /**
+ /**
* Edit method
*
* @param string|null $id Contact Us Form Submission id.
- * @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
+ * @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
*/
- public function edit($id = null)
- {
- $contactUsFormSubmission = $this->ContactUsFormSubmissions->get($id, contain: []);
- if ($this->request->is(['patch', 'post', 'put'])) {
- $contactUsFormSubmission = $this->ContactUsFormSubmissions->patchEntity($contactUsFormSubmission, $this->request->getData());
- if ($this->ContactUsFormSubmissions->save($contactUsFormSubmission)) {
- $this->Flash->success(__('The contact us form submission has been saved.'));
+ public function edit($id = null) {
+ $contactUsFormSubmission = $this->ContactUsFormSubmissions->get($id, contain: []);
+ if ($this->request->is(['patch', 'post', 'put'])) {
+ $contactUsFormSubmission = $this->ContactUsFormSubmissions->patchEntity($contactUsFormSubmission, $this->request->getData());
+ if ($this->ContactUsFormSubmissions->save($contactUsFormSubmission)) {
+ $this->Flash->success(__('The contact us form submission has been saved.'));
- return $this->redirect(['action' => 'index']);
- }
- $this->Flash->error(__('The contact us form submission could not be saved. Please, try again.'));
- }
- $this->set(compact('contactUsFormSubmission'));
- }
+ return $this->redirect(['action' => 'index']);
+ }
+ $this->Flash->error(__('The contact us form submission could not be saved. Please, try again.'));
+ }
+ $this->set(compact('contactUsFormSubmission'));
+ }
- /**
+ /**
* Delete method
*
* @param string|null $id Contact Us Form Submission id.
- * @return \Cake\Http\Response|null Redirects to index.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
+ * @return \Cake\Http\Response|null Redirects to index.
*/
- public function delete($id = null)
- {
- $this->request->allowMethod(['post', 'delete']);
- $contactUsFormSubmission = $this->ContactUsFormSubmissions->get($id);
- if ($this->ContactUsFormSubmissions->delete($contactUsFormSubmission)) {
- $this->Flash->success(__('The contact us form submission has been deleted.'));
- } else {
- $this->Flash->error(__('The contact us form submission could not be deleted. Please, try again.'));
- }
+ public function delete($id = null) {
+ $this->request->allowMethod(['post', 'delete']);
+ $contactUsFormSubmission = $this->ContactUsFormSubmissions->get($id);
+ if ($this->ContactUsFormSubmissions->delete($contactUsFormSubmission)) {
+ $this->Flash->success(__('The contact us form submission has been deleted.'));
+ } else {
+ $this->Flash->error(__('The contact us form submission could not be deleted. Please, try again.'));
+ }
+
+ return $this->redirect(['action' => 'index']);
+ }
- return $this->redirect(['action' => 'index']);
- }
}
diff --git a/src/Controller/Component/ContactUsComponent.php b/src/Controller/Component/ContactUsComponent.php
index 5ecc56f..2c9cea5 100644
--- a/src/Controller/Component/ContactUsComponent.php
+++ b/src/Controller/Component/ContactUsComponent.php
@@ -4,7 +4,6 @@ declare(strict_types=1);
namespace CakeContactUs\Controller\Component;
use Cake\Controller\Component;
-use Cake\Controller\ComponentRegistry;
use Cake\Core\Configure;
use Cake\Datasource\EntityInterface;
use Cake\Http\Response;
@@ -12,158 +11,155 @@ use Cake\I18n\DateTime;
use Cake\Log\Log;
use Cake\ORM\Table;
use Cake\ORM\TableRegistry;
-use CakeContactUs\Model\Entity\ContactUsFormSubmission;
-use CakeContactUs\Model\Table\ContactUsFormSubmissionsTable;
-use Exception;
use CakeContactUs\CakeContactUsPlugin;
+use CakeContactUs\Model\Table\ContactUsFormSubmissionsTable;
/**
* ContactUs component
+ *
+ * @property \Cake\Controller\Component\FlashComponent $Flash
*/
-class ContactUsComponent extends Component
-{
- /**
- * @var ContactUsFormSubmissionsTable|Table
- */
- protected ContactUsFormSubmissionsTable|Table $ContactUsFormSubmissions;
+class ContactUsComponent extends Component {
- /**
+ /**
+ * @var \CakeContactUs\Model\Table\ContactUsFormSubmissionsTable|\Cake\ORM\Table
+ */
+ protected ContactUsFormSubmissionsTable|Table $ContactUsFormSubmissions;
+
+ /**
* Default configuration.
*
* @var array
*/
- protected array $_defaultConfig = [];
+ protected array $_defaultConfig = [];
- /**
+ /**
* @var array|string[]
*/
- protected array $components = ['Flash'];
+ protected array $components = ['Flash'];
- /**
+ /**
* @param array $config
+ * @throws \Exception
* @return void
*
- * @throws Exception
*/
- public function initialize(array $config): void
- {
- parent::initialize($config); // TODO: Change the autogenerated stub
+ public function initialize(array $config): void {
+ parent::initialize($config); // TODO: Change the autogenerated stub
- $this->ContactUsFormSubmissions = TableRegistry::getTableLocator()->get('CakeContactUs.ContactUsFormSubmissions');
+ $this->ContactUsFormSubmissions = TableRegistry::getTableLocator()->get('CakeContactUs.ContactUsFormSubmissions');
- $requireCaptcha = Configure::readOrFail('ContactUs.fields.captcha');
- $this->setConfig('redirectUrl', Configure::read('ContactUs.redirectUrl', '/'));
- $this->setConfig('addIdToRedirect', Configure::read('ContactUs.addIdToRedirect', false));
- $this->setConfig('requireEmail', Configure::readOrFail('ContactUs.fields.email'));
- $this->setConfig('requireCaptcha', $requireCaptcha);
- if ($requireCaptcha) {
+ $requireCaptcha = Configure::readOrFail('ContactUs.fields.captcha');
+ $this->setConfig('redirectUrl', Configure::read('ContactUs.redirectUrl', '/'));
+ $this->setConfig('addIdToRedirect', Configure::read('ContactUs.addIdToRedirect', false));
+ $this->setConfig('requireEmail', Configure::readOrFail('ContactUs.fields.email'));
+ $this->setConfig('requireCaptcha', $requireCaptcha);
+ if ($requireCaptcha) {
// $this->_registry->load('Captcha.Captcha');
- $this->getController()->viewBuilder()->addHelpers(['Captcha.Captcha']);
- }
- }
+ $this->getController()->viewBuilder()->addHelpers(['Captcha.Captcha']);
+ }
+ }
- /**
- * @return EntityInterface|ContactUsFormSubmission
+ /**
+ * @return \Cake\Datasource\EntityInterface|\CakeContactUs\Model\Entity\ContactUsFormSubmission
*/
- public function newContactUsForm()
- {
- if ($this->getConfig('requireCaptcha')) {
- $this->ContactUsFormSubmissions->addBehavior('Captcha.Captcha');
- }
+ public function newContactUsForm() {
+ if ($this->getConfig('requireCaptcha')) {
+ $this->ContactUsFormSubmissions->addBehavior('Captcha.Captcha');
+ }
- return $this->ContactUsFormSubmissions->newEmptyEntity();
- }
+ return $this->ContactUsFormSubmissions->newEmptyEntity();
+ }
- /**
- * @return EntityInterface|ContactUsFormSubmission
+ /**
+ * @return \Cake\Http\Response|null|void
*/
- public function processContactUsForm(EntityInterface $contactUsFormSubmission, array|null $postData)
- {
- if (!isset($postData)) {
- $postData = $this->getController()->getRequest()->getData();
- }
- $postData['client_ip'] = array_key_exists('client_ip', $postData) && $postData['client_ip'] ?
- $postData['client_ip'] :
- ($this->getConfig('clientIpHeader') ?
- $this->getController()->getRequest()->getHeaderLine($this->getConfig('clientIpHeader')) :
- $this->getController()->getRequest()->clientIp()
- );
- $postData['submitted_at'] = DateTime::now();
+ public function processContactUsForm(EntityInterface $contactUsFormSubmission, array|null $postData) {
+ if (!isset($postData)) {
+ $postData = $this->getController()->getRequest()->getData();
+ }
+ $postData['client_ip'] = array_key_exists('client_ip', $postData) && $postData['client_ip'] ?
+ $postData['client_ip'] :
+ ($this->getConfig('clientIpHeader') ?
+ $this->getController()->getRequest()->getHeaderLine($this->getConfig('clientIpHeader')) :
+ $this->getController()->getRequest()->clientIp()
+ );
+ $postData['submitted_at'] = DateTime::now();
- $event = $this->getController()->dispatchEvent(CakeContactUsPlugin::EVENT_BEFORE_CONTACT_US_FORM_SAVED, [
- 'contactUsFormSubmission' => $contactUsFormSubmission,
- ], $this->getController());
- $result = $event->getResult();
+ $event = $this->getController()->dispatchEvent(CakeContactUsPlugin::EVENT_BEFORE_CONTACT_US_FORM_SAVED, [
+ 'contactUsFormSubmission' => $contactUsFormSubmission,
+ ], $this->getController());
+ $result = $event->getResult();
- Log::debug(print_r('$result', true));
- Log::debug(print_r($result, true));
- if ($result instanceof EntityInterface) {
- $postData = $result->toArray();
- $contactUsFormSubmission = $this->ContactUsFormSubmissions->patchEntity($contactUsFormSubmission, $postData);
- if ($contactUsFormSubmission->getErrors()) {
- Log::debug(print_r('$contactUsFormSubmission->getErrors()', true));
- Log::debug(print_r($contactUsFormSubmission->getErrors(), true));
- }
- $contactUsFormSubmissionSaved = $this->ContactUsFormSubmissions->save($contactUsFormSubmission);
- if ($contactUsFormSubmissionSaved) {
- return $this->_afterFormSaved($contactUsFormSubmissionSaved);
- }
+ Log::debug(print_r('$result', true));
+ Log::debug(print_r($result, true));
+ if ($result instanceof EntityInterface) {
+ $postData = $result->toArray();
+ $contactUsFormSubmission = $this->ContactUsFormSubmissions->patchEntity($contactUsFormSubmission, $postData);
+ if ($contactUsFormSubmission->getErrors()) {
+ Log::debug(print_r('$contactUsFormSubmission->getErrors()', true));
+ Log::debug(print_r($contactUsFormSubmission->getErrors(), true));
+ }
+ $contactUsFormSubmissionSaved = $this->ContactUsFormSubmissions->save($contactUsFormSubmission);
+ if ($contactUsFormSubmissionSaved) {
+ return $this->_afterFormSaved($contactUsFormSubmissionSaved);
+ }
- // @TODO contact us form submission failed - handle here
- }
+ // @TODO contact us form submission failed - handle here
+ }
- if ($event->isStopped()) {
- return $this->getController()->redirect($event->getResult());
- }
+ if ($event->isStopped()) {
+ return $this->getController()->redirect($event->getResult());
+ }
- if (!$this->getController()->getRequest()->is('post')) {
- return;
- }
+ if (!$this->getController()->getRequest()->is('post')) {
+ return;
+ }
- $contactUsFormSubmission = $this->ContactUsFormSubmissions->patchEntity($contactUsFormSubmission, $postData);
- if ($contactUsFormSubmission->getErrors()) {
- Log::debug(print_r('$contactUsFormSubmission->getErrors()', true));
- Log::debug(print_r($contactUsFormSubmission->getErrors(), true));
- }
+ $contactUsFormSubmission = $this->ContactUsFormSubmissions->patchEntity($contactUsFormSubmission, $postData);
+ if ($contactUsFormSubmission->getErrors()) {
+ Log::debug(print_r('$contactUsFormSubmission->getErrors()', true));
+ Log::debug(print_r($contactUsFormSubmission->getErrors(), true));
+ }
+ $contactUsFormSubmissionSaved = $this->ContactUsFormSubmissions->save($contactUsFormSubmission);
- $contactUsFormSubmissionSaved = $this->ContactUsFormSubmissions->save($contactUsFormSubmission);
+ if ($contactUsFormSubmissionSaved) {
+ return $this->_afterFormSaved($contactUsFormSubmissionSaved);
+ }
+ $message = __d('cake_contact_us', 'Something doesn\'t look quite right. Please try again.');
- if ($contactUsFormSubmissionSaved) {
- return $this->_afterFormSaved($contactUsFormSubmissionSaved);
- }
- $message = __d('cake_contact_us', 'Something doesn\'t look quite right. Please try again.');
+ $this->Flash->error($message);
- $this->Flash->error($message);
+ // @TODO contact us form submission failed - handle here
+ $this->getController()->set(['contactUsFormSubmission' => $contactUsFormSubmission]);
+ }
- // @TODO contact us form submission failed - handle here
- $this->getController()->set(['contactUsFormSubmission' => $contactUsFormSubmission]);
- }
-
- /**
+ /**
* Prepare flash messages after registration, and dispatch afterRegister event
*
- * @param \Cake\Datasource\EntityInterface|ContactUsFormSubmission $contactUsFormSubmissionSaved Contact us form submission entity
+ * @param \Cake\Datasource\EntityInterface|\CakeContactUs\Model\Entity\ContactUsFormSubmission $contactUsFormSubmissionSaved Contact us form submission entity
* @return \Cake\Http\Response
*/
- protected function _afterFormSaved(EntityInterface $contactUsFormSubmissionSaved)
- {
- $message = __d('cake_contact_us', 'Message received, thank you. We will be in touch soon.');
- $event = $this->getController()->dispatchEvent(CakeContactUsPlugin::EVENT_AFTER_CONTACT_US_FORM_SAVED, [
- 'contactUsFormSubmission' => $contactUsFormSubmissionSaved,
- ], $this->getController());
- $result = $event->getResult();
- if ($result instanceof Response) {
- return $result;
- }
- $this->Flash->success($message);
+ protected function _afterFormSaved(EntityInterface $contactUsFormSubmissionSaved) {
+ $message = __d('cake_contact_us', 'Message received, thank you. We will be in touch soon.');
+ $event = $this->getController()->dispatchEvent(CakeContactUsPlugin::EVENT_AFTER_CONTACT_US_FORM_SAVED, [
+ 'contactUsFormSubmission' => $contactUsFormSubmissionSaved,
+ ], $this->getController());
+ $result = $event->getResult();
+ if ($result instanceof Response) {
+ return $result;
+ }
+ $this->Flash->success($message);
+
+ $redirectUrl = $this->getConfig('redirectUrl');
+ Log::debug(print_r('$contactUsFormSubmissionSaved after save', true));
+ Log::debug(print_r($contactUsFormSubmissionSaved, true));
+ if ($this->getConfig('addIdToRedirect')) {
+ $redirectUrl[] = $contactUsFormSubmissionSaved->get($this->ContactUsFormSubmissions->getPrimaryKey());
+ }
+
+ return $this->getController()->redirect($redirectUrl);
+ }
- $redirectUrl = $this->getConfig('redirectUrl');
- Log::debug(print_r('$contactUsFormSubmissionSaved after save', true));
- Log::debug(print_r($contactUsFormSubmissionSaved, true));
- if ($this->getConfig('addIdToRedirect')) {
- $redirectUrl[] = $contactUsFormSubmissionSaved->get($this->ContactUsFormSubmissions->getPrimaryKey());
- }
- return $this->getController()->redirect($redirectUrl);
- }
}
diff --git a/src/Controller/ContactUsFormSubmissionsController.php b/src/Controller/ContactUsFormSubmissionsController.php
index 29cebf4..4e516f3 100644
--- a/src/Controller/ContactUsFormSubmissionsController.php
+++ b/src/Controller/ContactUsFormSubmissionsController.php
@@ -8,27 +8,27 @@ use App\Controller\AppController;
/**
* ContactUsFormSubmissions Controller
*
+ * @property \CakeContactUs\Controller\Component\ContactUsComponent $ContactUs
* @property \CakeContactUs\Model\Table\ContactUsFormSubmissionsTable $ContactUsFormSubmissions
*/
-class ContactUsFormSubmissionsController extends AppController
-{
- public function initialize(): void
- {
- parent::initialize(); // TODO: Change the autogenerated stub
- $this->loadComponent('CakeContactUs.ContactUs');
- }
+class ContactUsFormSubmissionsController extends AppController {
- /**
+ public function initialize(): void {
+ parent::initialize(); // TODO: Change the autogenerated stub
+ $this->loadComponent('CakeContactUs.ContactUs');
+ }
+
+ /**
* Add method
*
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
*/
- public function add()
- {
- $contactUsFormSubmission = $this->ContactUs->newContactUsForm();
- if ($this->request->is('post')) {
- return $this->ContactUs->processContactUsForm($contactUsFormSubmission, $this->request->getData());
- }
- $this->set(compact('contactUsFormSubmission'));
- }
+ public function add() {
+ $contactUsFormSubmission = $this->ContactUs->newContactUsForm();
+ if ($this->request->is('post')) {
+ return $this->ContactUs->processContactUsForm($contactUsFormSubmission, $this->request->getData());
+ }
+ $this->set(compact('contactUsFormSubmission'));
+ }
+
}
diff --git a/src/Mailer/ContactUsFormSubmissionsMailer.php b/src/Mailer/ContactUsFormSubmissionsMailer.php
index 9187278..f80d85e 100644
--- a/src/Mailer/ContactUsFormSubmissionsMailer.php
+++ b/src/Mailer/ContactUsFormSubmissionsMailer.php
@@ -4,72 +4,73 @@ declare(strict_types=1);
namespace CakeContactUs\Mailer;
use Cake\Core\Configure;
-use Cake\Datasource\EntityInterface;
use Cake\Mailer\Mailer;
use Cake\Mailer\Message;
+use CakeContactUs\Model\Entity\ContactUsFormSubmission;
/**
* User Mailer
*/
-class ContactUsFormSubmissionsMailer extends Mailer
-{
- /**
- * Send the templated email to the user
+class ContactUsFormSubmissionsMailer extends Mailer {
+
+ /**
+ * Send the confirmation email to the user
*
- * @param \Cake\Datasource\EntityInterface $user User entity
+ * @param \CakeContactUs\Model\Entity\ContactUsFormSubmission $contactUsFormSubmission contact us form submission entity
+ * @param array $options
* @return void
*/
- protected function confirmation(EntityInterface $contactUsFormSubmission, array $options = [])
- {
- $name = isset($contactUsFormSubmission['name']) ? $contactUsFormSubmission['name'] . ', ' : '';
- $subject = __d('cake_contact_us', 'We have received your message');
+ protected function confirmation(ContactUsFormSubmission $contactUsFormSubmission, array $options = []) {
+ $name = isset($contactUsFormSubmission->name) ? $contactUsFormSubmission->name . ', ' : '';
+ $subject = __d('cake_contact_us', 'We have received your message');
- $this
- ->setTo($contactUsFormSubmission['email'])
- ->setSubject($name . $subject)
- ->setEmailFormat(Message::MESSAGE_BOTH)
- ->setViewVars([
- 'contactUsFormSubmission' => $contactUsFormSubmission,
- ]);
+ $this
+ ->setTo($contactUsFormSubmission->email)
+ ->setSubject($name . $subject)
+ ->setEmailFormat(Message::MESSAGE_BOTH)
+ ->setViewVars([
+ 'contactUsFormSubmission' => $contactUsFormSubmission,
+ ]);
- $this->viewBuilder()
- ->setTemplate('CakeContactUs.confirmation');
- }
+ $this->viewBuilder()
+ ->setTemplate('CakeContactUs.confirmation');
+ }
- /**
+ /**
* Send to backoffice to take action
*
- * @param \Cake\Datasource\EntityInterface $user User entity
+ * @param \CakeContactUs\Model\Entity\ContactUsFormSubmission $contactUsFormSubmission contact us form submission entity
+ * @param array $options
* @return void
*/
- protected function backend(EntityInterface $contactUsFormSubmission, array $options = [])
- {
- $subject = __d('cake_contact_us', 'Contact Us Form Submitted');
- $name = isset($contactUsFormSubmission['name']) ? ' by ' . $contactUsFormSubmission['name'] : '';
+ protected function backend(ContactUsFormSubmission $contactUsFormSubmission, array $options = []) {
+ $subject = __d('cake_contact_us', 'Contact Us Form Submitted');
+ $name = isset($contactUsFormSubmission->name) ? ' by ' . $contactUsFormSubmission->name : '';
- $to = Configure::readOrFail('ContactUs.email.backend.to');
- $cc = Configure::read('ContactUs.email.backend.cc', []);
- $bcc = Configure::read('ContactUs.email.backend.bcc', []);
- $to = !is_array($to) ? [$to] : $to;
+ $to = Configure::readOrFail('ContactUs.email.backend.to');
+ $cc = Configure::read('ContactUs.email.backend.cc', []);
+ $bcc = Configure::read('ContactUs.email.backend.bcc', []);
+ $to = !is_array($to) ? [$to] : $to;
- $this
- ->setTo($to)
- ->setSubject($subject . $name)
- ->setEmailFormat(Message::MESSAGE_BOTH)
- ->setViewVars([
- 'contactUsFormSubmission' => $contactUsFormSubmission,
- ]);
+ $this
+ ->setTo($to)
+ ->setSubject($subject . $name)
+ ->setEmailFormat(Message::MESSAGE_BOTH)
+ ->setViewVars([
+ 'contactUsFormSubmission' => $contactUsFormSubmission,
+ ]);
- if ($cc) {
- $cc = !is_array($cc) ? [$cc] : $cc;
- $this->setCc($to);
- }
- if ($bcc) {
- $bcc = !is_array($bcc) ? [$bcc] : $bcc;
- $this->setBcc($bcc);
- }
+ if ($cc) {
+ $cc = !is_array($cc) ? [$cc] : $cc;
+ $this->setCc($to);
+ }
+ if ($bcc) {
+ $bcc = !is_array($bcc) ? [$bcc] : $bcc;
+ $this->setBcc($bcc);
+ }
+
+ $this->viewBuilder()
+ ->setTemplate('CakeContactUs.backend');
+ }
- $this->viewBuilder()
- ->setTemplate('CakeContactUs.backend');
- }
}
diff --git a/src/Model/Entity/ContactUsFormSubmission.php b/src/Model/Entity/ContactUsFormSubmission.php
index 3012554..9a72bca 100644
--- a/src/Model/Entity/ContactUsFormSubmission.php
+++ b/src/Model/Entity/ContactUsFormSubmission.php
@@ -18,9 +18,9 @@ use Cake\ORM\Entity;
* @property \Cake\I18n\DateTime|null $confirm_email_sent
* @property \Cake\I18n\DateTime|null $backend_email_sent
*/
-class ContactUsFormSubmission extends Entity
-{
- /**
+class ContactUsFormSubmission extends Entity {
+
+ /**
* Fields that can be mass assigned using newEntity() or patchEntity().
*
* Note that when '*' is set to true, this allows all unspecified fields to
@@ -29,14 +29,15 @@ class ContactUsFormSubmission extends Entity
*
* @var array
*/
- protected array $_accessible = [
- 'submitted_at' => true,
- 'client_ip' => true,
- 'name' => true,
- 'email' => true,
- 'subject' => true,
- 'message' => true,
- 'confirm_email_sent' => true,
- 'backend_email_sent' => true,
- ];
+ protected array $_accessible = [
+ 'submitted_at' => true,
+ 'client_ip' => true,
+ 'name' => true,
+ 'email' => true,
+ 'subject' => true,
+ 'message' => true,
+ 'confirm_email_sent' => true,
+ 'backend_email_sent' => true,
+ ];
+
}
diff --git a/src/Model/Table/ContactUsFormSubmissionsTable.php b/src/Model/Table/ContactUsFormSubmissionsTable.php
index 41490ad..93f7be2 100644
--- a/src/Model/Table/ContactUsFormSubmissionsTable.php
+++ b/src/Model/Table/ContactUsFormSubmissionsTable.php
@@ -3,151 +3,144 @@ declare(strict_types=1);
namespace CakeContactUs\Model\Table;
+use ArrayObject;
use Cake\Core\Configure;
use Cake\Core\Exception\CakeException;
use Cake\Datasource\EntityInterface;
-use Cake\Datasource\ResultSetInterface;
use Cake\Event\EventInterface;
use Cake\I18n\DateTime;
-use Cake\Log\Log;
use Cake\Mailer\MailerAwareTrait;
-use Cake\ORM\Query\SelectQuery;
-use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
use CakeContactUs\CakeContactUsPlugin;
use CakeContactUs\Model\Entity\ContactUsFormSubmission;
-use Closure;
-use Psr\SimpleCache\CacheInterface;
/**
* ContactUsFormSubmissions Model
*
- * @method ContactUsFormSubmission newEmptyEntity()
- * @method ContactUsFormSubmission newEntity(array $data, array $options = [])
+ * @method \CakeContactUs\Model\Entity\ContactUsFormSubmission newEmptyEntity()
+ * @method \CakeContactUs\Model\Entity\ContactUsFormSubmission newEntity(array $data, array $options = [])
* @method array newEntities(array $data, array $options = [])
- * @method ContactUsFormSubmission get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
- * @method ContactUsFormSubmission findOrCreate($search, ?callable $callback = null, array $options = [])
- * @method ContactUsFormSubmission patchEntity(EntityInterface $entity, array $data, array $options = [])
+ * @method \CakeContactUs\Model\Entity\ContactUsFormSubmission get(mixed $primaryKey, array|string $finder = 'all', \Psr\SimpleCache\CacheInterface|string|null $cache = null, \Closure|string|null $cacheKey = null, mixed ...$args)
+ * @method \CakeContactUs\Model\Entity\ContactUsFormSubmission findOrCreate($search, ?callable $callback = null, array $options = [])
+ * @method \CakeContactUs\Model\Entity\ContactUsFormSubmission patchEntity(EntityInterface $entity, array $data, array $options = [])
* @method array patchEntities(iterable $entities, array $data, array $options = [])
* @method ContactUsFormSubmission|false save(EntityInterface $entity, array $options = [])
- * @method ContactUsFormSubmission saveOrFail(EntityInterface $entity, array $options = [])
- * @method iterable|ResultSetInterface|false saveMany(iterable $entities, array $options = [])
- * @method iterable|ResultSetInterface saveManyOrFail(iterable $entities, array $options = [])
- * @method iterable|ResultSetInterface|false deleteMany(iterable $entities, array $options = [])
- * @method iterable|ResultSetInterface deleteManyOrFail(iterable $entities, array $options = [])
+ * @method \CakeContactUs\Model\Entity\ContactUsFormSubmission saveOrFail(\Cake\Datasource\EntityInterface $entity, array $options = [])
+ * @method iterable|\Cake\Datasource\ResultSetInterface|false saveMany(iterable $entities, array $options = [])
+ * @method iterable|\Cake\Datasource\ResultSetInterface saveManyOrFail(iterable $entities, array $options = [])
+ * @method iterable|\Cake\Datasource\ResultSetInterface|false deleteMany(iterable $entities, array $options = [])
+ * @method iterable|\Cake\Datasource\ResultSetInterface deleteManyOrFail(iterable $entities, array $options = [])
*/
-class ContactUsFormSubmissionsTable extends Table
-{
- use MailerAwareTrait;
+class ContactUsFormSubmissionsTable extends Table {
- /**
+ use MailerAwareTrait;
+
+ /**
* Initialize method
*
* @param array $config The configuration for the Table.
* @return void
*/
- public function initialize(array $config): void
- {
- parent::initialize($config);
+ public function initialize(array $config): void {
+ parent::initialize($config);
- $this->setTable('contact_us_form_submissions');
- $this->setDisplayField('name');
- $this->setPrimaryKey('id');
- }
+ $this->setTable('contact_us_form_submissions');
+ $this->setDisplayField('name');
+ $this->setPrimaryKey('id');
+ }
- /**
+ /**
* Default validation rules.
*
- * @param Validator $validator Validator instance.
- * @return Validator
+ * @param \Cake\Validation\Validator $validator Validator instance.
+ * @return \Cake\Validation\Validator
*/
- public function validationDefault(Validator $validator): Validator
- {
- $fields = Configure::readOrFail('ContactUs.fields');
- $validator
- ->dateTime('submitted_at')
- ->requirePresence('submitted_at', 'create')
- ->notEmptyDateTime('submitted_at');
+ public function validationDefault(Validator $validator): Validator {
+ $fields = Configure::readOrFail('ContactUs.fields');
+ $validator
+ ->dateTime('submitted_at')
+ ->requirePresence('submitted_at', 'create')
+ ->notEmptyDateTime('submitted_at');
- $validator
- ->scalar('client_ip')
- ->maxLength('client_ip', 45)
- ->allowEmptyString('client_ip');
+ $validator
+ ->scalar('client_ip')
+ ->maxLength('client_ip', 45)
+ ->allowEmptyString('client_ip');
- $validator
- ->scalar('name')
- ->maxLength('name', 255)
- ->requirePresence('name', 'create')
- ->notEmptyString('name');
+ $validator
+ ->scalar('name')
+ ->maxLength('name', 255)
+ ->requirePresence('name', 'create')
+ ->notEmptyString('name');
- // email
- $validator->email('email');
- if ($fields['email'] ?? false) {
- $validator->notEmptyString('email');
- } else {
- $validator->allowEmptyString('email');
- }
+ // email
+ $validator->email('email');
+ if ($fields['email'] ?? false) {
+ $validator->notEmptyString('email');
+ } else {
+ $validator->allowEmptyString('email');
+ }
- // subject
- $validator
- ->scalar('subject')
- ->maxLength('subject', 255);
- if ($fields['subject'] ?? false) {
- $validator->notEmptyString('subject');
- } else {
- $validator->allowEmptyString('subject');
- }
+ // subject
+ $validator
+ ->scalar('subject')
+ ->maxLength('subject', 255);
+ if ($fields['subject'] ?? false) {
+ $validator->notEmptyString('subject');
+ } else {
+ $validator->allowEmptyString('subject');
+ }
- $validator
- ->scalar('message')
- ->requirePresence('message', 'create')
- ->notEmptyString('message');
+ $validator
+ ->scalar('message')
+ ->requirePresence('message', 'create')
+ ->notEmptyString('message');
- $validator
- ->dateTime('confirm_email_sent')
- ->allowEmptyDateTime('confirm_email_sent');
+ $validator
+ ->dateTime('confirm_email_sent')
+ ->allowEmptyDateTime('confirm_email_sent');
- $validator
- ->dateTime('backend_email_sent')
- ->allowEmptyDateTime('backend_email_sent');
+ $validator
+ ->dateTime('backend_email_sent')
+ ->allowEmptyDateTime('backend_email_sent');
- return $validator;
- }
+ return $validator;
+ }
- /**
- * @param EventInterface $event
- * @param EntityInterface|ContactUsFormSubmission $contactUsFormSubmission
+ /**
+ * @param \Cake\Event\EventInterface $event
+ * @param \Cake\Datasource\EntityInterface|\CakeContactUs\Model\Entity\ContactUsFormSubmission $contactUsFormSubmission
* @param \ArrayObject $options
* @return void
*/
- public function afterSave(EventInterface $event, EntityInterface|ContactUsFormSubmission $contactUsFormSubmission, \ArrayObject $options)
- {
- if (!$contactUsFormSubmission->isNew()) {
- return;
- }
- $now = DateTime::now()->format(CakeContactUsPlugin::CAKE_CONTACT_US_MYSQL_DATETIME);
- $updateData = [];
- if (Configure::read('ContactUs.email.confirmation', false) && isset($contactUsFormSubmission->email)) {
- $mailer = Configure::read('ContactUs.email.mailerClass', 'CakeContactUs.ContactUsFormSubmissions');
- try {
- $this->getMailer($mailer)->send('confirmation', [$contactUsFormSubmission]);
- $updateData['confirm_email_sent'] = $now;
- } catch (CakeException $exception) {
- }
- }
+ public function afterSave(EventInterface $event, EntityInterface|ContactUsFormSubmission $contactUsFormSubmission, ArrayObject $options) {
+ if (!$contactUsFormSubmission->isNew()) {
+ return;
+ }
+ $now = DateTime::now()->format(CakeContactUsPlugin::CAKE_CONTACT_US_MYSQL_DATETIME);
+ $updateData = [];
+ if (Configure::read('ContactUs.email.confirmation', false) && isset($contactUsFormSubmission->email)) {
+ $mailer = Configure::read('ContactUs.email.mailerClass', 'CakeContactUs.ContactUsFormSubmissions');
+ try {
+ $this->getMailer($mailer)->send('confirmation', [$contactUsFormSubmission]);
+ $updateData['confirm_email_sent'] = $now;
+ } catch (CakeException $exception) {
+ }
+ }
+
+ if (Configure::read('ContactUs.email.backend.enabled', false)) {
+ $mailer = Configure::read('ContactUs.email.mailerClass', 'CakeContactUs.ContactUsFormSubmissions');
+ try {
+ $this->getMailer($mailer)->send('backend', [$contactUsFormSubmission]);
+ $updateData['backend_email_sent'] = $now;
+ } catch (CakeException $exception) {
+ }
+ }
+ if ($updateData) {
+ $contactUsFormSubmission = $this->patchEntity($contactUsFormSubmission, $updateData, ['validate' => false]);
+ $this->saveOrFail($contactUsFormSubmission);
+ }
+ }
- if (Configure::read('ContactUs.email.backend.enabled', false)) {
- $mailer = Configure::read('ContactUs.email.mailerClass', 'CakeContactUs.ContactUsFormSubmissions');
- try {
- $this->getMailer($mailer)->send('backend', [$contactUsFormSubmission]);
- $updateData['backend_email_sent'] = $now;
- } catch (CakeException $exception) {
- }
- }
- if ($updateData) {
- $contactUsFormSubmission = $this->patchEntity($contactUsFormSubmission, $updateData, ['validate' => false]);
- $this->saveOrFail($contactUsFormSubmission);
- }
- }
}
diff --git a/tests/Fixture/ContactUsFormSubmissionsFixture.php b/tests/Fixture/ContactUsFormSubmissionsFixture.php
index 9b12016..9e2e53b 100644
--- a/tests/Fixture/ContactUsFormSubmissionsFixture.php
+++ b/tests/Fixture/ContactUsFormSubmissionsFixture.php
@@ -8,28 +8,28 @@ use Cake\TestSuite\Fixture\TestFixture;
/**
* ContactUsFormSubmissionsFixture
*/
-class ContactUsFormSubmissionsFixture extends TestFixture
-{
- /**
+class ContactUsFormSubmissionsFixture extends TestFixture {
+
+ /**
* 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',
- ],
- ];
- parent::init();
- }
+ 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',
+ ],
+ ];
+ parent::init();
+ }
+
}
diff --git a/tests/TestCase/Controller/Component/ContactUsComponentTest.php b/tests/TestCase/Controller/Component/ContactUsComponentTest.php
index b1e1ba9..4304849 100644
--- a/tests/TestCase/Controller/Component/ContactUsComponentTest.php
+++ b/tests/TestCase/Controller/Component/ContactUsComponentTest.php
@@ -4,42 +4,74 @@ 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;
/**
* CakeContactUs\Controller\Component\ContactUsComponent Test Case
*/
-class ContactUsComponentTest extends TestCase
-{
+class ContactUsComponentTest extends TestCase {
+
+ protected ContactUsComponent $component;
+ protected Controller $controller;
+
/**
- * Test subject
+ * Fixtures
*
- * @var \CakeContactUs\Controller\Component\ContactUsComponent
+ * @var array
*/
- protected $ContactUs;
-
- /**
+ protected array $fixtures = [
+ 'plugin.CakeContactUs.ContactUsFormSubmissions',
+ ];
+
+ /**
* setUp method
*
* @return void
*/
- protected function setUp(): void
- {
- parent::setUp();
- $registry = new ComponentRegistry();
- $this->ContactUs = new ContactUsComponent($registry);
- }
+ 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->ContactUs);
+ protected function tearDown(): void {
+ unset($this->component);
- parent::tearDown();
+ 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);
}
}
diff --git a/tests/TestCase/Controller/ContactUsFormSubmissionsControllerTest.php b/tests/TestCase/Controller/ContactUsFormSubmissionsControllerTest.php
index 6615145..4fb2b04 100644
--- a/tests/TestCase/Controller/ContactUsFormSubmissionsControllerTest.php
+++ b/tests/TestCase/Controller/ContactUsFormSubmissionsControllerTest.php
@@ -3,317 +3,304 @@ declare(strict_types=1);
namespace CakeContactUs\Test\TestCase\Controller;
-use App\Model\Table\ContactUsFormSubmissionsTable;
-use Cake\Controller\Controller;
use Cake\Core\Configure;
use Cake\Event\EventList;
use Cake\Event\EventManager;
-use Cake\Http\ServerRequest;
use Cake\Mailer\Transport\DebugTransport;
-use Cake\ORM\Table;
use Cake\TestSuite\EmailTrait;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
use CakeContactUs\CakeContactUsPlugin;
-use CakeContactUs\Controller\ContactUsFormSubmissionsController;
-use PHPUnit\Exception;
/**
* CakeContactUs\Controller\ContactUsFormSubmissionsController Test Case
*
* @uses ContactUsFormSubmissionsController
*/
-class ContactUsFormSubmissionsControllerTest extends TestCase
-{
- use IntegrationTestTrait;
- use EmailTrait;
+class ContactUsFormSubmissionsControllerTest extends TestCase {
- /**
- * @var ContactUsFormSubmissionsTable|Table
+ use IntegrationTestTrait;
+ use EmailTrait;
+
+ /**
+ * @var \App\Model\Table\ContactUsFormSubmissionsTable|\Cake\ORM\Table
*/
- protected $ContactUsFormSubmissions;
+ protected $ContactUsFormSubmissions;
- /**
+ /**
* Fixtures
*
* @var array
*/
- protected array $fixtures = [
- 'plugin.CakeContactUs.ContactUsFormSubmissions',
- ];
+ protected array $fixtures = [
+ 'plugin.CakeContactUs.ContactUsFormSubmissions',
+ ];
- /**
+ /**
* setUp method
*
* @return void
*/
- protected function setUp(): void
- {
- parent::setUp();
- $this->ContactUsFormSubmissions = $this->getTableLocator()->get('ContactUsFormSubmissions');
+ protected function setUp(): void {
+ parent::setUp();
+ $this->ContactUsFormSubmissions = $this->getTableLocator()->get('ContactUsFormSubmissions');
- EventManager::instance()->setEventList(new EventList());
- }
+ EventManager::instance()->setEventList(new EventList());
+ }
- /**
+ /**
* tearDown method
*
* @return void
*/
- protected function tearDown(): void
- {
- unset($this->ContactUsFormSubmissions);
+ protected function tearDown(): void {
+ unset($this->ContactUsFormSubmissions);
- parent::tearDown();
- }
+ parent::tearDown();
+ }
- /**
+ /**
* Test add method
*
* Tests the add action with a logged in user
*
- * @return void
+ * @uses ContactUsFormSubmissionsController::add
* @throws Exception
*
- * @uses ContactUsFormSubmissionsController::add
+ * @return void
*/
- public function testAddGet(): void
- {
- $cntBefore = $this->ContactUsFormSubmissions->find()->count();
+ public function testAddGet(): void {
+ $cntBefore = $this->ContactUsFormSubmissions->find()->count();
- $url = [
- 'plugin' => 'CakeContactUs',
- 'controller' => 'ContactUsFormSubmissions',
- 'action' => 'add',
- ];
- $this->get($url);
- $this->assertResponseCode(200);
+ $url = [
+ 'plugin' => 'CakeContactUs',
+ 'controller' => 'ContactUsFormSubmissions',
+ 'action' => 'add',
+ ];
+ $this->get($url);
+ $this->assertResponseCode(200);
- $cntAfter = $this->ContactUsFormSubmissions->find()->count();
- $this->assertEquals($cntBefore, $cntAfter);
+ $cntAfter = $this->ContactUsFormSubmissions->find()->count();
+ $this->assertEquals($cntBefore, $cntAfter);
- $this->assertNoMailSent();
- }
+ $this->assertNoMailSent();
+ }
- /**
+ /**
* Test add method
*
* Tests a POST request to the add action with a logged in user
*
+ * @uses ContactUsFormSubmissionsController::add
+ * @throws Exception
+ *
* @return void
- * @throws Exception
- *
- * @uses ContactUsFormSubmissionsController::add
*/
- public function testAddPostSuccessNoEmail(): void
- {
- $cntBefore = $this->ContactUsFormSubmissions->find()->count();
+ public function testAddPostSuccessNoEmail(): void {
+ $cntBefore = $this->ContactUsFormSubmissions->find()->count();
- $url = [
- 'plugin' => 'CakeContactUs',
- 'controller' => 'ContactUsFormSubmissions',
- 'action' => 'add',
- ];
- $data = [
- 'name' => 'valid name',
- 'email' => 'valid_email@test.com',
- 'message' => 'valid message goes here',
- ];
- $this->post($url, $data);
- $this->assertResponseCode(302);
- $cntAfter = $this->ContactUsFormSubmissions->find()->count();
- $this->assertEquals($cntBefore + 1, $cntAfter);
- $this->assertEventFired(CakeContactUsPlugin::EVENT_AFTER_CONTACT_US_FORM_SAVED);
- $this->assertNoMailSent();
- }
+ $url = [
+ 'plugin' => 'CakeContactUs',
+ 'controller' => 'ContactUsFormSubmissions',
+ 'action' => 'add',
+ ];
+ $data = [
+ 'name' => 'valid name',
+ 'email' => 'valid_email@test.com',
+ 'message' => 'valid message goes here',
+ ];
+ $this->post($url, $data);
+ $this->assertResponseCode(302);
+ $cntAfter = $this->ContactUsFormSubmissions->find()->count();
+ $this->assertEquals($cntBefore + 1, $cntAfter);
+ $this->assertEventFired(CakeContactUsPlugin::EVENT_AFTER_CONTACT_US_FORM_SAVED);
+ $this->assertNoMailSent();
+ }
- /**
+ /**
* Test add method
*
* Tests a POST request to the add action with a logged in user
*
- * @return void
+ * @uses ContactUsFormSubmissionsController::add
* @throws Exception
*
- * @uses ContactUsFormSubmissionsController::add
+ * @return void
*/
- public function testAddPostSuccessBothEmailsSent(): void
- {
- Configure::write('ContactUs', [
- 'fields' => [
- 'captcha' => false,
- 'email' => true,
- ],
- 'email' => [
- 'mailerClass' => 'CakeContactUs.ContactUsFormSubmissions',
- 'confirmation' => true, // true or false
- 'backend' => [ // array with enabled and the to/cc/bcc/ fields as strings or arrays
- 'enabled' => true,
- 'to' => 'test@example.com',
- ],
- ],
- ]);
- Configure::write('EmailTransport', [
- 'default' => [
- 'className' => DebugTransport::class,
- ]
- ]);
+ public function testAddPostSuccessBothEmailsSent(): void {
+ Configure::write('ContactUs', [
+ 'fields' => [
+ 'captcha' => false,
+ 'email' => true,
+ ],
+ 'email' => [
+ 'mailerClass' => 'CakeContactUs.ContactUsFormSubmissions',
+ 'confirmation' => true, // true or false
+ 'backend' => [ // array with enabled and the to/cc/bcc/ fields as strings or arrays
+ 'enabled' => true,
+ 'to' => 'test@example.com',
+ ],
+ ],
+ ]);
+ Configure::write('EmailTransport', [
+ 'default' => [
+ 'className' => DebugTransport::class,
+ ],
+ ]);
- $cntBefore = $this->ContactUsFormSubmissions->find()->count();
+ $cntBefore = $this->ContactUsFormSubmissions->find()->count();
- $url = [
- 'plugin' => 'CakeContactUs',
- 'controller' => 'ContactUsFormSubmissions',
- 'action' => 'add',
- ];
- $data = [
- 'name' => 'valid name',
- 'email' => 'valid_email@test.com',
- 'message' => 'valid message goes here',
- ];
- $this->post($url, $data);
- $this->assertResponseCode(302);
+ $url = [
+ 'plugin' => 'CakeContactUs',
+ 'controller' => 'ContactUsFormSubmissions',
+ 'action' => 'add',
+ ];
+ $data = [
+ 'name' => 'valid name',
+ 'email' => 'valid_email@test.com',
+ 'message' => 'valid message goes here',
+ ];
+ $this->post($url, $data);
+ $this->assertResponseCode(302);
- $cntAfter = $this->ContactUsFormSubmissions->find()->count();
- $this->assertEquals($cntBefore + 1, $cntAfter);
- $this->assertEventFired(CakeContactUsPlugin::EVENT_AFTER_CONTACT_US_FORM_SAVED);
+ $cntAfter = $this->ContactUsFormSubmissions->find()->count();
+ $this->assertEquals($cntBefore + 1, $cntAfter);
+ $this->assertEventFired(CakeContactUsPlugin::EVENT_AFTER_CONTACT_US_FORM_SAVED);
- $this->assertMailCount(2); // confirmation + backend emails
- }
+ $this->assertMailCount(2); // confirmation + backend emails
+ }
- /**
+ /**
* Test add method
*
* Tests a POST request to the add action with a logged in user
*
- * @return void
+ * @uses ContactUsFormSubmissionsController::add
* @throws Exception
*
- * @uses ContactUsFormSubmissionsController::add
+ * @return void
*/
- public function testAddPostSuccessConfirmationEmailSent(): void
- {
- Configure::write('ContactUs', [
- 'fields' => [
- 'captcha' => false,
- 'email' => true,
- ],
- 'email' => [
- 'mailerClass' => 'CakeContactUs.ContactUsFormSubmissions',
- 'confirmation' => true, // true or false
- 'backend' => [ // array with enabled and the to/cc/bcc/ fields as strings or arrays
- 'enabled' => false,
- 'to' => 'test@example.com',
- ],
- ],
- ]);
- $cntBefore = $this->ContactUsFormSubmissions->find()->count();
+ public function testAddPostSuccessConfirmationEmailSent(): void {
+ Configure::write('ContactUs', [
+ 'fields' => [
+ 'captcha' => false,
+ 'email' => true,
+ ],
+ 'email' => [
+ 'mailerClass' => 'CakeContactUs.ContactUsFormSubmissions',
+ 'confirmation' => true, // true or false
+ 'backend' => [ // array with enabled and the to/cc/bcc/ fields as strings or arrays
+ 'enabled' => false,
+ 'to' => 'test@example.com',
+ ],
+ ],
+ ]);
+ $cntBefore = $this->ContactUsFormSubmissions->find()->count();
- $url = [
- 'plugin' => 'CakeContactUs',
- 'controller' => 'ContactUsFormSubmissions',
- 'action' => 'add',
- ];
- $data = [
- 'name' => 'valid name',
- 'email' => 'valid_email@test.com',
- 'message' => 'valid message goes here',
- ];
- $this->post($url, $data);
- $this->assertResponseCode(302);
+ $url = [
+ 'plugin' => 'CakeContactUs',
+ 'controller' => 'ContactUsFormSubmissions',
+ 'action' => 'add',
+ ];
+ $data = [
+ 'name' => 'valid name',
+ 'email' => 'valid_email@test.com',
+ 'message' => 'valid message goes here',
+ ];
+ $this->post($url, $data);
+ $this->assertResponseCode(302);
- $cntAfter = $this->ContactUsFormSubmissions->find()->count();
- $this->assertEquals($cntBefore + 1, $cntAfter);
- $this->assertEventFired(CakeContactUsPlugin::EVENT_AFTER_CONTACT_US_FORM_SAVED);
+ $cntAfter = $this->ContactUsFormSubmissions->find()->count();
+ $this->assertEquals($cntBefore + 1, $cntAfter);
+ $this->assertEventFired(CakeContactUsPlugin::EVENT_AFTER_CONTACT_US_FORM_SAVED);
- $this->assertMailCount(1); // confirmation only
- }
+ $this->assertMailCount(1); // confirmation only
+ }
- /**
+ /**
* Test add method
*
* Tests a POST request to the add action with a logged in user
*
- * @return void
+ * @uses ContactUsFormSubmissionsController::add
* @throws Exception
*
- * @uses ContactUsFormSubmissionsController::add
+ * @return void
*/
- public function testAddPostSuccessBackendEmailSent(): void
- {
- Configure::write('ContactUs', [
- 'fields' => [
- 'captcha' => false,
- 'email' => true,
- ],
- 'email' => [
- 'mailerClass' => 'CakeContactUs.ContactUsFormSubmissions',
- 'confirmation' => false, // true or false
- 'backend' => [ // array with enabled and the to/cc/bcc/ fields as strings or arrays
- 'enabled' => true,
- 'to' => 'test@example.com',
- ],
- ],
- ]);
+ public function testAddPostSuccessBackendEmailSent(): void {
+ Configure::write('ContactUs', [
+ 'fields' => [
+ 'captcha' => false,
+ 'email' => true,
+ ],
+ 'email' => [
+ 'mailerClass' => 'CakeContactUs.ContactUsFormSubmissions',
+ 'confirmation' => false, // true or false
+ 'backend' => [ // array with enabled and the to/cc/bcc/ fields as strings or arrays
+ 'enabled' => true,
+ 'to' => 'test@example.com',
+ ],
+ ],
+ ]);
- $cntBefore = $this->ContactUsFormSubmissions->find()->count();
+ $cntBefore = $this->ContactUsFormSubmissions->find()->count();
- $url = [
- 'plugin' => 'CakeContactUs',
- 'controller' => 'ContactUsFormSubmissions',
- 'action' => 'add',
- ];
- $data = [
- 'name' => 'valid name',
- 'email' => 'valid_email@test.com',
- 'message' => 'valid message goes here',
- ];
- $this->post($url, $data);
- $responseBody = (string)$this->_response->getBody();
- $tmpLog = fopen(TMP . 'phpunit.log', 'w');
- if ($tmpLog) {
- fwrite($tmpLog, $responseBody);
- }
- $this->assertResponseCode(302);
+ $url = [
+ 'plugin' => 'CakeContactUs',
+ 'controller' => 'ContactUsFormSubmissions',
+ 'action' => 'add',
+ ];
+ $data = [
+ 'name' => 'valid name',
+ 'email' => 'valid_email@test.com',
+ 'message' => 'valid message goes here',
+ ];
+ $this->post($url, $data);
+ $responseBody = (string)$this->_response->getBody();
+ $tmpLog = fopen(TMP . 'phpunit.log', 'w');
+ if ($tmpLog) {
+ fwrite($tmpLog, $responseBody);
+ }
+ $this->assertResponseCode(302);
- $cntAfter = $this->ContactUsFormSubmissions->find()->count();
- $this->assertEquals($cntBefore + 1, $cntAfter);
- $this->assertEventFired(CakeContactUsPlugin::EVENT_AFTER_CONTACT_US_FORM_SAVED);
+ $cntAfter = $this->ContactUsFormSubmissions->find()->count();
+ $this->assertEquals($cntBefore + 1, $cntAfter);
+ $this->assertEventFired(CakeContactUsPlugin::EVENT_AFTER_CONTACT_US_FORM_SAVED);
- $this->assertMailCount(1); // backend email only
- }
+ $this->assertMailCount(1); // backend email only
+ }
- /**
+ /**
* Test add method
*
* Tests a POST request to the add action with a logged in user
*
- * @return void
+ * @uses ContactUsFormSubmissionsController::add
* @throws Exception
*
- * @uses ContactUsFormSubmissionsController::add
+ * @return void
*/
- public function testAddPostLoggedInFailure(): void
- {
- $cntBefore = $this->ContactUsFormSubmissions->find()->count();
+ public function testAddPostLoggedInFailure(): void {
+ $cntBefore = $this->ContactUsFormSubmissions->find()->count();
- // $this->loginUserByRole('admin');
- $url = [
- 'plugin' => 'CakeContactUs',
- 'controller' => 'ContactUsFormSubmissions',
- 'action' => 'add',
- ];
- $data = [
- 'name' => 'valid name',
- 'email' => 'not_valid_email',
- 'message' => 'this is a valid message ',
- ];
- $this->post($url, $data);
- $this->assertResponseCode(200);
+ // $this->loginUserByRole('admin');
+ $url = [
+ 'plugin' => 'CakeContactUs',
+ 'controller' => 'ContactUsFormSubmissions',
+ 'action' => 'add',
+ ];
+ $data = [
+ 'name' => 'valid name',
+ 'email' => 'not_valid_email',
+ 'message' => 'this is a valid message ',
+ ];
+ $this->post($url, $data);
+ $this->assertResponseCode(200);
+
+ $cntAfter = $this->ContactUsFormSubmissions->find()->count();
+ $this->assertEquals($cntBefore, $cntAfter);
+ $this->assertEventFired(CakeContactUsPlugin::EVENT_BEFORE_CONTACT_US_FORM_SAVED);
+ $this->assertNoMailSent();
+ }
- $cntAfter = $this->ContactUsFormSubmissions->find()->count();
- $this->assertEquals($cntBefore, $cntAfter);
- $this->assertEventFired(CakeContactUsPlugin::EVENT_BEFORE_CONTACT_US_FORM_SAVED);
- $this->assertNoMailSent();
- }
}
diff --git a/tests/TestCase/Model/Table/ContactUsFormSubmissionsTableTest.php b/tests/TestCase/Model/Table/ContactUsFormSubmissionsTableTest.php
index 90d4dcd..553566d 100644
--- a/tests/TestCase/Model/Table/ContactUsFormSubmissionsTableTest.php
+++ b/tests/TestCase/Model/Table/ContactUsFormSubmissionsTableTest.php
@@ -9,83 +9,80 @@ use CakeContactUs\Model\Table\ContactUsFormSubmissionsTable;
/**
* CakeContactUs\Model\Table\ContactUsFormSubmissionsTable Test Case
*/
-class ContactUsFormSubmissionsTableTest extends TestCase
-{
- /**
+class ContactUsFormSubmissionsTableTest extends TestCase {
+
+ /**
* Test subject
*
* @var \CakeContactUs\Model\Table\ContactUsFormSubmissionsTable
*/
- protected $ContactUsFormSubmissions;
+ protected $ContactUsFormSubmissions;
- /**
+ /**
* Fixtures
*
* @var array
*/
- protected array $fixtures = [
- 'plugin.CakeContactUs.ContactUsFormSubmissions',
- ];
+ protected array $fixtures = [
+ 'plugin.CakeContactUs.ContactUsFormSubmissions',
+ ];
- /**
+ /**
* setUp method
*
* @return void
*/
- protected function setUp(): void
- {
- parent::setUp();
- $config = $this->getTableLocator()->exists('ContactUsFormSubmissions') ? [] : ['className' => ContactUsFormSubmissionsTable::class];
- $this->ContactUsFormSubmissions = $this->getTableLocator()->get('ContactUsFormSubmissions', $config);
- }
+ protected function setUp(): void {
+ parent::setUp();
+ $config = $this->getTableLocator()->exists('ContactUsFormSubmissions') ? [] : ['className' => ContactUsFormSubmissionsTable::class];
+ $this->ContactUsFormSubmissions = $this->getTableLocator()->get('ContactUsFormSubmissions', $config);
+ }
- /**
+ /**
* tearDown method
*
* @return void
*/
- protected function tearDown(): void
- {
- unset($this->ContactUsFormSubmissions);
+ protected function tearDown(): void {
+ unset($this->ContactUsFormSubmissions);
- parent::tearDown();
- }
+ parent::tearDown();
+ }
- /**
+ /**
* TestInitialize method
*
- * @return void
* @uses \CakeContactUs\Model\Table\ContactUsFormSubmissionsTable::initialize()
+ * @return void
*/
- public function testInitialize(): void
- {
- // verify all associations loaded
- $expectedAssociations = [];
- $associations = $this->ContactUsFormSubmissions->associations();
+ public function testInitialize(): void {
+ // verify all associations loaded
+ $expectedAssociations = [];
+ $associations = $this->ContactUsFormSubmissions->associations();
- $this->assertCount(count($expectedAssociations), $associations);
- foreach ($expectedAssociations as $expectedAssociation) {
- $this->assertTrue($this->ContactUsFormSubmissions->hasAssociation($expectedAssociation));
- }
+ $this->assertCount(count($expectedAssociations), $associations);
+ foreach ($expectedAssociations as $expectedAssociation) {
+ $this->assertTrue($this->ContactUsFormSubmissions->hasAssociation($expectedAssociation));
+ }
- // verify all behaviors loaded
- $expectedBehaviors = [];
- $behaviors = $this->ContactUsFormSubmissions->behaviors();
+ // verify all behaviors loaded
+ $expectedBehaviors = [];
+ $behaviors = $this->ContactUsFormSubmissions->behaviors();
- $this->assertCount(count($expectedBehaviors), $behaviors);
- foreach ($expectedBehaviors as $expectedBehavior) {
- $this->assertTrue($this->ContactUsFormSubmissions->hasBehavior($expectedBehavior));
- }
- }
+ $this->assertCount(count($expectedBehaviors), $behaviors);
+ foreach ($expectedBehaviors as $expectedBehavior) {
+ $this->assertTrue($this->ContactUsFormSubmissions->hasBehavior($expectedBehavior));
+ }
+ }
- /**
+ /**
* Test validationDefault method
*
- * @return void
* @uses \CakeContactUs\Model\Table\ContactUsFormSubmissionsTable::validationDefault()
+ * @return void
*/
- public function testValidationDefault(): void
- {
- $this->markTestIncomplete('Not implemented yet.');
- }
+ public function testValidationDefault(): void {
+ $this->markTestIncomplete('Not implemented yet.');
+ }
+
}
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index e83db15..aa07675 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -10,20 +10,19 @@ use Cake\Datasource\ConnectionManager;
use Cake\Mailer\Mailer;
use Cake\Mailer\Transport\DebugTransport;
use Cake\Mailer\TransportFactory;
-use Cake\TestSuite\Fixture\SchemaLoader;
use CakeContactUs\CakeContactUsPlugin;
use Migrations\TestSuite\Migrator;
use TestApp\Controller\AppController;
if (!defined('DS')) {
- define('DS', DIRECTORY_SEPARATOR);
+ define('DS', DIRECTORY_SEPARATOR);
}
if (!defined('WINDOWS')) {
- if (DS === '\\' || substr(PHP_OS, 0, 3) === 'WIN') {
- define('WINDOWS', true);
- } else {
- define('WINDOWS', false);
- }
+ if (DS === '\\' || substr(PHP_OS, 0, 3) === 'WIN') {
+ define('WINDOWS', true);
+ } else {
+ define('WINDOWS', false);
+ }
}
define('PLUGIN_ROOT', dirname(__DIR__));
@@ -48,42 +47,42 @@ require CORE_PATH . 'config/bootstrap.php';
require CAKE . 'functions.php';
Configure::write('App', [
- 'namespace' => 'TestApp',
- 'encoding' => 'UTF-8',
- 'paths' => [
- 'testWebroot' => PLUGIN_ROOT . DS . 'tests' . DS . 'test_app' . DS . 'webroot' . DS,
- 'webroot' => PLUGIN_ROOT . DS . 'webroot' . DS,
- 'templates' => [
- PLUGIN_ROOT . DS . 'tests' . DS . 'test_app' . DS . 'templates' . DS,
- ],
- ],
+ 'namespace' => 'TestApp',
+ 'encoding' => 'UTF-8',
+ 'paths' => [
+ 'testWebroot' => PLUGIN_ROOT . DS . 'tests' . DS . 'test_app' . DS . 'webroot' . DS,
+ 'webroot' => PLUGIN_ROOT . DS . 'webroot' . DS,
+ 'templates' => [
+ PLUGIN_ROOT . DS . 'tests' . DS . 'test_app' . DS . 'templates' . DS,
+ ],
+ ],
]);
Configure::write('debug', true);
Configure::write('ContactUs', [
- 'fields' => [
- 'captcha' => false,
- 'email' => true,
- ],
- 'email' => [
- 'mailerClass' => 'CakeContactUs.ContactUsFormSubmissions',
- 'confirmation' => false, // true or false
- 'backend' => [ // array with enabled and the to/cc/bcc/ fields as strings or arrays
- 'enabled' => false,
- 'to' => 'test@example.com',
- ],
- ],
+ 'fields' => [
+ 'captcha' => false,
+ 'email' => true,
+ ],
+ 'email' => [
+ 'mailerClass' => 'CakeContactUs.ContactUsFormSubmissions',
+ 'confirmation' => false, // true or false
+ 'backend' => [ // array with enabled and the to/cc/bcc/ fields as strings or arrays
+ 'enabled' => false,
+ 'to' => 'test@example.com',
+ ],
+ ],
]);
Configure::write('EmailTransport', [
- 'default' => [
- 'className' => DebugTransport::class,
- ]
+ 'default' => [
+ 'className' => DebugTransport::class,
+ ],
]);
TransportFactory::setConfig('default', [
- 'className' => DebugTransport::class,
+ 'className' => DebugTransport::class,
]);
Configure::write('Email', [
- /*
+ /*
* Email delivery profiles
*
* Delivery profiles allow you to predefine various properties about email
@@ -92,35 +91,35 @@ Configure::write('Email', [
* easier. Each profile accepts a number of keys. See `Cake\Mailer\Email`
* for more information.
*/
- 'default' => [
- 'transport' => 'default',
- 'from' => 'test@example.com',
- /*
+ 'default' => [
+ 'transport' => 'default',
+ 'from' => 'test@example.com',
+ /*
* Will by default be set to config value of App.encoding, if that exists otherwise to UTF-8.
*/
- //'charset' => 'utf-8',
- //'headerCharset' => 'utf-8',
- ],
+ //'charset' => 'utf-8',
+ //'headerCharset' => 'utf-8',
+ ],
]);
$cache = [
- 'default' => [
- 'engine' => 'File',
- 'path' => CACHE,
- ],
- '_cake_translations_' => [
- 'className' => 'File',
- 'prefix' => 'crud_myapp_cake_core_',
- 'path' => CACHE . 'persistent/',
- 'serialize' => true,
- 'duration' => '+10 seconds',
- ],
- '_cake_model_' => [
- 'className' => 'File',
- 'prefix' => 'crud_my_app_cake_model_',
- 'path' => CACHE . 'models/',
- 'serialize' => 'File',
- 'duration' => '+10 seconds',
- ],
+ 'default' => [
+ 'engine' => 'File',
+ 'path' => CACHE,
+ ],
+ '_cake_translations_' => [
+ 'className' => 'File',
+ 'prefix' => 'crud_myapp_cake_core_',
+ 'path' => CACHE . 'persistent/',
+ 'serialize' => true,
+ 'duration' => '+10 seconds',
+ ],
+ '_cake_model_' => [
+ 'className' => 'File',
+ 'prefix' => 'crud_my_app_cake_model_',
+ 'path' => CACHE . 'models/',
+ 'serialize' => 'File',
+ 'duration' => '+10 seconds',
+ ],
];
Cache::setConfig($cache);
@@ -133,15 +132,15 @@ Plugin::getCollection()->add(new CakeContactUsPlugin());
Chronos::setTestNow(Chronos::now());
if (!getenv('DB_URL')) {
- putenv('DB_URL=sqlite:///:memory:');
+ putenv('DB_URL=sqlite:///:memory:');
}
ConnectionManager::setConfig('test', [
- 'className' => Connection::class,
- 'url' => getenv('DB_URL') ?: null,
- 'timezone' => 'UTC',
- 'quoteIdentifiers' => false,
- 'cacheMetadata' => true,
+ 'className' => Connection::class,
+ 'url' => getenv('DB_URL') ?: null,
+ 'timezone' => 'UTC',
+ 'quoteIdentifiers' => false,
+ 'cacheMetadata' => true,
]);
/**
@@ -156,7 +155,17 @@ 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);
+}
$migrator = new Migrator();
$migrator->run(['plugin' => 'CakeContactUs']);
+$migrator->run(['plugin' => 'Captcha']);