From 8a5658a2dcdb944ddc938607a38e433567d99f9e Mon Sep 17 00:00:00 2001 From: Osma Suominen Date: Wed, 21 Aug 2024 11:06:52 +0300 Subject: [PATCH 1/7] add vocabulary description metadata from config.ttl to vocab-home page --- src/model/VocabularyConfig.php | 9 +++++++++ src/view/vocab-home.twig | 1 + tests/VocabularyConfigTest.php | 9 +++++++++ tests/cypress/template/vocab-home.cy.js | 9 +++++++++ tests/testconfig.ttl | 1 + 5 files changed, 29 insertions(+) diff --git a/src/model/VocabularyConfig.php b/src/model/VocabularyConfig.php index f1ba881fe..bd0323b86 100644 --- a/src/model/VocabularyConfig.php +++ b/src/model/VocabularyConfig.php @@ -271,6 +271,15 @@ public function getTitle($lang = null) return $this->getLiteral('dc:title', false, $lang); } + /** + * Returns the human readable vocabulary description. + * @return string the description of the vocabulary + */ + public function getDescription($lang = null) + { + return $this->getLiteral('dc:description', false, $lang); + } + /** * Returns the sorting strategy for notation codes set in the config.ttl * config: either "lexical", "natural", or null if sorting by notations is diff --git a/src/view/vocab-home.twig b/src/view/vocab-home.twig index d4e9fbc58..1f748322b 100644 --- a/src/view/vocab-home.twig +++ b/src/view/vocab-home.twig @@ -1,6 +1,7 @@ {% set pageType = 'vocab-home' %} {% extends "base-template.twig" %} {% block title %}{{ vocab.title(request.contentLang) }} - {{ GlobalConfig.serviceName }}{% endblock %} +{% block description %}{{ vocab.config.description(request.contentLang) }}{% endblock %} {% block content %} diff --git a/tests/VocabularyConfigTest.php b/tests/VocabularyConfigTest.php index 80cc50f28..1e1f56173 100644 --- a/tests/VocabularyConfigTest.php +++ b/tests/VocabularyConfigTest.php @@ -360,6 +360,15 @@ public function testGetTitle() $this->assertEquals('Test ontology', $vocab->getConfig()->getTitle('en')); } + /** + * @covers VocabularyConfig::getDescription + */ + public function testGetDesctiption() + { + $vocab = $this->model->getVocabulary('test'); + $this->assertEquals('Description of Test ontology', $vocab->getConfig()->getDescription('en')); + } + /** * @covers VocabularyConfig::getShowDeprecatedChanges * @covers VocabularyConfig::getBoolean diff --git a/tests/cypress/template/vocab-home.cy.js b/tests/cypress/template/vocab-home.cy.js index a0f798162..09cc7abe1 100644 --- a/tests/cypress/template/vocab-home.cy.js +++ b/tests/cypress/template/vocab-home.cy.js @@ -9,6 +9,15 @@ describe('Vocabulary home page', () => { cy.get('head meta[name="title"]').should('have.attr', 'content', expectedTitle); cy.get('head meta[property="og:title"]').should('have.attr', 'content', expectedTitle); }) + it('Contains description metadata', () => { + cy.visit('/test/en') // go to the "Test ontology" home page + + const expectedDescription = 'Description of Test ontology' + + // check that the page has description metadata + cy.get('head meta[name="description"]').should('have.attr', 'content', expectedDescription); + cy.get('head meta[property="og:description"]').should('have.attr', 'content', expectedDescription); + }) it('contains vocabulary title', () => { cy.visit('/test/en') // go to the "Test ontology" home page diff --git a/tests/testconfig.ttl b/tests/testconfig.ttl index 448c99f25..b619225d3 100644 --- a/tests/testconfig.ttl +++ b/tests/testconfig.ttl @@ -77,6 +77,7 @@ :test a skosmos:Vocabulary, void:Dataset ; dc:title "Test ontology"@en ; + dc:description "Description of Test ontology"@en ; dc:subject :cat_science ; dc:type mdrtype:ONTOLOGY ; void:dataDump ; From 6b2340728bd6ab4bd1a6d3d4d303d148bae49995 Mon Sep 17 00:00:00 2001 From: Osma Suominen Date: Wed, 21 Aug 2024 11:22:02 +0300 Subject: [PATCH 2/7] fix unit test that broke --- tests/VocabularyTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/VocabularyTest.php b/tests/VocabularyTest.php index 6cdc2d208..b235a8497 100644 --- a/tests/VocabularyTest.php +++ b/tests/VocabularyTest.php @@ -225,7 +225,7 @@ public function testGetInfo() { $vocab = $this->model->getVocabulary('test'); $info = $vocab->getInfo(); - $this->assertEquals(array("dc:title" => array('Test ontology'), 'dc:modified' => array('Wednesday, October 1, 2014 16:29:03'), "rdf:type" => array('http://www.w3.org/2004/02/skos/core#ConceptScheme' => 'http://www.w3.org/2004/02/skos/core#ConceptScheme'), "owl:versionInfo" => array('The latest and greatest version')), $info); + $this->assertEquals(array("dc:title" => array('Test ontology'), 'dc:modified' => array('Wednesday, October 1, 2014 16:29:03'), "rdf:type" => array('http://www.w3.org/2004/02/skos/core#ConceptScheme' => 'http://www.w3.org/2004/02/skos/core#ConceptScheme'), "owl:versionInfo" => array('The latest and greatest version'), "dc:description" => array('Description of Test ontology')), $info); } /** From 3f4d7b1d723acd23c7cd1f704605a5bf3126f519 Mon Sep 17 00:00:00 2001 From: Osma Suominen Date: Wed, 21 Aug 2024 11:22:42 +0300 Subject: [PATCH 3/7] add og:site_name metadata on all pages + cypress tests --- src/view/base-template.twig | 1 + tests/cypress/template/about.cy.js | 8 ++++++++ tests/cypress/template/concept.cy.js | 7 +++++++ tests/cypress/template/error.cy.js | 8 ++++++++ tests/cypress/template/feedback.cy.js | 16 ++++++++++++++++ tests/cypress/template/landing.cy.js | 8 ++++++++ tests/cypress/template/vocab-home.cy.js | 7 +++++++ tests/cypress/template/vocab-search.cy.js | 7 +++++++ 8 files changed, 62 insertions(+) diff --git a/src/view/base-template.twig b/src/view/base-template.twig index d91dacab2..1c3591546 100644 --- a/src/view/base-template.twig +++ b/src/view/base-template.twig @@ -16,6 +16,7 @@ {% endif %} + diff --git a/tests/cypress/template/about.cy.js b/tests/cypress/template/about.cy.js index 31f798bf1..1f0c130dc 100644 --- a/tests/cypress/template/about.cy.js +++ b/tests/cypress/template/about.cy.js @@ -19,6 +19,14 @@ describe('About page', () => { cy.get('head meta[name="description"]').should('have.attr', 'content', expectedDescription); cy.get('head meta[property="og:description"]').should('have.attr', 'content', expectedDescription); }) + it('Contains site name metadata', () => { + // go to the Skosmos about page + cy.visit('/en/about') + + const expectedSiteName = 'Skosmos being tested' + // check that the page has site name metadata + cy.get('head meta[property="og:site_name"]').should('have.attr', 'content', expectedSiteName); + }) it('Contains version number information', () => { // go to the Skosmos about page cy.visit('/en/about') diff --git a/tests/cypress/template/concept.cy.js b/tests/cypress/template/concept.cy.js index 38cd0a060..7198ded21 100644 --- a/tests/cypress/template/concept.cy.js +++ b/tests/cypress/template/concept.cy.js @@ -142,6 +142,13 @@ describe('Concept page', () => { cy.get('head meta[name="title"]').should('have.attr', 'content', expectedTitle); cy.get('head meta[property="og:title"]').should('have.attr', 'content', expectedTitle); }) + it('Contains site name metadata', () => { + cy.visit('/yso/en/page/p1265') // go to "archaeology" concept page + + const expectedSiteName = 'Skosmos being tested' + // check that the page has site name metadata + cy.get('head meta[property="og:site_name"]').should('have.attr', 'content', expectedSiteName); + }) it("doesn't contain breadcrumbs for top concepts", () => { cy.visit('/yso/en/page/p4762') // go to "objects" concept page diff --git a/tests/cypress/template/error.cy.js b/tests/cypress/template/error.cy.js index fcd6b0f07..9f246bff3 100644 --- a/tests/cypress/template/error.cy.js +++ b/tests/cypress/template/error.cy.js @@ -10,6 +10,14 @@ describe('Error page', () => { cy.get('head meta[name="title"]').should('have.attr', 'content', expectedTitle); cy.get('head meta[property="og:title"]').should('have.attr', 'content', expectedTitle); }) + it('Contains site name metadata', () => { + // go to a non-existing page + cy.visit('/404', {failOnStatusCode: false}) + + const expectedSiteName = 'Skosmos being tested' + // check that the page has site name metadata + cy.get('head meta[property="og:site_name"]').should('have.attr', 'content', expectedSiteName); + }) it('Contains 404 error code', () => { // check that HTTP code is 404 when accessing a non-existing page cy.request({url: '/404', failOnStatusCode: false}).its('status').should('equal', 404) diff --git a/tests/cypress/template/feedback.cy.js b/tests/cypress/template/feedback.cy.js index fd9b08d7c..74961b193 100644 --- a/tests/cypress/template/feedback.cy.js +++ b/tests/cypress/template/feedback.cy.js @@ -19,6 +19,14 @@ describe('Feedback page', () => { cy.get('head meta[name="description"]').should('have.attr', 'content', expectedDescription); cy.get('head meta[property="og:description"]').should('have.attr', 'content', expectedDescription); }) + it('Contains site name metadata', () => { + // go to the general feedback page + cy.visit('/en/feedback') + + const expectedSiteName = 'Skosmos being tested' + // check that the page has site name metadata + cy.get('head meta[property="og:site_name"]').should('have.attr', 'content', expectedSiteName); + }) it('Sends feedback', () => { // go to the general feedback page cy.visit('/en/feedback') @@ -75,6 +83,14 @@ describe('Vocab feedback page', () => { cy.get('head meta[name="description"]').should('have.attr', 'content', expectedDescription); cy.get('head meta[property="og:description"]').should('have.attr', 'content', expectedDescription); }) + it('Contains site name metadata', () => { + // go to test vocab feedback page + cy.visit('/test/en/feedback') + + const expectedSiteName = 'Skosmos being tested' + // check that the page has site name metadata + cy.get('head meta[property="og:site_name"]').should('have.attr', 'content', expectedSiteName); + }) it('Displays correct vocab option', () => { // go to test vocab feedback page cy.visit('/test/en/feedback') diff --git a/tests/cypress/template/landing.cy.js b/tests/cypress/template/landing.cy.js index 18dff9f0c..a13c8b56d 100644 --- a/tests/cypress/template/landing.cy.js +++ b/tests/cypress/template/landing.cy.js @@ -21,6 +21,14 @@ describe('Landing page', () => { cy.get('head meta[name="description"]').should('have.attr', 'content', expectedDescription); cy.get('head meta[property="og:description"]').should('have.attr', 'content', expectedDescription); }) + it('Contains site name metadata', () => { + // go to the Skosmos front page + cy.visit('/') + + const expectedSiteName = 'Skosmos being tested' + // check that the page has site name metadata + cy.get('head meta[property="og:site_name"]').should('have.attr', 'content', expectedSiteName); + }) it('links to vocabulary home', () => { // go to the Skosmos front page cy.visit('/') diff --git a/tests/cypress/template/vocab-home.cy.js b/tests/cypress/template/vocab-home.cy.js index 09cc7abe1..8af4e7c93 100644 --- a/tests/cypress/template/vocab-home.cy.js +++ b/tests/cypress/template/vocab-home.cy.js @@ -18,6 +18,13 @@ describe('Vocabulary home page', () => { cy.get('head meta[name="description"]').should('have.attr', 'content', expectedDescription); cy.get('head meta[property="og:description"]').should('have.attr', 'content', expectedDescription); }) + it('Contains site name metadata', () => { + cy.visit('/test/en') // go to the "Test ontology" home page + + const expectedSiteName = 'Skosmos being tested' + // check that the page has site name metadata + cy.get('head meta[property="og:site_name"]').should('have.attr', 'content', expectedSiteName); + }) it('contains vocabulary title', () => { cy.visit('/test/en') // go to the "Test ontology" home page diff --git a/tests/cypress/template/vocab-search.cy.js b/tests/cypress/template/vocab-search.cy.js index 554b1da3e..ead3c97a7 100644 --- a/tests/cypress/template/vocab-search.cy.js +++ b/tests/cypress/template/vocab-search.cy.js @@ -11,6 +11,13 @@ describe('Vocabulary search page', () => { cy.get('head meta[name="title"]').should('have.attr', 'content', expectedTitle); cy.get('head meta[property="og:title"]').should('have.attr', 'content', expectedTitle); }) + it('Contains site name metadata', () => { + cy.visit(`/${vocab}/en/search?clang=en&q=${term}`) + + const expectedSiteName = 'Skosmos being tested' + // check that the page has site name metadata + cy.get('head meta[property="og:site_name"]').should('have.attr', 'content', expectedSiteName); + }) it('Contains correct amount of search results ', () => { const count = 1; const searchCountTitle = `${count} results for \'${term}\'`; From d39500c95c2756017b0b49ac25f1eeb76b15f570 Mon Sep 17 00:00:00 2001 From: Osma Suominen Date: Wed, 21 Aug 2024 11:30:52 +0300 Subject: [PATCH 4/7] add open graph prefix; add og:type; drop legacy twitter:card metadata --- src/view/base-template.twig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/view/base-template.twig b/src/view/base-template.twig index 1c3591546..e524c865e 100644 --- a/src/view/base-template.twig +++ b/src/view/base-template.twig @@ -1,5 +1,5 @@ - + @@ -15,7 +15,7 @@ {% endif %} - + From 9bdb8948d4246a410181db32cdc7dcf0efd2f309 Mon Sep 17 00:00:00 2001 From: Osma Suominen Date: Wed, 21 Aug 2024 13:32:38 +0300 Subject: [PATCH 5/7] fix bug in getLangUrl after moving code under src/ --- src/model/Request.php | 2 +- tests/RequestTest.php | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/model/Request.php b/src/model/Request.php index bc1c316b5..3fb046d98 100644 --- a/src/model/Request.php +++ b/src/model/Request.php @@ -210,7 +210,7 @@ public function getRequestUri() */ public function getLangUrl($newlang=null) { - $script_name = str_replace('/index.php', '', $this->getServerConstant('SCRIPT_NAME')); + $script_name = str_replace('/src/index.php', '', $this->getServerConstant('SCRIPT_NAME')); $langurl = substr(str_replace($script_name, '', strval($this->getServerConstant('REQUEST_URI'))), 1); if ($newlang !== null) { $langurl = preg_replace("#^(.*/)?{$this->lang}/#", "$1{$newlang}/", $langurl); diff --git a/tests/RequestTest.php b/tests/RequestTest.php index 8a3205e06..bdffea3bc 100644 --- a/tests/RequestTest.php +++ b/tests/RequestTest.php @@ -179,7 +179,7 @@ public function testGetVersion() */ public function testGetLangUrlNoParamRoot() { - $this->request->setServerConstant('SCRIPT_NAME', '/Skosmos/index.php'); + $this->request->setServerConstant('SCRIPT_NAME', '/Skosmos/src/index.php'); $this->request->setServerConstant('REQUEST_URI', '/Skosmos/en/'); $langurl = $this->request->getLangUrl(); $this->assertEquals("en/", $langurl); @@ -190,7 +190,7 @@ public function testGetLangUrlNoParamRoot() */ public function testGetLangUrlNoParamVocab() { - $this->request->setServerConstant('SCRIPT_NAME', '/Skosmos/index.php'); + $this->request->setServerConstant('SCRIPT_NAME', '/Skosmos/src/index.php'); $this->request->setServerConstant('REQUEST_URI', '/Skosmos/myvocab/en/'); $langurl = $this->request->getLangUrl(); $this->assertEquals("myvocab/en/", $langurl); @@ -201,7 +201,7 @@ public function testGetLangUrlNoParamVocab() */ public function testGetLangUrlNoParamVocabIndex() { - $this->request->setServerConstant('SCRIPT_NAME', '/Skosmos/index.php'); + $this->request->setServerConstant('SCRIPT_NAME', '/Skosmos/src/index.php'); $this->request->setServerConstant('REQUEST_URI', '/Skosmos/myvocab/en/index'); $langurl = $this->request->getLangUrl(); $this->assertEquals("myvocab/en/index", $langurl); @@ -212,7 +212,7 @@ public function testGetLangUrlNoParamVocabIndex() */ public function testGetLangUrlNewLangRoot() { - $this->request->setServerConstant('SCRIPT_NAME', '/Skosmos/index.php'); + $this->request->setServerConstant('SCRIPT_NAME', '/Skosmos/src/index.php'); $this->request->setServerConstant('REQUEST_URI', '/Skosmos/en/'); $this->request->setLang('en'); $langurl = $this->request->getLangUrl("sv"); @@ -224,7 +224,7 @@ public function testGetLangUrlNewLangRoot() */ public function testGetLangUrlNewLangVocab() { - $this->request->setServerConstant('SCRIPT_NAME', '/Skosmos/index.php'); + $this->request->setServerConstant('SCRIPT_NAME', '/Skosmos/src/index.php'); $this->request->setServerConstant('REQUEST_URI', '/Skosmos/myvocab/en/'); $this->request->setLang('en'); $langurl = $this->request->getLangUrl("sv"); @@ -236,7 +236,7 @@ public function testGetLangUrlNewLangVocab() */ public function testGetLangUrlNewLangVocabIndex() { - $this->request->setServerConstant('SCRIPT_NAME', '/Skosmos/index.php'); + $this->request->setServerConstant('SCRIPT_NAME', '/Skosmos/src/index.php'); $this->request->setServerConstant('REQUEST_URI', '/Skosmos/myvocab/en/index'); $this->request->setLang('en'); $langurl = $this->request->getLangUrl("sv"); @@ -248,7 +248,7 @@ public function testGetLangUrlNewLangVocabIndex() */ public function testGetLangUrlSanitizeSpecialChars() { - $this->request->setServerConstant('SCRIPT_NAME', '/Skosmos/index.php'); + $this->request->setServerConstant('SCRIPT_NAME', '/Skosmos/src/index.php'); $this->request->setServerConstant('REQUEST_URI', '/Skosmos/http://example.com'); $this->request->setLang('en'); $langurl = $this->request->getLangUrl(); From 6284b2589496a00fd17cda3a966f6fbdc606f819 Mon Sep 17 00:00:00 2001 From: Osma Suominen Date: Wed, 21 Aug 2024 13:38:39 +0300 Subject: [PATCH 6/7] SEO: add link rel=canonical and og:url metadata for all page types --- src/view/about.twig | 1 + src/view/base-template.twig | 4 ++++ src/view/concept.twig | 1 + src/view/error.twig | 1 + src/view/feedback.twig | 1 + src/view/landing.twig | 1 + src/view/vocab-home.twig | 1 + src/view/vocab-search.twig | 2 ++ tests/cypress/template/about.cy.js | 9 +++++++++ tests/cypress/template/concept.cy.js | 17 +++++++++++++++++ tests/cypress/template/error.cy.js | 9 +++++++++ tests/cypress/template/feedback.cy.js | 18 ++++++++++++++++++ tests/cypress/template/landing.cy.js | 9 +++++++++ tests/cypress/template/vocab-home.cy.js | 8 ++++++++ tests/cypress/template/vocab-search.cy.js | 8 ++++++++ 15 files changed, 90 insertions(+) diff --git a/src/view/about.twig b/src/view/about.twig index 4dbbfc30e..fd60ff2e9 100644 --- a/src/view/about.twig +++ b/src/view/about.twig @@ -2,6 +2,7 @@ {% extends "base-template.twig" %} {% block title %}{{ "About" | trans}} - {{ GlobalConfig.serviceName }}{% endblock %} {% block description %}{{ GlobalConfig.aboutDescription(request.lang) }}{% endblock %} +{% block url %}{{ BaseHref }}{{ request.lang }}/about{% endblock %} {% block content %} diff --git a/src/view/base-template.twig b/src/view/base-template.twig index e524c865e..68808ee8d 100644 --- a/src/view/base-template.twig +++ b/src/view/base-template.twig @@ -15,6 +15,10 @@ {% endif %} +{% if block('url') is defined and block('url') is not empty %} + + +{% endif %} diff --git a/src/view/concept.twig b/src/view/concept.twig index 2aa3258a7..b74dcd95c 100644 --- a/src/view/concept.twig +++ b/src/view/concept.twig @@ -1,6 +1,7 @@ {% set pageType = 'concept' %} {% extends "base-template.twig" %} {% block title %}{{ concept.label }} - {{ vocab.shortName }} - {{ GlobalConfig.serviceName }}{% endblock %} +{% block url %}{{ BaseHref }}{{ concept.uri|link_url(vocab,request.lang,'page',request.contentLang) }}{% endblock %} {% block content %} {% include "sidebar.inc" %} diff --git a/src/view/error.twig b/src/view/error.twig index 716e3b486..f58ec08db 100644 --- a/src/view/error.twig +++ b/src/view/error.twig @@ -1,6 +1,7 @@ {% set pageType = 'error' %} {% extends "base-template.twig" %} {% block title %}{{ "Error"| trans }} - {{ GlobalConfig.serviceName }}{% endblock %} +{% block url %}{{ BaseHref }}{{ request.langurl }}{% endblock %} {% block content %} {% set pageError = request.vocabid != '' and request.page == 'page' %} {% if pageError %} diff --git a/src/view/feedback.twig b/src/view/feedback.twig index bb7b106f6..5406b347a 100644 --- a/src/view/feedback.twig +++ b/src/view/feedback.twig @@ -3,6 +3,7 @@ {% block title %}{{ "Feedback"|trans }} - {{ GlobalConfig.serviceName }}{% endblock %} {% block description %}{{ GlobalConfig.feedbackDescription(request.lang) }}{% endblock %} +{% block url %}{{ BaseHref }}{% if request.vocab %}{{ request.vocab.id }}/{% endif %}{{ request.lang }}/feedback{% endblock %} {% block content %} diff --git a/src/view/landing.twig b/src/view/landing.twig index a4cd980cf..6e546ed08 100644 --- a/src/view/landing.twig +++ b/src/view/landing.twig @@ -2,6 +2,7 @@ {% extends "base-template.twig" %} {% block title %}{{ GlobalConfig.serviceNameLong(request.lang) }}{% endblock %} {% block description %}{{ GlobalConfig.serviceDescription(request.lang) }}{% endblock %} +{% block url %}{{ BaseHref }}{{ request.lang }}/{% endblock %} {% block content %}
diff --git a/src/view/vocab-home.twig b/src/view/vocab-home.twig index 1f748322b..cf6143d7f 100644 --- a/src/view/vocab-home.twig +++ b/src/view/vocab-home.twig @@ -2,6 +2,7 @@ {% extends "base-template.twig" %} {% block title %}{{ vocab.title(request.contentLang) }} - {{ GlobalConfig.serviceName }}{% endblock %} {% block description %}{{ vocab.config.description(request.contentLang) }}{% endblock %} +{% block url %}{{ BaseHref }}{{ vocab.id }}/{{ request.lang }}/{% if request.contentLang != request.lang and request.contentLang != '' and request.contentLang in vocab.config.languages %}?clang={{ request.contentLang }}{% endif %}{% endblock %} {% block content %} diff --git a/src/view/vocab-search.twig b/src/view/vocab-search.twig index 9ff15dd4e..8611301ef 100644 --- a/src/view/vocab-search.twig +++ b/src/view/vocab-search.twig @@ -1,6 +1,8 @@ {% set pageType = 'vocab-search' %} {% extends "base-template.twig" %} {% block title %}'{{ term }}' - {{ vocab.shortName(request.contentLang) }} - {{ GlobalConfig.serviceName }}{% endblock %} +{% block url %}{{ BaseHref }}{{ vocab.id }}/{{ request.lang }}/search?clang={{ request.contentLang}}&q={{ term|url_encode }}{% endblock %} + {% block content %}
diff --git a/tests/cypress/template/about.cy.js b/tests/cypress/template/about.cy.js index 1f0c130dc..28ee151ea 100644 --- a/tests/cypress/template/about.cy.js +++ b/tests/cypress/template/about.cy.js @@ -27,6 +27,15 @@ describe('About page', () => { // check that the page has site name metadata cy.get('head meta[property="og:site_name"]').should('have.attr', 'content', expectedSiteName); }) + it('Contains canonical URL metadata', () => { + // go to the Skosmos about page + cy.visit('/en/about') + + const expectedUrl = Cypress.config('baseUrl') + 'en/about' + // check that the page has canonical URL metadata + cy.get('link[rel="canonical"]').should('have.attr', 'href', expectedUrl); + cy.get('head meta[property="og:url"]').should('have.attr', 'content', expectedUrl); + }) it('Contains version number information', () => { // go to the Skosmos about page cy.visit('/en/about') diff --git a/tests/cypress/template/concept.cy.js b/tests/cypress/template/concept.cy.js index 7198ded21..5695dc87d 100644 --- a/tests/cypress/template/concept.cy.js +++ b/tests/cypress/template/concept.cy.js @@ -149,6 +149,23 @@ describe('Concept page', () => { // check that the page has site name metadata cy.get('head meta[property="og:site_name"]').should('have.attr', 'content', expectedSiteName); }) + it('Contains canonical URL metadata (short URL)', () => { + cy.visit('/yso/en/page/p1265') // go to "archaeology" concept page + + const expectedUrl = Cypress.config('baseUrl') + 'yso/en/page/p1265' + // check that the page has canonical URL metadata + cy.get('link[rel="canonical"]').should('have.attr', 'href', expectedUrl); + cy.get('head meta[property="og:url"]').should('have.attr', 'content', expectedUrl); + }) + it('Contains canonical URL metadata (long URL)', () => { + // go to "archaeology" concept page using long URL based on URI + cy.visit('/yso/en/page/?uri=http%3A%2F%2Fwww.yso.fi%2Fonto%2Fyso%2Fp1265') + + const expectedUrl = Cypress.config('baseUrl') + 'yso/en/page/p1265' + // check that the page has canonical URL metadata + cy.get('link[rel="canonical"]').should('have.attr', 'href', expectedUrl); + cy.get('head meta[property="og:url"]').should('have.attr', 'content', expectedUrl); + }) it("doesn't contain breadcrumbs for top concepts", () => { cy.visit('/yso/en/page/p4762') // go to "objects" concept page diff --git a/tests/cypress/template/error.cy.js b/tests/cypress/template/error.cy.js index 9f246bff3..608efa744 100644 --- a/tests/cypress/template/error.cy.js +++ b/tests/cypress/template/error.cy.js @@ -18,6 +18,15 @@ describe('Error page', () => { // check that the page has site name metadata cy.get('head meta[property="og:site_name"]').should('have.attr', 'content', expectedSiteName); }) + it('Contains canonical URL metadata', () => { + // go to a non-existing page + cy.visit('/404', {failOnStatusCode: false}) + + const expectedUrl = Cypress.config('baseUrl') + '404/' + // check that the page has canonical URL metadata + cy.get('link[rel="canonical"]').should('have.attr', 'href', expectedUrl); + cy.get('head meta[property="og:url"]').should('have.attr', 'content', expectedUrl); + }) it('Contains 404 error code', () => { // check that HTTP code is 404 when accessing a non-existing page cy.request({url: '/404', failOnStatusCode: false}).its('status').should('equal', 404) diff --git a/tests/cypress/template/feedback.cy.js b/tests/cypress/template/feedback.cy.js index 74961b193..71a169ca4 100644 --- a/tests/cypress/template/feedback.cy.js +++ b/tests/cypress/template/feedback.cy.js @@ -27,6 +27,15 @@ describe('Feedback page', () => { // check that the page has site name metadata cy.get('head meta[property="og:site_name"]').should('have.attr', 'content', expectedSiteName); }) + it('Contains canonical URL metadata', () => { + // go to the general feedback page + cy.visit('/en/feedback') + + const expectedUrl = Cypress.config('baseUrl') + 'en/feedback' + // check that the page has canonical URL metadata + cy.get('link[rel="canonical"]').should('have.attr', 'href', expectedUrl); + cy.get('head meta[property="og:url"]').should('have.attr', 'content', expectedUrl); + }) it('Sends feedback', () => { // go to the general feedback page cy.visit('/en/feedback') @@ -91,6 +100,15 @@ describe('Vocab feedback page', () => { // check that the page has site name metadata cy.get('head meta[property="og:site_name"]').should('have.attr', 'content', expectedSiteName); }) + it('Contains canonical URL metadata', () => { + // go to test vocab feedback page + cy.visit('/test/en/feedback') + + const expectedUrl = Cypress.config('baseUrl') + 'test/en/feedback' + // check that the page has canonical URL metadata + cy.get('link[rel="canonical"]').should('have.attr', 'href', expectedUrl); + cy.get('head meta[property="og:url"]').should('have.attr', 'content', expectedUrl); + }) it('Displays correct vocab option', () => { // go to test vocab feedback page cy.visit('/test/en/feedback') diff --git a/tests/cypress/template/landing.cy.js b/tests/cypress/template/landing.cy.js index a13c8b56d..598bcc7ed 100644 --- a/tests/cypress/template/landing.cy.js +++ b/tests/cypress/template/landing.cy.js @@ -29,6 +29,15 @@ describe('Landing page', () => { // check that the page has site name metadata cy.get('head meta[property="og:site_name"]').should('have.attr', 'content', expectedSiteName); }) + it('Contains canonical URL metadata', () => { + // go to the Skosmos front page + cy.visit('/') + + const expectedUrl = Cypress.config('baseUrl') + 'en/' + // check that the page has canonical URL metadata + cy.get('link[rel="canonical"]').should('have.attr', 'href', expectedUrl); + cy.get('head meta[property="og:url"]').should('have.attr', 'content', expectedUrl); + }) it('links to vocabulary home', () => { // go to the Skosmos front page cy.visit('/') diff --git a/tests/cypress/template/vocab-home.cy.js b/tests/cypress/template/vocab-home.cy.js index 8af4e7c93..2d9004ec1 100644 --- a/tests/cypress/template/vocab-home.cy.js +++ b/tests/cypress/template/vocab-home.cy.js @@ -25,6 +25,14 @@ describe('Vocabulary home page', () => { // check that the page has site name metadata cy.get('head meta[property="og:site_name"]').should('have.attr', 'content', expectedSiteName); }) + it('Contains canonical URL metadata', () => { + cy.visit('/test/en') // go to the "Test ontology" home page + + const expectedUrl = Cypress.config('baseUrl') + 'test/en/' + // check that the page has canonical URL metadata + cy.get('link[rel="canonical"]').should('have.attr', 'href', expectedUrl); + cy.get('head meta[property="og:url"]').should('have.attr', 'content', expectedUrl); + }) it('contains vocabulary title', () => { cy.visit('/test/en') // go to the "Test ontology" home page diff --git a/tests/cypress/template/vocab-search.cy.js b/tests/cypress/template/vocab-search.cy.js index ead3c97a7..1e9dd0fa0 100644 --- a/tests/cypress/template/vocab-search.cy.js +++ b/tests/cypress/template/vocab-search.cy.js @@ -18,6 +18,14 @@ describe('Vocabulary search page', () => { // check that the page has site name metadata cy.get('head meta[property="og:site_name"]').should('have.attr', 'content', expectedSiteName); }) + it('Contains canonical URL metadata', () => { + cy.visit(`/${vocab}/en/search?clang=en&q=${term}`) + + const expectedUrl = Cypress.config('baseUrl') + `${vocab}/en/search?clang=en&q=${term}` + // check that the page has canonical URL metadata + cy.get('link[rel="canonical"]').should('have.attr', 'href', expectedUrl); + cy.get('head meta[property="og:url"]').should('have.attr', 'content', expectedUrl); + }) it('Contains correct amount of search results ', () => { const count = 1; const searchCountTitle = `${count} results for \'${term}\'`; From fba5bb125f20b97ab22e3b3edddcfe1a58165b61 Mon Sep 17 00:00:00 2001 From: Osma Suominen Date: Wed, 21 Aug 2024 13:52:08 +0300 Subject: [PATCH 7/7] simplify canonical URL generation using Request.getLangUrl() --- src/view/about.twig | 2 +- src/view/feedback.twig | 2 +- src/view/landing.twig | 2 +- src/view/vocab-home.twig | 2 +- src/view/vocab-search.twig | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/view/about.twig b/src/view/about.twig index fd60ff2e9..a5c208711 100644 --- a/src/view/about.twig +++ b/src/view/about.twig @@ -2,7 +2,7 @@ {% extends "base-template.twig" %} {% block title %}{{ "About" | trans}} - {{ GlobalConfig.serviceName }}{% endblock %} {% block description %}{{ GlobalConfig.aboutDescription(request.lang) }}{% endblock %} -{% block url %}{{ BaseHref }}{{ request.lang }}/about{% endblock %} +{% block url %}{{ BaseHref }}{{ request.langurl }}{% endblock %} {% block content %} diff --git a/src/view/feedback.twig b/src/view/feedback.twig index 5406b347a..4632bbf99 100644 --- a/src/view/feedback.twig +++ b/src/view/feedback.twig @@ -3,7 +3,7 @@ {% block title %}{{ "Feedback"|trans }} - {{ GlobalConfig.serviceName }}{% endblock %} {% block description %}{{ GlobalConfig.feedbackDescription(request.lang) }}{% endblock %} -{% block url %}{{ BaseHref }}{% if request.vocab %}{{ request.vocab.id }}/{% endif %}{{ request.lang }}/feedback{% endblock %} +{% block url %}{{ BaseHref }}{{ request.langurl }}{% endblock %} {% block content %} diff --git a/src/view/landing.twig b/src/view/landing.twig index 6e546ed08..505004e6a 100644 --- a/src/view/landing.twig +++ b/src/view/landing.twig @@ -2,7 +2,7 @@ {% extends "base-template.twig" %} {% block title %}{{ GlobalConfig.serviceNameLong(request.lang) }}{% endblock %} {% block description %}{{ GlobalConfig.serviceDescription(request.lang) }}{% endblock %} -{% block url %}{{ BaseHref }}{{ request.lang }}/{% endblock %} +{% block url %}{{ BaseHref }}{{ request.langurl }}{% endblock %} {% block content %}
diff --git a/src/view/vocab-home.twig b/src/view/vocab-home.twig index cf6143d7f..0104ae2cf 100644 --- a/src/view/vocab-home.twig +++ b/src/view/vocab-home.twig @@ -2,7 +2,7 @@ {% extends "base-template.twig" %} {% block title %}{{ vocab.title(request.contentLang) }} - {{ GlobalConfig.serviceName }}{% endblock %} {% block description %}{{ vocab.config.description(request.contentLang) }}{% endblock %} -{% block url %}{{ BaseHref }}{{ vocab.id }}/{{ request.lang }}/{% if request.contentLang != request.lang and request.contentLang != '' and request.contentLang in vocab.config.languages %}?clang={{ request.contentLang }}{% endif %}{% endblock %} +{% block url %}{{ BaseHref }}{{ request.langurl }}{% endblock %} {% block content %} diff --git a/src/view/vocab-search.twig b/src/view/vocab-search.twig index 8611301ef..fec32221e 100644 --- a/src/view/vocab-search.twig +++ b/src/view/vocab-search.twig @@ -1,7 +1,7 @@ {% set pageType = 'vocab-search' %} {% extends "base-template.twig" %} {% block title %}'{{ term }}' - {{ vocab.shortName(request.contentLang) }} - {{ GlobalConfig.serviceName }}{% endblock %} -{% block url %}{{ BaseHref }}{{ vocab.id }}/{{ request.lang }}/search?clang={{ request.contentLang}}&q={{ term|url_encode }}{% endblock %} +{% block url %}{{ BaseHref }}{{ request.langurl }}{% endblock %} {% block content %}