-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Cypress] Refactoring SEF Test to Avoid Using the Joomla Command-Line Client Tool #44656
base: 5.2-dev
Are you sure you want to change the base?
Changes from 2 commits
1554a64
0595b79
294c534
17f5372
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,115 +1,143 @@ | ||
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'); | ||
}); | ||
const setSefDefaults = () => cy.task('deleteRelativePath', '.htaccess') | ||
.then(() => cy.config_setParameter('sef', true)) | ||
.then(() => cy.config_setParameter('sef_suffix', false)) | ||
.then(() => cy.config_setParameter('sef_rewrite', false)) | ||
.then(() => cy.db_updateExtensionParameter('enforcesuffix', '1', 'plg_system_sef')) | ||
.then(() => cy.db_updateExtensionParameter('indexphp', '1', 'plg_system_sef')) | ||
.then(() => cy.db_updateExtensionParameter('trailingslash', '0', 'plg_system_sef')) | ||
.then(() => cy.db_updateExtensionParameter('strictrouting', '1', 'plg_system_sef')); | ||
|
||
// Ensure that we always start with a clean SEF default state | ||
beforeEach(() => setSefDefaults()); | ||
|
||
// Return to the clean SEF default state for subsequent Joomla System Tests | ||
afterEach(() => setSefDefaults()); | ||
|
||
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); | ||
}); | ||
cy.config_setParameter('sef', false) | ||
.then(() => { | ||
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); | ||
}); | ||
cy.config_setParameter('sef_suffix', true) | ||
.then(() => { | ||
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); | ||
}); | ||
cy.config_setParameter('sef_suffix', true) | ||
.then(() => cy.db_updateExtensionParameter('enforcesuffix', '0', 'plg_system_sef')) | ||
.then(() => cy.request({ url: '/index.php/component/users/login', followRedirect: false })) | ||
.then((response) => { | ||
expect(response.status).to.eq(200); | ||
}) | ||
.then(() => 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); | ||
}); | ||
cy.config_setParameter('sef_rewrite', true) | ||
.then(() => cy.task('copyRelativeFile', { source: 'htaccess.txt', destination: '.htaccess' })) | ||
.then(() => 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$/); | ||
}) | ||
.then(() => 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); | ||
}); | ||
cy.config_setParameter('sef_rewrite', true) | ||
.then(() => cy.task('copyRelativeFile', { source: 'htaccess.txt', destination: '.htaccess' })) | ||
.then(() => cy.db_updateExtensionParameter('indexphp', '0', 'plg_system_sef')) | ||
.then(() => cy.request({ url: '/index.php/component/users/login', followRedirect: false })) | ||
.then((response) => { | ||
expect(response.status).to.eq(200); | ||
}) | ||
.then(() => 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.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.db_updateExtensionParameter('trailingslash', '1', 'plg_system_sef') | ||
.then(() => 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\/$/); | ||
}) | ||
.then(() => 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); | ||
}); | ||
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); | ||
}); | ||
cy.db_updateExtensionParameter('strictrouting', '0', 'plg_system_sef') | ||
.then(() => cy.request({ url: '/index.php?option=com_users&view=login', followRedirect: false })) | ||
.then((response) => { | ||
expect(response.status).to.eq(200); | ||
}) | ||
.then(() => cy.request({ url: '/index.php/component/users/login', followRedirect: false })) | ||
.then((response) => { | ||
expect(response.status).to.eq(200); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
Cypress.Commands.add('config_setParameter', (parameter, value) => { | ||
const configPath = `${Cypress.env('cmsPath')}/configuration.php`; | ||
|
||
cy.readFile(configPath).then((fileContent) => { | ||
// Return a Cypress chainable for chaining | ||
return cy.readFile(configPath).then((fileContent) => { | ||
// Setup the new value | ||
const newValue = typeof value === 'string' ? `'${value}'` : value; | ||
|
||
|
@@ -11,7 +12,11 @@ Cypress.Commands.add('config_setParameter', (parameter, value) => { | |
// Replace the whole line with the new value | ||
const content = fileContent.replace(regex, `public $${parameter} = ${newValue};`); | ||
|
||
// Write the modified content back to the configuration file relative to the CMS root folder | ||
cy.task('writeRelativeFile', { path: 'configuration.php', content }); | ||
/* Write the modified content back to the configuration file relative to the CMS root folder and | ||
* wait for the task to complete and chain it. | ||
*/ | ||
return cy.task('writeRelativeFile', { path: 'configuration.php', content }).then((result) => { | ||
cy.log(result); // Log success message for debugging | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the Cypress GUI, I consistently see |
||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return type changed to
Promise
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the hint, it looks right as one more change and I will test it and adopt the function header, but I'm running out of time these days, come back soon ...