diff --git a/components/com_contact/src/View/Category/HtmlView.php b/components/com_contact/src/View/Category/HtmlView.php index 2ab162e8fcc1e..a179b37101f02 100644 --- a/components/com_contact/src/View/Category/HtmlView.php +++ b/components/com_contact/src/View/Category/HtmlView.php @@ -14,6 +14,7 @@ use Joomla\CMS\Mail\MailHelper; use Joomla\CMS\MVC\View\CategoryView; use Joomla\Component\Contact\Site\Helper\RouteHelper; +use Joomla\Registry\Registry; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -97,6 +98,16 @@ protected function prepareDocument() { parent::prepareDocument(); + if (!\is_object($this->category->metadata)) { + $this->category->metadata = new Registry($this->category->metadata); + } + + foreach ($this->category->metadata->toArray() as $k => $v) { + if ($v) { + $this->getDocument()->setMetaData($k, $v); + } + } + $this->addFeed(); if ($this->menuItemMatchCategory) { diff --git a/tests/System/integration/site/components/com_contact/Category.cy.js b/tests/System/integration/site/components/com_contact/Category.cy.js index 5e8914b00440d..e5ced239e6b42 100644 --- a/tests/System/integration/site/components/com_contact/Category.cy.js +++ b/tests/System/integration/site/components/com_contact/Category.cy.js @@ -43,4 +43,15 @@ describe('Test in frontend that the contact category view', () => { cy.get('#adminForm').should('exist'); }); }); + + it('applies the robots metadata of the category to the category page', () => { + cy.db_createContact({ name: 'automated test contact 1' }) + .then((contact) => cy.task('queryDB', `UPDATE #__categories SET metadata = '{"robots":"noindex, follow"}' WHERE id = ${contact.catid}`) + .then(() => { + cy.visit(`/index.php?option=com_contact&view=category&id=${contact.catid}`); + + cy.get('head meta[name="robots"]').should('have.attr', 'content', 'noindex, follow'); + }) + .then(() => cy.task('queryDB', `UPDATE #__categories SET metadata = '' WHERE id = ${contact.catid}`))); + }); });