Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/plugins/contact/customreply/services/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/contact/customreply/src/Extension/CustomReply.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -40,6 +41,7 @@
final class CustomReply extends CMSPlugin implements SubscriberInterface
{
use DatabaseAwareTrait;
use UserFactoryAwareTrait;

/**
* Application object
Expand Down
54 changes: 54 additions & 0 deletions tests/cypress/integration/plugins/ContactCustomReply.cy.js
Original file line number Diff line number Diff line change
@@ -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();
Comment on lines +25 to +26

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (testing): Consider asserting on the UI success state after form submission, not only on the email side effect.

These tests only assert on the resulting emails, not on the frontend behavior (success message, lack of validation errors, redirect, etc.). Please add a UI assertion (for example, cy.contains('Thank you for your message') or a selector-based check) to verify the user-facing flow and better protect against regressions where the email is sent but the UI fails.

Suggested implementation:

        cy.get('#jform_contact_message').type('Test message content');
        cy.get('button.btn.btn-primary.validate[type="submit"]').click();

        // Assert on the UI success state to verify the user-facing flow
        cy.contains('Thank you for your message').should('be.visible');

        cy.task('getMails').then((mails) => {
  1. If the actual success message text in your Joomla setup differs from 'Thank you for your message', update the string in cy.contains(...) to match the real UI copy.
  2. Alternatively, if there's a stable success-alert selector (e.g. .alert-success), you can tighten the assertion to something like:
    cy.get('.alert-success').should('contain', 'Thank you for your message');


cy.task('getMails').then((mails) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (testing): Differentiate the custom reply test from the non-custom case by asserting plugin-specific behavior.

This mostly duplicates the can send an email on contact form submission test, just with the plugin enabled. To validate the custom reply behavior, please add at least one assertion that’s specific to the plugin, such as:

  • Expecting an extra email (e.g., admin + auto-reply).
  • Verifying one email is sent to testuser@example.com.
  • Checking for text or a marker introduced by the custom reply plugin.
    Otherwise, the test can still pass even if the custom reply logic is broken, as long as the base contact email works.

expect(mails.length).to.be.greaterThan(0);
cy.wrap(mails[0].body).should('contain', 'Test message content');
});
Comment on lines +26 to +31

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (testing): Strengthen assertions on the outgoing email (count, recipient, subject) to better prove the behavior.

Right now the test only checks that at least one email is sent and that the first email body contains the message text. Please also assert the exact number of emails, that the recipient matches the configured contact address, and that the subject matches (or includes) the submitted Test Subject. These checks will better guard against regressions in email routing or templating.

Suggested change
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');
});
cy.get('button.btn.btn-primary.validate[type="submit"]').click();
cy.task('getMails').then((mails) => {
expect(mails).to.have.length(1);
const mail = mails[0];
if (contact.email_to) {
expect(mail.to).to.contain(contact.email_to);
}
expect(mail.subject).to.contain('Test Subject');
expect(mail.body).to.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');
});
});
});
});
2 changes: 1 addition & 1 deletion tests/cypress/integration/plugins/MagicLogin.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Loading