diff --git a/src/plugins/contact/customreply/services/provider.php b/src/plugins/contact/customreply/services/provider.php index 50cf569..cad24f8 100644 --- a/src/plugins/contact/customreply/services/provider.php +++ b/src/plugins/contact/customreply/services/provider.php @@ -16,6 +16,7 @@ use Joomla\CMS\Extension\PluginInterface; use Joomla\CMS\Factory; use Joomla\CMS\Plugin\PluginHelper; +use Joomla\CMS\User\UserFactoryInterface; use Joomla\DI\Container; use Joomla\DI\ServiceProviderInterface; use Joomla\Event\DispatcherInterface; @@ -60,6 +61,7 @@ function (Container $container) { $plugin = new CustomReply($subject, $config); $plugin->setApplication(Factory::getApplication()); $plugin->setDatabase($container->get('DatabaseDriver')); + $plugin->setUserFactory($container->get(UserFactoryInterface::class)); return $plugin; } diff --git a/src/plugins/contact/customreply/src/Extension/CustomReply.php b/src/plugins/contact/customreply/src/Extension/CustomReply.php index c9adb55..7326a0c 100644 --- a/src/plugins/contact/customreply/src/Extension/CustomReply.php +++ b/src/plugins/contact/customreply/src/Extension/CustomReply.php @@ -23,6 +23,7 @@ use Joomla\CMS\Plugin\CMSPlugin; use Joomla\CMS\String\PunycodeHelper; use Joomla\CMS\Uri\Uri; +use Joomla\CMS\User\UserFactoryAwareTrait; use Joomla\Database\DatabaseAwareTrait; use Joomla\Event\SubscriberInterface; @@ -40,6 +41,7 @@ final class CustomReply extends CMSPlugin implements SubscriberInterface { use DatabaseAwareTrait; + use UserFactoryAwareTrait; /** * Application object diff --git a/tests/cypress/integration/plugins/ContactCustomReply.cy.js b/tests/cypress/integration/plugins/ContactCustomReply.cy.js new file mode 100644 index 0000000..f8529f4 --- /dev/null +++ b/tests/cypress/integration/plugins/ContactCustomReply.cy.js @@ -0,0 +1,54 @@ +describe('Test in frontend that the contact form view', () => { + afterEach(() => cy.task('queryDB', 'DELETE FROM #__contact_details')); + + it('can create a contact through a form', () => { + cy.doFrontendLogin(); + cy.visit('/index.php?option=com_contact&view=form&layout=edit'); + cy.get('#jform_name').type('test contact 1'); + cy.get('.mb-2 > .btn-primary').click(); + + cy.task('queryDB', 'SELECT catid FROM #__contact_details WHERE name = \'test contact 1\'').then((id) => { + cy.visit(`/index.php?option=com_contact&view=category&id=${id[0].catid}`); + + cy.contains('test contact 1').should('exist'); + }); + }); + + it('can send an email on contact form submission', () => { + cy.task('clearEmails'); + cy.db_getUserId().then((id) => cy.db_createContact({ name: 'test contact', user_id: id })) + .then((contact) => { + cy.visit(`/index.php?option=com_contact&view=contact&id=${contact.id}`); + cy.get('#jform_contact_name').type('Test User'); + cy.get('#jform_contact_email').type('testuser@example.com'); + cy.get('#jform_contact_emailmsg').type('Test Subject'); + cy.get('#jform_contact_message').type('Test message content'); + cy.get('button.btn.btn-primary.validate[type="submit"]').click(); + + cy.task('getMails').then((mails) => { + expect(mails.length).to.be.greaterThan(0); + cy.wrap(mails[0].body).should('contain', 'Test message content'); + }); + }); + }); + + it('can send an email on contact form submission with custom reply enabled', () => { + cy.task('clearEmails'); + cy.db_updateExtensionParameter('custom_reply', '1', 'com_contact'); + cy.db_enableExtension('1', 'plg_contact_customreply'); + cy.db_getUserId().then((id) => cy.db_createContact({ name: 'test contact', user_id: id })) + .then((contact) => { + cy.visit(`/index.php?option=com_contact&view=contact&id=${contact.id}`); + cy.get('#jform_contact_name').type('Test User'); + cy.get('#jform_contact_email').type('testuser@example.com'); + cy.get('#jform_contact_emailmsg').type('Test Subject'); + cy.get('#jform_contact_message').type('Test message content'); + cy.get('button.btn.btn-primary.validate[type="submit"]').click(); + + cy.task('getMails').then((mails) => { + expect(mails.length).to.be.greaterThan(0); + cy.wrap(mails[0].body).should('contain', 'Test message content'); + }); + }); + }); +}); diff --git a/tests/cypress/integration/plugins/MagicLogin.cy.js b/tests/cypress/integration/plugins/MagicLogin.cy.js index a7c35db..aac7a02 100644 --- a/tests/cypress/integration/plugins/MagicLogin.cy.js +++ b/tests/cypress/integration/plugins/MagicLogin.cy.js @@ -24,7 +24,7 @@ describe('Test that the magiclogin system plugin', () => { it('sends magic link when user enters email address', () => { cy.db_createUser({ name: 'Magic User', username: 'magicuser', email: 'magic@example.com', password: '098f6bcd4621d373cade4e832627b4f6' }); - + cy.task('clearEmails'); cy.visit('/index.php?option=com_users&view=login'); cy.get('#username').type('magic@example.com'); cy.get('#password').type('1');