Skip to content

Commit

Permalink
Merge branch '4.4-dev' into 5.0/upmerge
Browse files Browse the repository at this point in the history
  • Loading branch information
HLeithner committed Aug 14, 2023
2 parents 6ba6cbd + fcc7209 commit e4d90cf
Show file tree
Hide file tree
Showing 15 changed files with 477 additions and 222 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ public function &getTemplate()
$this->template->client_id = (int) $this->template->client_id;

if (!isset($this->template->xmldata)) {
$this->template->xmldata = TemplatesHelper::parseXMLTemplateFile($this->template->client_id === 0 ? JPATH_ROOT : JPATH_ROOT . '/administrator', $this->template->name);
$this->template->xmldata = TemplatesHelper::parseXMLTemplateFile($this->template->client_id === 0 ? JPATH_ROOT : JPATH_ROOT . '/administrator', $this->template->element);
}
}
}
Expand Down Expand Up @@ -1799,7 +1799,7 @@ public function getMediaFiles()
$template = $this->getTemplate();

if (!isset($template->xmldata)) {
$template->xmldata = TemplatesHelper::parseXMLTemplateFile($template->client_id === 0 ? JPATH_ROOT : JPATH_ROOT . '/administrator', $template->name);
$template->xmldata = TemplatesHelper::parseXMLTemplateFile($template->client_id === 0 ? JPATH_ROOT : JPATH_ROOT . '/administrator', $template->element);
}

if (!isset($template->xmldata->inheritable) || (isset($template->xmldata->parent) && $template->xmldata->parent === '')) {
Expand Down
34 changes: 34 additions & 0 deletions libraries/src/Event/AbstractEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,23 @@ public function __construct(string $name, array $arguments = [])
*/
public function getArgument($name, $default = null)
{
// B/C check for numeric access to named argument, eg $event->getArgument('0').
if (is_numeric($name)) {
if (key($this->arguments) != 0) {
$argNames = \array_keys($this->arguments);
$name = $argNames[$name] ?? '';
}

@trigger_error(
sprintf(
'Numeric access to named event arguments is deprecated, and will not work in Joomla 6. Event %s argument %s',
\get_class($this),
$name
),
E_USER_DEPRECATED
);
}

$methodName = 'get' . ucfirst($name);

$value = parent::getArgument($name, $default);
Expand Down Expand Up @@ -167,6 +184,23 @@ public function getArgument($name, $default = null)
*/
public function setArgument($name, $value)
{
// B/C check for numeric access to named argument, eg $event->setArgument('0', $value).
if (is_numeric($name)) {
if (key($this->arguments) != 0) {
$argNames = \array_keys($this->arguments);
$name = $argNames[$name] ?? '';
}

@trigger_error(
sprintf(
'Numeric access to named event arguments is deprecated, and will not work in Joomla 6. Event %s argument %s',
\get_class($this),
$name
),
E_USER_DEPRECATED
);
}

$methodName = 'set' . ucfirst($name);

if (method_exists($this, $methodName)) {
Expand Down
12 changes: 9 additions & 3 deletions libraries/src/Plugin/CMSPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
namespace Joomla\CMS\Plugin;

use Joomla\CMS\Application\CMSApplicationInterface;
use Joomla\CMS\Event\AbstractImmutableEvent;
use Joomla\CMS\Event\Result\ResultAwareInterface;
use Joomla\CMS\Extension\PluginInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\LanguageAwareInterface;
Expand Down Expand Up @@ -291,9 +293,13 @@ function (AbstractEvent $event) use ($methodName) {
return;
}

// Restore the old results and add the new result from our method call
$allResults[] = $result;
$event['result'] = $allResults;
if ($event instanceof ResultAwareInterface) {
$event->addResult($result);
} elseif (!$event instanceof AbstractImmutableEvent) {
// Restore the old results and add the new result from our method call
$allResults[] = $result;
$event['result'] = $allResults;
}
}
);
}
Expand Down
8 changes: 8 additions & 0 deletions tests/System/integration/api/com_banners/Banners.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ describe('Test that banners API endpoint', () => {
.should('include', 'automated test banner'));
});

it('can deliver a single banner', () => {
cy.db_createBanner({ name: 'automated test banner' })
.then((banner) => cy.api_get(`/banners/${banner.id}`))
.then((response) => cy.wrap(response).its('body').its('data').its('attributes')
.its('name')
.should('include', 'automated test banner'));
});

it('can create a banner', () => {
cy.db_createCategory({ extension: 'com_banners' })
.then((categoryId) => cy.api_post('/banners', {
Expand Down
31 changes: 28 additions & 3 deletions tests/System/integration/api/com_banners/Categories.cy.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,33 @@
describe('Test that content categories API endpoint', () => {
describe('Test that banners categories API endpoint', () => {
afterEach(() => cy.task('queryDB', "DELETE FROM #__categories WHERE title = 'automated test banner category'"));

it('can display a list of categories', () => {
cy.db_createCategory({ title: 'automated test category', extension: 'com_banners' })
cy.db_createCategory({ title: 'automated test banner category', extension: 'com_banners' })
.then((id) => cy.db_createBanner({ name: 'automated test banner', catid: id }))
.then(() => cy.api_get('/banners/categories'))
.then((response) => cy.api_responseContains(response, 'title', 'automated test category'));
.then((response) => cy.api_responseContains(response, 'title', 'automated test banner category'));
});

it('can display a single category', () => {
cy.db_createCategory({ title: 'automated test banner category', extension: 'com_banners' })
.then((id) => cy.api_get(`/banners/categories/${id}`))
.then((response) => cy.wrap(response).its('body').its('data').its('attributes')
.its('title')
.should('include', 'automated test banner category'));
});

it('can create a category', () => {
cy.api_post('/banners/categories', { title: 'automated test banner category' })
.then((response) => cy.wrap(response).its('body').its('data').its('attributes')
.its('title')
.should('include', 'automated test banner category'));
});

it('can update a category', () => {
cy.db_createCategory({ title: 'automated test banner category', extension: 'com_banners' })
.then((id) => cy.api_patch(`/banners/categories/${id}`, { title: 'updated automated test banner category' }))
.then((response) => cy.wrap(response).its('body').its('data').its('attributes')
.its('title')
.should('include', 'updated automated test banner category'));
});
});
44 changes: 44 additions & 0 deletions tests/System/integration/api/com_banners/Clients.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
describe('Test that banners clients API endpoint', () => {
afterEach(() => cy.task('queryDB', 'DELETE FROM #__banner_clients'));

it('can deliver a list of clients', () => {
cy.db_createBannerClient({ name: 'automated test banner client' })
.then(() => cy.api_get('/banners/clients'))
.then((response) => cy.wrap(response).its('body').its('data.0').its('attributes')
.its('name')
.should('include', 'automated test banner client'));
});

it('can deliver a single client', () => {
cy.db_createBannerClient({ name: 'automated test banner client' })
.then((bannerclient) => cy.api_get(`/banners/clients/${bannerclient.id}`))
.then((response) => cy.wrap(response).its('body').its('data').its('attributes')
.its('name')
.should('include', 'automated test banner client'));
});

it('can create a client', () => {
cy.api_post('/banners/clients', {
name: 'automated test banner client',
contact: 'automated test banner client',
state: 1,
extrainfo: '',
})
.then((response) => cy.wrap(response).its('body').its('data').its('attributes')
.its('name')
.should('include', 'automated test banner client'));
});

it('can update a client', () => {
cy.db_createBannerClient({ name: 'automated test banner client' })
.then((bannerclient) => cy.api_patch(`/banners/clients/${bannerclient.id}`, { name: 'updated automated test banner client' }))
.then((response) => cy.wrap(response).its('body').its('data').its('attributes')
.its('name')
.should('include', 'updated automated test banner client'));
});

it('can delete a client', () => {
cy.db_createBannerClient({ name: 'automated test banner client', state: -2 })
.then((bannerclient) => cy.api_delete(`/banners/clients/${bannerclient.id}`));
});
});
31 changes: 28 additions & 3 deletions tests/System/integration/api/com_contact/Categories.cy.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,33 @@
describe('Test that content categories API endpoint', () => {
describe('Test that contact categories API endpoint', () => {
afterEach(() => cy.task('queryDB', "DELETE FROM #__categories WHERE title = 'automated test contact category'"));

it('can display a list of categories', () => {
cy.db_createCategory({ title: 'automated test category', extension: 'com_contact' })
cy.db_createCategory({ title: 'automated test contact category', extension: 'com_contact' })
.then((id) => cy.db_createContact({ name: 'automated test contact', catid: id }))
.then(() => cy.api_get('/contacts/categories'))
.then((response) => cy.api_responseContains(response, 'title', 'automated test category'));
.then((response) => cy.api_responseContains(response, 'title', 'automated test contact category'));
});

it('can display a single category', () => {
cy.db_createCategory({ title: 'automated test contact category', extension: 'com_contact' })
.then((id) => cy.api_get(`/contacts/categories/${id}`))
.then((response) => cy.wrap(response).its('body').its('data').its('attributes')
.its('title')
.should('include', 'automated test contact category'));
});

it('can create a category', () => {
cy.api_post('/contacts/categories', { title: 'automated test contact category' })
.then((response) => cy.wrap(response).its('body').its('data').its('attributes')
.its('title')
.should('include', 'automated test contact category'));
});

it('can update a category', () => {
cy.db_createCategory({ title: 'automated test contact category', extension: 'com_contact' })
.then((id) => cy.api_patch(`/contacts/categories/${id}`, { title: 'updated automated test contact category' }))
.then((response) => cy.wrap(response).its('body').its('data').its('attributes')
.its('title')
.should('include', 'updated automated test contact category'));
});
});
33 changes: 32 additions & 1 deletion tests/System/integration/api/com_contact/Contacts.cy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
describe('Test that contacts API endpoint', () => {
beforeEach(() => cy.task('clearEmails'));
afterEach(() => cy.task('queryDB', 'DELETE FROM #__contact_details'));

it('can deliver a list of contacts', () => {
Expand All @@ -9,8 +10,16 @@ describe('Test that contacts API endpoint', () => {
.should('include', 'automated test contact'));
});

it('can deliver a single contact', () => {
cy.db_createContact({ name: 'automated test contact' })
.then((contact) => cy.api_get(`/contacts/${contact.id}`))
.then((response) => cy.wrap(response).its('body').its('data').its('attributes')
.its('name')
.should('include', 'automated test contact'));
});

it('can create a contact', () => {
cy.db_createCategory({ extension: 'com_contacts' })
cy.db_createCategory({ extension: 'com_contact' })
.then((categoryId) => cy.api_post('/contacts', {
name: 'automated test contact',
alias: 'test-contact',
Expand All @@ -35,4 +44,26 @@ describe('Test that contacts API endpoint', () => {
cy.db_createContact({ name: 'automated test contact', published: -2 })
.then((contact) => cy.api_delete(`/contacts/${contact.id}`));
});

it('can submit a contact form', () => {
cy.db_getUserId().then((id) => cy.db_createContact({ name: 'automated test contact', user_id: id, params: '{"show_email_form":"1"}' }))
.then((contact) => cy.api_post(`/contacts/form/${contact.id}`, {
contact_name: Cypress.env('name'),
contact_email: Cypress.env('email'),
contact_subject: 'automated test subject',
contact_message: 'automated test message',
}))
.then((response) => cy.wrap(response).its('status')
.should('equal', 200));

cy.task('getMails').then((mails) => {
cy.wrap(mails).should('have.lengthOf', 1);
cy.wrap(mails[0].sender).should('equal', Cypress.env('email'));
cy.wrap(mails[0].receivers).should('have.property', Cypress.env('email'));
cy.wrap(mails[0].headers.subject).should('equal', `${Cypress.env('sitename')}: automated test subject`);
cy.wrap(mails[0].body).should('have.string', 'This is an enquiry email via');
cy.wrap(mails[0].body).should('have.string', `${Cypress.env('name')} <${Cypress.env('email')}>`);
cy.wrap(mails[0].body).should('have.string', 'automated test message');
});
});
});
112 changes: 61 additions & 51 deletions tests/System/integration/api/com_contact/Field_Group.cy.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,69 @@
describe('Test that group field contact API endpoint', () => {
afterEach(() => cy.task('queryDB', 'DELETE FROM #__fields_groups'));

it('can deliver a list of group fields', () => {
cy.db_createFieldGroup({ title: 'automated test group field', context: 'com_contact.contact' })
.then(() => cy.api_get('/fields/groups/contacts/contact'))
.then((response) => cy.wrap(response).its('body').its('data.0').its('attributes')
.its('title')
.should('include', 'automated test group field'));
});
['contact', 'mail', 'categories'].forEach((context) => {
it(`can deliver a list of group fields (${context})`, () => {
cy.db_createFieldGroup({ title: `automated test group field contacts ${context}`, context: `com_contact.${context}` })
.then(() => cy.api_get(`/fields/groups/contacts/${context}`))
.then((response) => cy.wrap(response).its('body').its('data.0').its('attributes')
.its('title')
.should('include', `automated test group field contacts ${context}`));
});

it.only('can create a group field', () => {
cy.api_post('/fields/groups/contacts/contact', {
title: 'automated test group field',
access: 1,
context: 'com_contact.contact',
default_value: '',
description: '',
group_id: 0,
label: 'contact group field',
language: '*',
name: 'contact-group_field',
note: '',
params: {
class: '',
display: '2',
display_readonly: '2',
hint: '',
label_class: '',
label_render_class: '',
layout: '',
prefix: '',
render_class: '',
show_on: '',
showlabel: '1',
suffix: '',
},
required: 0,
state: 1,
type: 'text',
})
.then((response) => cy.wrap(response).its('body').its('data').its('attributes')
.its('title')
.should('include', 'automated test group field'));
});
it(`can deliver a single group field (${context})`, () => {
cy.db_createFieldGroup({ title: `automated test group field contacts ${context}`, context: `com_contact.${context}` })
.then((id) => cy.api_get(`/fields/groups/contacts/${context}/${id}`))
.then((response) => cy.wrap(response).its('body').its('data').its('attributes')
.its('title')
.should('include', `automated test group field contacts ${context}`));
});

it('can update a group field', () => {
cy.db_createFieldGroup({ title: 'automated test group field', access: 1, context: 'com_contact.contact' })
.then((id) => cy.api_patch(`/fields/groups/contacts/contact/${id}`, { title: 'updated automated test group field', context: 'com_contact.contact' }))
.then((response) => cy.wrap(response).its('body').its('data').its('attributes')
.its('title')
.should('include', 'updated automated test group field'));
});
it(`can create a group field (${context})`, () => {
cy.api_post(`/fields/groups/contacts/${context}`, {
title: `automated test group field contacts ${context}`,
access: 1,
context: `com_contact.${context}`,
default_value: '',
description: '',
group_id: 0,
label: 'contact group field',
language: '*',
name: 'contact-group_field',
note: '',
params: {
class: '',
display: '2',
display_readonly: '2',
hint: '',
label_class: '',
label_render_class: '',
layout: '',
prefix: '',
render_class: '',
show_on: '',
showlabel: '1',
suffix: '',
},
required: 0,
state: 1,
type: 'text',
})
.then((response) => cy.wrap(response).its('body').its('data').its('attributes')
.its('title')
.should('include', `automated test group field contacts ${context}`));
});

it(`can update a group field (${context})`, () => {
cy.db_createFieldGroup({ title: 'automated test group field', access: 1, context: `com_contact.${context}` })
.then((id) => cy.api_patch(`/fields/groups/contacts/${context}/${id}`, { title: `updated automated test group field ${context}` }))
.then((response) => cy.wrap(response).its('body').its('data').its('attributes')
.its('title')
.should('include', `updated automated test group field ${context}`));
});

it('can delete a group field', () => {
cy.db_createFieldGroup({ title: 'automated test group field', state: -2 })
.then((id) => cy.api_delete(`/fields/groups/contacts/contact/${id}`));
it(`can delete a group field (${context})`, () => {
cy.db_createFieldGroup({ title: 'automated test group field', context: `com_contact.${context}`, state: -2 })
.then((id) => cy.api_delete(`/fields/groups/contacts/${context}/${id}`));
});
});
});

0 comments on commit e4d90cf

Please sign in to comment.