Skip to content

Commit

Permalink
[5.2] add test for site router (sef) (#44253)
Browse files Browse the repository at this point in the history
* [5.2] add test for site router (sef)

* use copyFileSync
  • Loading branch information
heelc29 authored Oct 30, 2024
1 parent 59dbd1a commit 0662f56
Show file tree
Hide file tree
Showing 7 changed files with 403 additions and 3 deletions.
1 change: 1 addition & 0 deletions tests/System/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ The Joomla System Tests come with some convenient [Cypress Tasks](https://docs.c
- **cleanupDB** – Deletes the inserted items from the database
- **writeRelativeFile** – Writes a file relative to the CMS root folder
- **deleteRelativePath** – Deletes a file or folder relative to the CMS root folder
- **copyRelativeFile** – Copies a file relative to the CMS root folder
- **startMailServer** – Starts the smtp-tester SMTP server
- **getMails** – Get received mails from smtp-tester
- **clearEmails** – Clear all smtp-tester received mails
Expand Down
1 change: 1 addition & 0 deletions tests/System/drone-system-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ chown -R www-data /tests/www/$TEST_GROUP/
chmod -R 777 /tests/www/$TEST_GROUP/images

echo "[RUNNER] Start Apache"
a2enmod rewrite
apache2ctl -D FOREGROUND &

echo "[RUNNER] Run cypress tests"
Expand Down
115 changes: 115 additions & 0 deletions tests/System/integration/plugins/system/sef/SefPlugin.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
describe('Test that the sef system plugin', () => {
afterEach(() => {
cy.task('deleteRelativePath', '.htaccess');
cy.exec(`php ${Cypress.env('cmsPath')}/cli/joomla.php config:set sef=true sef_suffix=false sef_rewrite=false`);
cy.db_updateExtensionParameter('enforcesuffix', '1', 'plg_system_sef');
cy.db_updateExtensionParameter('indexphp', '1', 'plg_system_sef');
cy.db_updateExtensionParameter('trailingslash', '0', 'plg_system_sef');
cy.db_updateExtensionParameter('strictrouting', '1', 'plg_system_sef');
});

it('can process if option \'sef\' disabled', () => {
cy.exec(`php ${Cypress.env('cmsPath')}/cli/joomla.php config:set sef=false`);
cy.request({ url: '/index.php?option=com_users&view=login', followRedirect: false }).then((response) => {
expect(response.status).to.eq(200);
});
cy.request({ url: '/index.php/component/users/login', failOnStatusCode: false, followRedirect: false }).then((response) => {
expect(response.status).to.eq(404);
});
});

it('can process if option \'enforcesuffix\' enabled', () => {
cy.exec(`php ${Cypress.env('cmsPath')}/cli/joomla.php config:set sef_suffix=true`);
cy.request({ url: '/index.php/component/users/login', followRedirect: false }).then((response) => {
expect(response.status).to.eq(301);
expect(response.redirectedToUrl).to.match(/\/index\.php\/component\/users\/login\.html$/);
});
cy.request({ url: '/index.php/component/users/login.html', followRedirect: false }).then((response) => {
expect(response.status).to.eq(200);
});
});

it('can process if option \'enforcesuffix\' disabled', () => {
cy.exec(`php ${Cypress.env('cmsPath')}/cli/joomla.php config:set sef_suffix=true`);
cy.db_updateExtensionParameter('enforcesuffix', '0', 'plg_system_sef');
cy.request({ url: '/index.php/component/users/login', followRedirect: false }).then((response) => {
expect(response.status).to.eq(200);
});
cy.request({ url: '/index.php/component/users/login.html', followRedirect: false }).then((response) => {
expect(response.status).to.eq(200);
});
});

it('can process if option \'indexphp\' enabled', () => {
cy.exec(`php ${Cypress.env('cmsPath')}/cli/joomla.php config:set sef_rewrite=true`);
cy.task('copyRelativeFile', { source: 'htaccess.txt', destination: '.htaccess' });
cy.request({ url: '/index.php/component/users/login', followRedirect: false }).then((response) => {
expect(response.status).to.eq(301);
expect(response.redirectedToUrl).to.match(/(?<!index\.php)\/component\/users\/login$/);
});
cy.request({ url: '/component/users/login', followRedirect: false }).then((response) => {
expect(response.status).to.eq(200);
});
});

it('can process if option \'indexphp\' disabled', () => {
cy.exec(`php ${Cypress.env('cmsPath')}/cli/joomla.php config:set sef_rewrite=true`);
cy.task('copyRelativeFile', { source: 'htaccess.txt', destination: '.htaccess' });
cy.db_updateExtensionParameter('indexphp', '0', 'plg_system_sef');
cy.request({ url: '/index.php/component/users/login', followRedirect: false }).then((response) => {
expect(response.status).to.eq(200);
});
cy.request({ url: '/component/users/login', followRedirect: false }).then((response) => {
expect(response.status).to.eq(200);
});
});

it('can process if option \'trailingslash\' disabled', () => {
cy.request({ url: '/index.php/component/users/login/', followRedirect: false }).then((response) => {
expect(response.status).to.eq(301);
expect(response.redirectedToUrl).to.match(/\/index\.php\/component\/users\/login$/);
});
cy.request({ url: '/index.php/component/users/login', followRedirect: false }).then((response) => {
expect(response.status).to.eq(200);
});
cy.visit('/');
cy.get('li.nav-item').contains('Home')
.should('have.attr', 'href')
.and('match', /\/index\.php$/);
});

it('can process if option \'trailingslash\' enabled', () => {
cy.db_updateExtensionParameter('trailingslash', '1', 'plg_system_sef');
cy.request({ url: '/index.php/component/users/login', followRedirect: false }).then((response) => {
expect(response.status).to.eq(301);
expect(response.redirectedToUrl).to.match(/\/index\.php\/component\/users\/login\/$/);
});
cy.request({ url: '/index.php/component/users/login/', followRedirect: false }).then((response) => {
expect(response.status).to.eq(200);
});
cy.visit('/');
cy.get('li.nav-item').contains('Home')
.should('have.attr', 'href')
.and('match', /\/index\.php\/$/);
});

it('can process if option \'strictrouting\' enabled', () => {
cy.request({ url: '/index.php?option=com_users&view=login', followRedirect: false }).then((response) => {
expect(response.status).to.eq(301);
expect(response.redirectedToUrl).to.match(/\/index\.php\/component\/users\/login$/);
});
cy.request({ url: '/index.php/component/users/login', followRedirect: false }).then((response) => {
expect(response.status).to.eq(200);
});
});

it('can process if option \'strictrouting\' disabled', () => {
cy.db_updateExtensionParameter('strictrouting', '0', 'plg_system_sef');
cy.request({ url: '/index.php?option=com_users&view=login', followRedirect: false }).then((response) => {
expect(response.status).to.eq(200);
});
cy.request({ url: '/index.php/component/users/login', followRedirect: false }).then((response) => {
expect(response.status).to.eq(200);
});
});
});
132 changes: 132 additions & 0 deletions tests/System/integration/site/components/com_contact/Router.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
describe('Test in frontend that the contact site router', () => {
it('can process contact without a menu item', () => {
cy.db_createContact({ name: 'Test Contact', alias: 'test-contact-router' }).then((contact) => {
cy.request({ url: `/index.php?option=com_contact&view=contact&id=${contact.id}`, followRedirect: false }).then((response) => {
expect(response.status).to.eq(301);
expect(response.redirectedToUrl).to.match(/\/index\.php\/component\/contact\/contact\/test-contact-router$/);
});

cy.visit('/index.php/component/contact/contact/test-contact-router');
cy.url().should('match', /\/index\.php\/component\/contact\/contact\/test-contact-router$/);
cy.title().should('equal', 'Test Contact');
cy.get('main h1').contains('Home');
cy.get('main h2').contains('Test Contact');
cy.get('main h3').contains('Contact');
cy.get('nav.mod-breadcrumbs__wrapper ol.mod-breadcrumbs').children().as('breadcrumb');
cy.get('@breadcrumb').should('have.length', 4);
cy.get('@breadcrumb').eq(2).should('contain', 'Uncategorised');
cy.get('@breadcrumb').eq(3).should('contain', 'Test Contact');
});
});

it('can process contact with a single contact menu item', () => {
cy.db_createContact({ name: 'Test Contact', alias: 'test-contact-router' }).then((contact) => {
cy.db_createMenuItem({
title: 'Test Menu Single Contact',
alias: 'test-menu-contact-router',
path: 'test-menu-contact-router',
link: `index.php?option=com_contact&view=contact&id=${contact.id}`,
});
cy.request({ url: `/index.php?option=com_contact&view=contact&id=${contact.id}&catid=${contact.catid}`, followRedirect: false }).then((response) => {
expect(response.status).to.eq(301);
expect(response.redirectedToUrl).to.match(/\/index\.php\/test-menu-contact-router$/);
});

cy.visit('/index.php/test-menu-contact-router');
cy.url().should('match', /\/index\.php\/test-menu-contact-router$/);
cy.title().should('equal', 'Test Menu Single Contact');
cy.get('main h1').contains('Test Contact');
cy.get('main h2').contains('Contact');
cy.get('nav.mod-breadcrumbs__wrapper ol.mod-breadcrumbs').children().as('breadcrumb');
cy.get('@breadcrumb').should('have.length', 3);
cy.get('@breadcrumb').eq(2).should('contain', 'Test Menu Single Contact');
});
});

it('can process contact with a category list menu item', () => {
cy.db_createContact({ name: 'Test Contact', alias: 'test-contact-router' }).then((contact) => {
cy.db_createMenuItem({
title: 'Test Menu Contact Category',
alias: 'test-menu-category-router',
path: 'test-menu-category-router',
link: `index.php?option=com_contact&view=category&id=${contact.catid}`,
});
cy.request({ url: `/index.php?option=com_contact&view=contact&id=${contact.id}&catid=${contact.catid}`, followRedirect: false }).then((response) => {
expect(response.status).to.eq(301);
expect(response.redirectedToUrl).to.match(/\/index\.php\/test-menu-category-router\/test-contact-router$/);
});

cy.visit('/index.php/test-menu-category-router');
cy.url().should('match', /\/index\.php\/test-menu-category-router$/);
cy.title().should('equal', 'Test Menu Contact Category');
cy.get('main h1').contains('Uncategorised');
cy.get('nav.mod-breadcrumbs__wrapper ol.mod-breadcrumbs').children().as('breadcrumb');
cy.get('@breadcrumb').should('have.length', 3);
cy.get('@breadcrumb').eq(2).should('contain', 'Test Menu Contact Category');
cy.get('main div.com-contact-category a')
.contains('Test Contact')
.should('have.attr', 'href')
.and('match', /\/index\.php\/test-menu-category-router\/test-contact-router$/);

cy.visit('/index.php/test-menu-category-router/test-contact-router');
cy.url().should('match', /\/index\.php\/test-menu-category-router\/test-contact-router$/);
cy.title().should('equal', 'Test Contact');
cy.get('main h1').contains('Test Contact');
cy.get('main h2').contains('Contact');
cy.get('nav.mod-breadcrumbs__wrapper ol.mod-breadcrumbs').children().as('breadcrumb');
cy.get('@breadcrumb').should('have.length', 4);
cy.get('@breadcrumb').eq(2).should('contain', 'Test Menu Contact Category');
cy.get('@breadcrumb').eq(3).should('contain', 'Test Contact');
});
});

it('can process contact with a categories list menu item', () => {
cy.db_createContact({ name: 'Test Contact', alias: 'test-contact-router' }).then((contact) => {
cy.db_createMenuItem({
title: 'Test Menu Contact Categories',
alias: 'test-menu-categories-router',
path: 'test-menu-categories-router',
link: 'index.php?option=com_contact&view=categories&id=0',
});
cy.request({ url: `/index.php?option=com_contact&view=contact&id=${contact.id}&catid=${contact.catid}`, followRedirect: false }).then((response) => {
expect(response.status).to.eq(301);
expect(response.redirectedToUrl).to.match(/\/index\.php\/test-menu-categories-router\/uncategorised\/test-contact-router$/);
});

cy.visit('/index.php/test-menu-categories-router');
cy.url().should('match', /\/index\.php\/test-menu-categories-router$/);
cy.title().should('equal', 'Test Menu Contact Categories');
cy.get('nav.mod-breadcrumbs__wrapper ol.mod-breadcrumbs').children().as('breadcrumb');
cy.get('@breadcrumb').should('have.length', 3);
cy.get('@breadcrumb').eq(2).should('contain', 'Test Menu Contact Categories');
cy.get('main div.com-contact-categories h3 a')
.contains('Uncategorised')
.should('have.attr', 'href')
.and('match', /\/index\.php\/test-menu-categories-router\/uncategorised$/);

cy.visit('/index.php/test-menu-categories-router/uncategorised');
cy.url().should('match', /\/index\.php\/test-menu-categories-router\/uncategorised$/);
cy.title().should('equal', 'Test Menu Contact Categories');
cy.get('main h1').contains('Uncategorised');
cy.get('nav.mod-breadcrumbs__wrapper ol.mod-breadcrumbs').children().as('breadcrumb');
cy.get('@breadcrumb').should('have.length', 4);
cy.get('@breadcrumb').eq(2).should('contain', 'Test Menu Contact Categories');
cy.get('@breadcrumb').eq(3).should('contain', 'Uncategorised');
cy.get('main div.com-contact-category a')
.contains('Test Contact')
.should('have.attr', 'href')
.and('match', /\/index\.php\/test-menu-categories-router\/uncategorised\/test-contact-router$/);

cy.visit('/index.php/test-menu-categories-router/uncategorised/test-contact-router');
cy.url().should('match', /\/index\.php\/test-menu-categories-router\/uncategorised\/test-contact-router$/);
cy.title().should('equal', 'Test Contact');
cy.get('main h1').contains('Test Contact');
cy.get('main h2').contains('Contact');
cy.get('nav.mod-breadcrumbs__wrapper ol.mod-breadcrumbs').children().as('breadcrumb');
cy.get('@breadcrumb').should('have.length', 5);
cy.get('@breadcrumb').eq(2).should('contain', 'Test Menu Contact Categories');
cy.get('@breadcrumb').eq(3).should('contain', 'Uncategorised');
cy.get('@breadcrumb').eq(4).should('contain', 'Test Contact');
});
});
});
Loading

0 comments on commit 0662f56

Please sign in to comment.