Skip to content

Commit

Permalink
Split and add tests for reader
Browse files Browse the repository at this point in the history
  • Loading branch information
beatrycze-volk committed Jun 21, 2024
1 parent e3ff7f2 commit 659700e
Show file tree
Hide file tree
Showing 20 changed files with 3,389 additions and 1,474 deletions.
1,478 changes: 4 additions & 1,474 deletions tests/Mods/ModsReaderTest.php

Large diffs are not rendered by default.

94 changes: 94 additions & 0 deletions tests/Mods/Reader/AbstractReaderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

/**
* Copyright (C) 2024 Saxon State and University Library Dresden
*
* This file is part of the php-mods-reader.
*
* @license GNU General Public License version 3 or later.
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/

namespace Slub\Mods\Reader;

use Slub\Mods\ModsReaderTest;

/**
* Tests for reading Abstract element
*/
class AbstractReaderTest extends ModsReaderTest
{

/**
* @test
*/
public function getAbstractForBookDocument()
{
$abstract = $this->bookReader->getAbstract();
self::assertNotNull($abstract);
self::assertNotEmpty($abstract->getDisplayLabel());
self::assertEquals('Content description', $abstract->getDisplayLabel());
self::assertNotEmpty($abstract->getValue());
self::assertEquals('Test description for document which contains display label.', $abstract->getValue());
self::assertTrue($abstract->isShareable());
}

/**
* @test
*/
public function getAbstractByQueryForBookDocument()
{
$abstract = $this->bookReader->getAbstract('[@displayLabel="Content description"]');
self::assertNotNull($abstract);
self::assertNotEmpty($abstract->getDisplayLabel());
self::assertEquals('Content description', $abstract->getDisplayLabel());
self::assertNotEmpty($abstract->getValue());
self::assertEquals('Test description for document which contains display label.', $abstract->getValue());
self::assertTrue($abstract->isShareable());
}

/**
* @test
*/
public function getNoAbstractByQueryForBookDocument()
{
$abstract = $this->bookReader->getAbstract('[@displayLabel="Random"]');
self::assertNull($abstract);
}

/**
* @test
*/
public function getAbstractForSerialDocument()
{
$abstract = $this->serialReader->getAbstract();
self::assertNotNull($abstract);
self::assertEmpty($abstract->getDisplayLabel());
self::assertNotEmpty($abstract->getValue());
self::assertEquals('Test description for non shareable document.', $abstract->getValue());
self::assertFalse($abstract->isShareable());
}

/**
* @test
*/
public function getAbstractByQueryForSerialDocument()
{
$abstract = $this->serialReader->getAbstract('[@shareable="no"]');
self::assertNotNull($abstract);
self::assertEmpty($abstract->getDisplayLabel());
self::assertNotEmpty($abstract->getValue());
self::assertEquals('Test description for non shareable document.', $abstract->getValue());
self::assertFalse($abstract->isShareable());
}

/**
* @test
*/
public function getNoAbstractByQueryForSerialDocument()
{
$abstract = $this->serialReader->getAbstract('[@shareable="yes"]');
self::assertNull($abstract);
}
}
179 changes: 179 additions & 0 deletions tests/Mods/Reader/AccessConditionReaderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
<?php

/**
* Copyright (C) 2024 Saxon State and University Library Dresden
*
* This file is part of the php-mods-reader.
*
* @license GNU General Public License version 3 or later.
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/

namespace Slub\Mods\Reader;

use Slub\Mods\Element\AccessCondition;
use Slub\Mods\ModsReaderTest;

/**
* Tests for reading AccessCondition element
*/
class AccessConditionReaderTest extends ModsReaderTest
{

/**
* @test
*/
public function getAccessConditionsForBookDocument()
{
$accessConditions = $this->bookReader->getAccessConditions();
self::assertNotEmpty($accessConditions);
self::assertEquals(1, count($accessConditions));
self::assertAccessConditionForBookDocument($accessConditions[0]);
}

/**
* @test
*/
public function getAccessConditionForBookDocument()
{
$accessCondition = $this->bookReader->getAccessCondition(0);
self::assertAccessConditionForBookDocument($accessCondition);
}

/**
* @test
*/
public function getFirstAccessConditionForBookDocument()
{
$accessCondition = $this->bookReader->getFirstAccessCondition();
self::assertAccessConditionForBookDocument($accessCondition);
}

/**
* @test
*/
public function getLastAccessConditionForBookDocument()
{
$accessCondition = $this->bookReader->getLastAccessCondition();
self::assertAccessConditionForBookDocument($accessCondition);
}

/**
* @test
*/
public function getAccessConditionsByQueryForBookDocument()
{
$accessConditions = $this->bookReader->getAccessConditions('[@type="use and reproduction"]');
self::assertNotEmpty($accessConditions);
self::assertEquals(1, count($accessConditions));
self::assertAccessConditionForBookDocument($accessConditions[0]);
}

/**
* @test
*/
public function getFirstAccessConditionByQueryForBookDocument()
{
$accessCondition = $this->bookReader->getFirstAccessCondition('[@type="use and reproduction"]');
self::assertAccessConditionForBookDocument($accessCondition);
}

/**
* @test
*/
public function getLastAccessConditionByQueryForBookDocument()
{
$accessCondition = $this->bookReader->getLastAccessCondition('[@type="use and reproduction"]');
self::assertAccessConditionForBookDocument($accessCondition);
}

/**
* @test
*/
public function getNoAccessConditionsByQueryForBookDocument()
{
$accessConditions = $this->bookReader->getAccessConditions('[@type="restriction on access"]');
self::assertEmpty($accessConditions);
}

/**
* @test
*/
public function getNoAccessConditionByQueryForBookDocument()
{
$accessCondition = $this->bookReader->getAccessCondition(1, '[@type="restriction on access"]');
self::assertNull($accessCondition);
}

/**
* @test
*/
public function getNoFirstAccessConditionsByQueryForBookDocument()
{
$accessCondition = $this->bookReader->getFirstAccessCondition('[@type="restriction on access"]');
self::assertNull($accessCondition);
}

/**
* @test
*/
public function getNoLastAccessConditionsByQueryForBookDocument()
{
$accessCondition = $this->bookReader->getLastAccessCondition('[@type="restriction on access"]');
self::assertNull($accessCondition);
}

/**
* @test
*/
public function getAccessConditionsForSerialDocument()
{
$accessConditions = $this->serialReader->getAccessConditions();
self::assertNotEmpty($accessConditions);
self::assertEquals(1, count($accessConditions));
self::assertAccessConditionForSerialDocument($accessConditions[0]);
}

/**
* @test
*/
public function getAccessConditionsByQueryForSerialDocument()
{
$accessConditions = $this->serialReader->getAccessConditions('[@type="restriction on access"]');
self::assertNotEmpty($accessConditions);
self::assertEquals(1, count($accessConditions));
self::assertAccessConditionForSerialDocument($accessConditions[0]);
}

/**
* @test
*/
public function getNoAccessConditionsByQueryForSerialDocument()
{
$accessConditions = $this->serialReader->getAccessConditions('[@type="use and reproduction"]');
self::assertEmpty($accessConditions);
}

private static function assertAccessConditionForBookDocument(AccessCondition $accessCondition)
{
self::assertNotEmpty($accessCondition->getValue());
self::assertEquals('Use of this public-domain resource is unrestricted.', $accessCondition->getValue());
self::assertNotEmpty($accessCondition->getType());
self::assertEquals('use and reproduction', $accessCondition->getType());
self::assertEmpty($accessCondition->getDisplayLabel());
self::assertEmpty($accessCondition->getXlinkHref());
}

private static function assertAccessConditionForSerialDocument(AccessCondition $accessCondition)
{
self::assertNotEmpty($accessCondition->getValue());
self::assertEquals('Open Access', $accessCondition->getValue());
self::assertNotEmpty($accessCondition->getType());
self::assertEquals('restriction on access', $accessCondition->getType());
self::assertNotEmpty($accessCondition->getDisplayLabel());
self::assertEquals('Access Status', $accessCondition->getDisplayLabel());
// TODO: check out xlink
// self::assertEquals('http://purl.org/eprint/accessRights/OpenAccess', $accessCondition->getXlinkHref());
}
}
Loading

0 comments on commit 659700e

Please sign in to comment.