Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 128 additions & 0 deletions tests/RecordManagerTest/Base/Utils/XslTransformationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?php

/**
* XmlTransformation tests
*
* PHP version 8
*
* Copyright (C) The National Library of Finland 2026
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @category DataManagement
* @package RecordManager
* @author Minna Rönkä <minna.ronka@helsinki.fi>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://github.com/NatLibFi/RecordManager
*/

namespace RecordManagerTest\Base\Utils;

use RecordManager\Base\Utils\XslTransformation;
use RecordManagerTest\Base\Feature\FixtureTrait;

/**
* XmlTransformation tests
*
* @category DataManagement
* @package RecordManager
* @author Minna Rönkä <minna.ronka@helsinki.fi>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://github.com/NatLibFi/RecordManager
*/
class XslTransformationTest extends \PHPUnit\Framework\TestCase
{
use FixtureTrait;

/**
* Test LIDO-EDM transformation with image
*
* @return void
*/
public function testLido2EdmTransformationWithImage()
{
$xslTransformation = $this->getXslTransformation('lido2edm_image.properties');
$lidoRecord = $this->getFixture('utils/XslTransformation/lido_image.xml');
$expectedEdm = $this->getFixture('utils/XslTransformation/lido_image_edm.xml');
$transformedEdm = $xslTransformation->transform($lidoRecord);
$this->assertSame($expectedEdm, $transformedEdm);
}

/**
* Test LIDO-EDM transformation with video
*
* @return void
*/
public function testLido2EdmTransformationWithVideo()
{
$xslTransformation = $this->getXslTransformation('lido2edm_video.properties');
$lidoRecord = $this->getFixture('utils/XslTransformation/lido_video.xml');
$expectedEdm = $this->getFixture('utils/XslTransformation/lido_video_edm.xml');
$transformedEdm = $xslTransformation->transform($lidoRecord);
$this->assertSame($expectedEdm, $transformedEdm);
}

/**
* Test LIDO-EDM transformation with text
*
* @return void
*/
public function testLido2EdmTransformationWithText()
{
$xslTransformation = $this->getXslTransformation('lido2edm_text.properties');
$lidoRecord = $this->getFixture('utils/XslTransformation/lido_text.xml');
$expectedEdm = $this->getFixture('utils/XslTransformation/lido_text_edm.xml');
$transformedEdm = $xslTransformation->transform($lidoRecord);
$this->assertSame($expectedEdm, $transformedEdm);
}

/**
* Test LIDO-EDM transformation with 3D
*
* @return void
*/
public function testLido2EdmTransformationWith3D()
{
$xslTransformation = $this->getXslTransformation('lido2edm_3D.properties');
$lidoRecord = $this->getFixture('utils/XslTransformation/lido_3D.xml');
$expectedEdm = $this->getFixture('utils/XslTransformation/lido_3D_edm.xml');
$transformedEdm = $xslTransformation->transform($lidoRecord);
$this->assertSame($expectedEdm, $transformedEdm);
}

/**
* Create XmlTransformation
*
* @param string $config Transformation config file name
*
* @return XslTransformation
*/
protected function getXslTransformation(string $config)
{
return new XslTransformation(
$this->getConfigDir(),
$config
);
}

/**
* Get config directory
*
* @return string
*/
protected function getConfigDir()
{
return $this->getFixtureDir() . 'config/xsltransformationtest/transformations';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl">
<xsl:output method="xml" indent="no"/>

<xsl:template name="europeanalic">
<xsl:param name="license"/>

<xsl:variable name="licenseLC" select="php:function('mb_strtolower', string($license), 'UTF-8')"/>

<xsl:choose>
<xsl:when test="contains($licenseLC, 'cc') and (contains($licenseLC, '4.0') or contains($licenseLC, '3.0'))">
<!-- CC license -->
<xsl:text>http://creativecommons.org/licenses/</xsl:text>
<xsl:variable name="ccver" select="substring($licenseLC, string-length($licenseLC)-2)"/>
<xsl:variable name="cclic" select="normalize-space(substring-before(substring-after($licenseLC, 'cc '), $ccver))"/>
<xsl:value-of select="$cclic"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="$ccver"/>
<xsl:text>/</xsl:text>
</xsl:when>

<xsl:when test="contains($licenseLC, 'public domain') or contains($license, 'publicdomain')">
<!-- Public Domain -->
<xsl:text>http://creativecommons.org/publicdomain/mark/1.0/</xsl:text>
</xsl:when>

<xsl:when test="contains($licenseLC, 'CC0')">
<!-- CC0 -->
<xsl:text>http://creativecommons.org/publicdomain/zero/1.0/</xsl:text>
</xsl:when>

<xsl:when test="contains($licenseLC, 'inc') or contains($license, 'copyright')">
<!-- In Copyright -->
<xsl:text>http://rightsstatements.org/vocab/InC/1.0/</xsl:text>
</xsl:when>

<xsl:when test="contains($licenseLC, 'cne')">
<!-- Copyright Not Evaluated -->
<xsl:text>http://rightsstatements.org/vocab/CNE/1.0/</xsl:text>
</xsl:when>

<xsl:otherwise>
<xsl:value-of select="$license"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

</xsl:stylesheet>
Loading
Loading