Skip to content

Commit

Permalink
Merge pull request #1601 from NatLibFi/issue1484-concept-page-mapping…
Browse files Browse the repository at this point in the history
…s-fix-order

Order mappings on concept page first by source vocabulary, then by label
  • Loading branch information
osma authored Mar 6, 2024
2 parents 1b906f4 + ed30a50 commit 9e02d76
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/model/ConceptMappingPropertyValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public function getLabel($lang = '', $queryExVocabs = true)
return $label;
}

public function getSortKey()
{
return strtolower($this->getVocabName() . ": " . $this->getLabel());
}

private function queryLabel($lang = '', $queryExVocabs = true)
{
if ($this->clang) {
Expand Down
4 changes: 2 additions & 2 deletions src/model/ConceptProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ private function sortValues()
});
} else {
uasort($this->values, function ($a, $b) {
// assume that labels are unique
return strcoll(strtolower($a->getLabel()), strtolower($b->getLabel()));
// assume that sort keys are unique
return strcoll($a->getSortKey(), $b->getSortKey());
});
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/model/ConceptPropertyValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public function getLang()
return $this->model->getLocale();
}

public function getSortKey()
{
return strtolower($this->getLabel());
}

public function getLabel($lang = '', $fallbackToUri = 'uri')
{
if ($this->clang) {
Expand Down
5 changes: 5 additions & 0 deletions src/model/ConceptPropertyValueLiteral.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ public function getLabel()
return $this->literal->getValue();
}

public function getSortKey()
{
return strtolower($this->getLabel());
}

public function getUri()
{
return null;
Expand Down
12 changes: 12 additions & 0 deletions tests/ConceptMappingPropertyValueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ public function testConstructor()
$this->assertEquals('skos:exactMatch', $mapping->getType());
}

/**
* @covers ConceptMappingPropertyValue::getSortKey
* @covers ConceptMappingPropertyValue::getLabel
* @covers ConceptMappingPropertyValue::queryLabel
* @covers DataObject::getExternalLabel
*/
public function testGetSortKey()
{
$propvals = $this->props['skos:exactMatch']->getValues();
$this->assertEquals('test ontology: eel', $propvals['Eel http://www.skosmos.skos/test/ta115']->getSortKey());
}

/**
* @covers ConceptMappingPropertyValue::getLabel
* @covers ConceptMappingPropertyValue::queryLabel
Expand Down
10 changes: 10 additions & 0 deletions tests/ConceptPropertyValueLiteralTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ public function testConstructor()
$this->assertEquals(null, $prop->__toString());
}

/**
* @covers ConceptPropertyValueLiteral::getSortKey
*/
public function testGetSortKey()
{
$props = $this->concept->getProperties();
$propvals = $props['skos:scopeNote']->getValues();
$this->assertEquals('carp are oily freshwater fish', $propvals['Carp are oily freshwater fish']->getSortKey());
}

/**
* @covers ConceptPropertyValueLiteral::getLabel
*/
Expand Down
10 changes: 10 additions & 0 deletions tests/ConceptPropertyValueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ public function testGetLang()
$this->assertEquals('en', $propvals['Crucian carp http://www.skosmos.skos/test/ta121']->getLang());
}

/**
* @covers ConceptPropertyValue::getSortKey
*/
public function testGetSortKey()
{
$props = $this->concept->getProperties();
$propvals = $props['skos:narrower']->getValues();
$this->assertEquals('crucian carp', $propvals['Crucian carp http://www.skosmos.skos/test/ta121']->getSortKey());
}

/**
* @covers ConceptPropertyValue::getLabel
*/
Expand Down
8 changes: 4 additions & 4 deletions tests/cypress/template/concept.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,10 @@ describe('Concept page', () => {
// check the second mapping property name
cy.get('.prop-mapping h2').eq(1).contains('Exactly matching concepts')
// check the second mapping property values (only one should be enough)
cy.get('.prop-mapping').eq(1).find('.prop-mapping-label').eq(0).contains('musiikintutkimus (fi)')
cy.get('.prop-mapping').eq(1).find('.prop-mapping-label').eq(0).find('a').invoke('text').should('equal', 'musiikintutkimus')
cy.get('.prop-mapping').eq(1).find('.prop-mapping-label').eq(0).find('a').should('have.attr', 'href', 'http://www.yso.fi/onto/ysa/Y155072')
cy.get('.prop-mapping').eq(1).find('.prop-mapping-vocab').eq(0).contains('YSA - Yleinen suomalainen asiasanasto')
cy.get('.prop-mapping').eq(1).find('.prop-mapping-label').eq(2).contains('musiikintutkimus (fi)')
cy.get('.prop-mapping').eq(1).find('.prop-mapping-label').eq(2).find('a').invoke('text').should('equal', 'musiikintutkimus')
cy.get('.prop-mapping').eq(1).find('.prop-mapping-label').eq(2).find('a').should('have.attr', 'href', 'http://www.yso.fi/onto/ysa/Y155072')
cy.get('.prop-mapping').eq(1).find('.prop-mapping-vocab').eq(2).contains('YSA - Yleinen suomalainen asiasanasto')
// check that the second mapping property has the right number of entries
cy.get('.prop-mapping').eq(1).find('.prop-mapping-label').should('have.length', 3)
})
Expand Down

0 comments on commit 9e02d76

Please sign in to comment.