WIP - phpstan and phpcs - tests failing currently
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ declare(strict_types=1);
|
||||
|
||||
use Migrations\AbstractMigration;
|
||||
|
||||
class CreateContactUsFormSubmissions extends AbstractMigration
|
||||
{
|
||||
class CreateContactUsFormSubmissions extends AbstractMigration {
|
||||
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
@@ -12,8 +12,7 @@ class CreateContactUsFormSubmissions extends AbstractMigration
|
||||
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
|
||||
* @return void
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
public function change(): void {
|
||||
$table = $this->table('contact_us_form_submissions', ['id' => false, 'primary_key' => ['id']]);
|
||||
|
||||
$table->addColumn('id', 'uuid', [
|
||||
@@ -58,4 +57,5 @@ class CreateContactUsFormSubmissions extends AbstractMigration
|
||||
]);
|
||||
$table->create();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
21
phpcs.xml
Normal file
21
phpcs.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0"?>
|
||||
<ruleset name="plugin">
|
||||
<arg value="nps"/>
|
||||
|
||||
<file>src/</file>
|
||||
<file>config/</file>
|
||||
<file>tests/</file>
|
||||
|
||||
<exclude-pattern>/tests/test_files/</exclude-pattern>
|
||||
<exclude-pattern>/tests/test_app/</exclude-pattern>
|
||||
|
||||
<rule ref="vendor/fig-r/psr2r-sniffer/PSR2R/ruleset.xml"/>
|
||||
|
||||
<rule ref="PSR1.Classes.ClassDeclaration.MissingNamespace">
|
||||
<exclude-pattern>*/config/Migrations/*</exclude-pattern>
|
||||
</rule>
|
||||
<rule ref="PhpCollective.Classes.ClassFileName.NoMatch">
|
||||
<exclude-pattern>*/config/Migrations/*</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
</ruleset>
|
||||
10
phpstan.neon
Normal file
10
phpstan.neon
Normal file
@@ -0,0 +1,10 @@
|
||||
includes:
|
||||
- vendor/cakedc/cakephp-phpstan/extension.neon
|
||||
|
||||
parameters:
|
||||
level: 4
|
||||
paths:
|
||||
- src
|
||||
bootstrapFiles:
|
||||
- tests/bootstrap.php
|
||||
treatPhpDocTypesAsCertain: false
|
||||
@@ -13,10 +13,21 @@ use Cake\Routing\RouteBuilder;
|
||||
/**
|
||||
* Plugin for CakeContactUs
|
||||
*/
|
||||
class CakeContactUsPlugin extends BasePlugin
|
||||
{
|
||||
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.
|
||||
@@ -27,8 +38,7 @@ 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 {
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,8 +50,7 @@ class CakeContactUsPlugin extends BasePlugin
|
||||
* @param \Cake\Routing\RouteBuilder $routes The route builder to update.
|
||||
* @return void
|
||||
*/
|
||||
public function routes(RouteBuilder $routes): 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']);
|
||||
@@ -62,8 +71,7 @@ class CakeContactUsPlugin extends BasePlugin
|
||||
* @param \Cake\Http\MiddlewareQueue $middlewareQueue The middleware queue to update.
|
||||
* @return \Cake\Http\MiddlewareQueue
|
||||
*/
|
||||
public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue
|
||||
{
|
||||
public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue {
|
||||
// Add your middlewares here
|
||||
|
||||
return $middlewareQueue;
|
||||
@@ -75,8 +83,7 @@ class CakeContactUsPlugin extends BasePlugin
|
||||
* @param \Cake\Console\CommandCollection $commands The command collection to update.
|
||||
* @return \Cake\Console\CommandCollection
|
||||
*/
|
||||
public function console(CommandCollection $commands): CommandCollection
|
||||
{
|
||||
public function console(CommandCollection $commands): CommandCollection {
|
||||
// Add your commands here
|
||||
|
||||
$commands = parent::console($commands);
|
||||
@@ -87,12 +94,12 @@ class CakeContactUsPlugin extends BasePlugin
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
public function services(ContainerInterface $container): void {
|
||||
// Add your services here
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,10 +10,9 @@ use App\Controller\AppController;
|
||||
*
|
||||
* @property \CakeContactUs\Model\Table\ContactUsFormSubmissionsTable $ContactUsFormSubmissions
|
||||
*/
|
||||
class ContactUsFormSubmissionsController extends AppController
|
||||
{
|
||||
public function initialize(): void
|
||||
{
|
||||
class ContactUsFormSubmissionsController extends AppController {
|
||||
|
||||
public function initialize(): void {
|
||||
parent::initialize(); // TODO: Change the autogenerated stub
|
||||
}
|
||||
|
||||
@@ -22,8 +21,7 @@ class ContactUsFormSubmissionsController extends AppController
|
||||
*
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
public function index() {
|
||||
$query = $this->ContactUsFormSubmissions->find();
|
||||
$contactUsFormSubmissions = $this->paginate($query);
|
||||
|
||||
@@ -34,25 +32,22 @@ class ContactUsFormSubmissionsController extends AppController
|
||||
* 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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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());
|
||||
@@ -70,11 +65,10 @@ class ContactUsFormSubmissionsController extends AppController
|
||||
* 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)
|
||||
{
|
||||
public function delete($id = null) {
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
$contactUsFormSubmission = $this->ContactUsFormSubmissions->get($id);
|
||||
if ($this->ContactUsFormSubmissions->delete($contactUsFormSubmission)) {
|
||||
@@ -85,4 +79,5 @@ class ContactUsFormSubmissionsController extends AppController
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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,18 +11,18 @@ 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
|
||||
{
|
||||
class ContactUsComponent extends Component {
|
||||
|
||||
/**
|
||||
* @var ContactUsFormSubmissionsTable|Table
|
||||
* @var \CakeContactUs\Model\Table\ContactUsFormSubmissionsTable|\Cake\ORM\Table
|
||||
*/
|
||||
protected ContactUsFormSubmissionsTable|Table $ContactUsFormSubmissions;
|
||||
|
||||
@@ -41,12 +40,11 @@ class ContactUsComponent extends Component
|
||||
|
||||
/**
|
||||
* @param array $config
|
||||
* @throws \Exception
|
||||
* @return void
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function initialize(array $config): void
|
||||
{
|
||||
public function initialize(array $config): void {
|
||||
parent::initialize($config); // TODO: Change the autogenerated stub
|
||||
|
||||
$this->ContactUsFormSubmissions = TableRegistry::getTableLocator()->get('CakeContactUs.ContactUsFormSubmissions');
|
||||
@@ -63,10 +61,9 @@ class ContactUsComponent extends Component
|
||||
}
|
||||
|
||||
/**
|
||||
* @return EntityInterface|ContactUsFormSubmission
|
||||
* @return \Cake\Datasource\EntityInterface|\CakeContactUs\Model\Entity\ContactUsFormSubmission
|
||||
*/
|
||||
public function newContactUsForm()
|
||||
{
|
||||
public function newContactUsForm() {
|
||||
if ($this->getConfig('requireCaptcha')) {
|
||||
$this->ContactUsFormSubmissions->addBehavior('Captcha.Captcha');
|
||||
}
|
||||
@@ -75,10 +72,9 @@ class ContactUsComponent extends Component
|
||||
}
|
||||
|
||||
/**
|
||||
* @return EntityInterface|ContactUsFormSubmission
|
||||
* @return \Cake\Http\Response|null|void
|
||||
*/
|
||||
public function processContactUsForm(EntityInterface $contactUsFormSubmission, array|null $postData)
|
||||
{
|
||||
public function processContactUsForm(EntityInterface $contactUsFormSubmission, array|null $postData) {
|
||||
if (!isset($postData)) {
|
||||
$postData = $this->getController()->getRequest()->getData();
|
||||
}
|
||||
@@ -126,7 +122,6 @@ class ContactUsComponent extends Component
|
||||
Log::debug(print_r($contactUsFormSubmission->getErrors(), true));
|
||||
}
|
||||
|
||||
|
||||
$contactUsFormSubmissionSaved = $this->ContactUsFormSubmissions->save($contactUsFormSubmission);
|
||||
|
||||
if ($contactUsFormSubmissionSaved) {
|
||||
@@ -143,11 +138,10 @@ class ContactUsComponent extends Component
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
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,
|
||||
@@ -164,6 +158,8 @@ class ContactUsComponent extends Component
|
||||
if ($this->getConfig('addIdToRedirect')) {
|
||||
$redirectUrl[] = $contactUsFormSubmissionSaved->get($this->ContactUsFormSubmissions->getPrimaryKey());
|
||||
}
|
||||
|
||||
return $this->getController()->redirect($redirectUrl);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,12 +8,12 @@ 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
|
||||
{
|
||||
class ContactUsFormSubmissionsController extends AppController {
|
||||
|
||||
public function initialize(): void {
|
||||
parent::initialize(); // TODO: Change the autogenerated stub
|
||||
$this->loadComponent('CakeContactUs.ContactUs');
|
||||
}
|
||||
@@ -23,12 +23,12 @@ class ContactUsFormSubmissionsController extends AppController
|
||||
*
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
public function add() {
|
||||
$contactUsFormSubmission = $this->ContactUs->newContactUsForm();
|
||||
if ($this->request->is('post')) {
|
||||
return $this->ContactUs->processContactUsForm($contactUsFormSubmission, $this->request->getData());
|
||||
}
|
||||
$this->set(compact('contactUsFormSubmission'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,28 +4,28 @@ 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
|
||||
{
|
||||
class ContactUsFormSubmissionsMailer extends Mailer {
|
||||
|
||||
/**
|
||||
* Send the templated email to the user
|
||||
* 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'] . ', ' : '';
|
||||
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'])
|
||||
->setTo($contactUsFormSubmission->email)
|
||||
->setSubject($name . $subject)
|
||||
->setEmailFormat(Message::MESSAGE_BOTH)
|
||||
->setViewVars([
|
||||
@@ -39,13 +39,13 @@ class ContactUsFormSubmissionsMailer extends Mailer
|
||||
/**
|
||||
* 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 = [])
|
||||
{
|
||||
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->name) ? ' by ' . $contactUsFormSubmission->name : '';
|
||||
|
||||
$to = Configure::readOrFail('ContactUs.email.backend.to');
|
||||
$cc = Configure::read('ContactUs.email.backend.cc', []);
|
||||
@@ -72,4 +72,5 @@ class ContactUsFormSubmissionsMailer extends Mailer
|
||||
$this->viewBuilder()
|
||||
->setTemplate('CakeContactUs.backend');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ 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().
|
||||
*
|
||||
@@ -39,4 +39,5 @@ class ContactUsFormSubmission extends Entity
|
||||
'confirm_email_sent' => true,
|
||||
'backend_email_sent' => true,
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
@@ -3,42 +3,37 @@ 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<ContactUsFormSubmission> 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<ContactUsFormSubmission> patchEntities(iterable $entities, array $data, array $options = [])
|
||||
* @method ContactUsFormSubmission|false save(EntityInterface $entity, array $options = [])
|
||||
* @method ContactUsFormSubmission saveOrFail(EntityInterface $entity, array $options = [])
|
||||
* @method iterable<ContactUsFormSubmission>|ResultSetInterface<ContactUsFormSubmission>|false saveMany(iterable $entities, array $options = [])
|
||||
* @method iterable<ContactUsFormSubmission>|ResultSetInterface<ContactUsFormSubmission> saveManyOrFail(iterable $entities, array $options = [])
|
||||
* @method iterable<ContactUsFormSubmission>|ResultSetInterface<ContactUsFormSubmission>|false deleteMany(iterable $entities, array $options = [])
|
||||
* @method iterable<ContactUsFormSubmission>|ResultSetInterface<ContactUsFormSubmission> deleteManyOrFail(iterable $entities, array $options = [])
|
||||
* @method \CakeContactUs\Model\Entity\ContactUsFormSubmission saveOrFail(\Cake\Datasource\EntityInterface $entity, array $options = [])
|
||||
* @method iterable<ContactUsFormSubmission>|\Cake\Datasource\ResultSetInterface<ContactUsFormSubmission>|false saveMany(iterable $entities, array $options = [])
|
||||
* @method iterable<ContactUsFormSubmission>|\Cake\Datasource\ResultSetInterface<ContactUsFormSubmission> saveManyOrFail(iterable $entities, array $options = [])
|
||||
* @method iterable<ContactUsFormSubmission>|\Cake\Datasource\ResultSetInterface<ContactUsFormSubmission>|false deleteMany(iterable $entities, array $options = [])
|
||||
* @method iterable<ContactUsFormSubmission>|\Cake\Datasource\ResultSetInterface<ContactUsFormSubmission> deleteManyOrFail(iterable $entities, array $options = [])
|
||||
*/
|
||||
class ContactUsFormSubmissionsTable extends Table
|
||||
{
|
||||
class ContactUsFormSubmissionsTable extends Table {
|
||||
|
||||
use MailerAwareTrait;
|
||||
|
||||
/**
|
||||
@@ -47,8 +42,7 @@ class ContactUsFormSubmissionsTable extends Table
|
||||
* @param array<string, mixed> $config The configuration for the Table.
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(array $config): void
|
||||
{
|
||||
public function initialize(array $config): void {
|
||||
parent::initialize($config);
|
||||
|
||||
$this->setTable('contact_us_form_submissions');
|
||||
@@ -59,11 +53,10 @@ class ContactUsFormSubmissionsTable extends Table
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
public function validationDefault(Validator $validator): Validator {
|
||||
$fields = Configure::readOrFail('ContactUs.fields');
|
||||
$validator
|
||||
->dateTime('submitted_at')
|
||||
@@ -116,13 +109,12 @@ class ContactUsFormSubmissionsTable extends Table
|
||||
}
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
public function afterSave(EventInterface $event, EntityInterface|ContactUsFormSubmission $contactUsFormSubmission, ArrayObject $options) {
|
||||
if (!$contactUsFormSubmission->isNew()) {
|
||||
return;
|
||||
}
|
||||
@@ -150,4 +142,5 @@ class ContactUsFormSubmissionsTable extends Table
|
||||
$this->saveOrFail($contactUsFormSubmission);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,15 +8,14 @@ use Cake\TestSuite\Fixture\TestFixture;
|
||||
/**
|
||||
* ContactUsFormSubmissionsFixture
|
||||
*/
|
||||
class ContactUsFormSubmissionsFixture extends TestFixture
|
||||
{
|
||||
class ContactUsFormSubmissionsFixture extends TestFixture {
|
||||
|
||||
/**
|
||||
* Init method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init(): void
|
||||
{
|
||||
public function init(): void {
|
||||
$this->records = [
|
||||
[
|
||||
'id' => '76fbe7fb-1949-4670-a3d2-c0b48eb98e8d',
|
||||
@@ -32,4 +31,5 @@ class ContactUsFormSubmissionsFixture extends TestFixture
|
||||
];
|
||||
parent::init();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,31 +4,41 @@ 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<string>
|
||||
*/
|
||||
protected $ContactUs;
|
||||
protected array $fixtures = [
|
||||
'plugin.CakeContactUs.ContactUsFormSubmissions',
|
||||
];
|
||||
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
$registry = new ComponentRegistry();
|
||||
$this->ContactUs = new ContactUsComponent($registry);
|
||||
$request = new ServerRequest();
|
||||
$this->controller = new Controller($request);
|
||||
$registry = new ComponentRegistry($this->controller);
|
||||
|
||||
$this->component = new ContactUsComponent($registry);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -36,10 +46,32 @@ class ContactUsComponentTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
unset($this->ContactUs);
|
||||
protected function tearDown(): void {
|
||||
unset($this->component);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,33 +3,27 @@ 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
|
||||
{
|
||||
class ContactUsFormSubmissionsControllerTest extends TestCase {
|
||||
|
||||
use IntegrationTestTrait;
|
||||
use EmailTrait;
|
||||
|
||||
/**
|
||||
* @var ContactUsFormSubmissionsTable|Table
|
||||
* @var \App\Model\Table\ContactUsFormSubmissionsTable|\Cake\ORM\Table
|
||||
*/
|
||||
protected $ContactUsFormSubmissions;
|
||||
|
||||
@@ -47,8 +41,7 @@ class ContactUsFormSubmissionsControllerTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
$this->ContactUsFormSubmissions = $this->getTableLocator()->get('ContactUsFormSubmissions');
|
||||
|
||||
@@ -60,8 +53,7 @@ class ContactUsFormSubmissionsControllerTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
protected function tearDown(): void {
|
||||
unset($this->ContactUsFormSubmissions);
|
||||
|
||||
parent::tearDown();
|
||||
@@ -72,13 +64,12 @@ class ContactUsFormSubmissionsControllerTest extends TestCase
|
||||
*
|
||||
* 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
|
||||
{
|
||||
public function testAddGet(): void {
|
||||
$cntBefore = $this->ContactUsFormSubmissions->find()->count();
|
||||
|
||||
$url = [
|
||||
@@ -100,13 +91,12 @@ class ContactUsFormSubmissionsControllerTest extends TestCase
|
||||
*
|
||||
* 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 testAddPostSuccessNoEmail(): void
|
||||
{
|
||||
public function testAddPostSuccessNoEmail(): void {
|
||||
$cntBefore = $this->ContactUsFormSubmissions->find()->count();
|
||||
|
||||
$url = [
|
||||
@@ -132,13 +122,12 @@ class ContactUsFormSubmissionsControllerTest extends TestCase
|
||||
*
|
||||
* 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
|
||||
{
|
||||
public function testAddPostSuccessBothEmailsSent(): void {
|
||||
Configure::write('ContactUs', [
|
||||
'fields' => [
|
||||
'captcha' => false,
|
||||
@@ -156,7 +145,7 @@ class ContactUsFormSubmissionsControllerTest extends TestCase
|
||||
Configure::write('EmailTransport', [
|
||||
'default' => [
|
||||
'className' => DebugTransport::class,
|
||||
]
|
||||
],
|
||||
]);
|
||||
|
||||
$cntBefore = $this->ContactUsFormSubmissions->find()->count();
|
||||
@@ -186,13 +175,12 @@ class ContactUsFormSubmissionsControllerTest extends TestCase
|
||||
*
|
||||
* 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
|
||||
{
|
||||
public function testAddPostSuccessConfirmationEmailSent(): void {
|
||||
Configure::write('ContactUs', [
|
||||
'fields' => [
|
||||
'captcha' => false,
|
||||
@@ -234,13 +222,12 @@ class ContactUsFormSubmissionsControllerTest extends TestCase
|
||||
*
|
||||
* 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
|
||||
{
|
||||
public function testAddPostSuccessBackendEmailSent(): void {
|
||||
Configure::write('ContactUs', [
|
||||
'fields' => [
|
||||
'captcha' => false,
|
||||
@@ -288,13 +275,12 @@ class ContactUsFormSubmissionsControllerTest extends TestCase
|
||||
*
|
||||
* 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
|
||||
{
|
||||
public function testAddPostLoggedInFailure(): void {
|
||||
$cntBefore = $this->ContactUsFormSubmissions->find()->count();
|
||||
|
||||
// $this->loginUserByRole('admin');
|
||||
@@ -316,4 +302,5 @@ class ContactUsFormSubmissionsControllerTest extends TestCase
|
||||
$this->assertEventFired(CakeContactUsPlugin::EVENT_BEFORE_CONTACT_US_FORM_SAVED);
|
||||
$this->assertNoMailSent();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,8 +9,8 @@ use CakeContactUs\Model\Table\ContactUsFormSubmissionsTable;
|
||||
/**
|
||||
* CakeContactUs\Model\Table\ContactUsFormSubmissionsTable Test Case
|
||||
*/
|
||||
class ContactUsFormSubmissionsTableTest extends TestCase
|
||||
{
|
||||
class ContactUsFormSubmissionsTableTest extends TestCase {
|
||||
|
||||
/**
|
||||
* Test subject
|
||||
*
|
||||
@@ -32,8 +32,7 @@ class ContactUsFormSubmissionsTableTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
$config = $this->getTableLocator()->exists('ContactUsFormSubmissions') ? [] : ['className' => ContactUsFormSubmissionsTable::class];
|
||||
$this->ContactUsFormSubmissions = $this->getTableLocator()->get('ContactUsFormSubmissions', $config);
|
||||
@@ -44,8 +43,7 @@ class ContactUsFormSubmissionsTableTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
protected function tearDown(): void {
|
||||
unset($this->ContactUsFormSubmissions);
|
||||
|
||||
parent::tearDown();
|
||||
@@ -54,11 +52,10 @@ class ContactUsFormSubmissionsTableTest extends TestCase
|
||||
/**
|
||||
* TestInitialize method
|
||||
*
|
||||
* @return void
|
||||
* @uses \CakeContactUs\Model\Table\ContactUsFormSubmissionsTable::initialize()
|
||||
* @return void
|
||||
*/
|
||||
public function testInitialize(): void
|
||||
{
|
||||
public function testInitialize(): void {
|
||||
// verify all associations loaded
|
||||
$expectedAssociations = [];
|
||||
$associations = $this->ContactUsFormSubmissions->associations();
|
||||
@@ -81,11 +78,11 @@ class ContactUsFormSubmissionsTableTest extends TestCase
|
||||
/**
|
||||
* Test validationDefault method
|
||||
*
|
||||
* @return void
|
||||
* @uses \CakeContactUs\Model\Table\ContactUsFormSubmissionsTable::validationDefault()
|
||||
* @return void
|
||||
*/
|
||||
public function testValidationDefault(): void
|
||||
{
|
||||
public function testValidationDefault(): void {
|
||||
$this->markTestIncomplete('Not implemented yet.');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ 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;
|
||||
@@ -77,7 +76,7 @@ Configure::write('ContactUs', [
|
||||
Configure::write('EmailTransport', [
|
||||
'default' => [
|
||||
'className' => DebugTransport::class,
|
||||
]
|
||||
],
|
||||
]);
|
||||
TransportFactory::setConfig('default', [
|
||||
'className' => DebugTransport::class,
|
||||
@@ -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']);
|
||||
|
||||
Reference in New Issue
Block a user