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 19, 2024
1 parent a3068da commit e9ff2fb
Show file tree
Hide file tree
Showing 20 changed files with 2,568 additions and 1,474 deletions.
1,478 changes: 4 additions & 1,474 deletions tests/Mods/ModsReaderTest.php

Large diffs are not rendered by default.

76 changes: 76 additions & 0 deletions tests/Mods/Reader/AbstractReaderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?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
{

public function testGetAbstractForBookDocument()
{
$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());
}

public function testGetAbstractByQueryForBookDocument()
{
$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());
}

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

public function testGetAbstractForSerialDocument()
{
$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());
}

public function testGetAbstractByQueryForSerialDocument()
{
$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());
}

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

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

public function testGetAccessConditionForBookDocument()
{
$accessCondition = $this->bookReader->getAccessCondition(0);
self::assertAccessConditionForBookDocument($accessCondition);
}

public function testGetFirstAccessConditionForBookDocument()
{
$accessCondition = $this->bookReader->getFirstAccessCondition();
self::assertAccessConditionForBookDocument($accessCondition);
}

public function testGetLastAccessConditionForBookDocument()
{
$accessCondition = $this->bookReader->getLastAccessCondition();
self::assertAccessConditionForBookDocument($accessCondition);
}

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

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

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

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

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

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

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

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

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

public function testGetNoAccessConditionsByQueryForSerialDocument()
{
$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());
}
}
138 changes: 138 additions & 0 deletions tests/Mods/Reader/ClassificationReaderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<?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\Classification;
use Slub\Mods\ModsReaderTest;

/**
* Tests for reading Classification element
*/
class ClassificationReaderTest extends ModsReaderTest
{

public function testGetClassificationsForBookDocument()
{
$classifications = $this->bookReader->getClassifications();
self::assertNotEmpty($classifications);
self::assertEquals(2, count($classifications));
self::assertFirstClassificationForBookDocument($classifications[0]);
}

public function testGetClassificationForBookDocument()
{
$classification = $this->bookReader->getClassification(0);
self::assertFirstClassificationForBookDocument($classification);
}

public function testGetFirstClassificationForBookDocument()
{
$classification = $this->bookReader->getFirstClassification();
self::assertFirstClassificationForBookDocument($classification);
}

public function testGetLastClassificationForBookDocument()
{
$classification = $this->bookReader->getLastClassification();
self::assertSecondClassificationForBookDocument($classification);
}

public function testGetClassificationsByQueryForBookDocument()
{
$classifications = $this->bookReader->getClassifications('[@authority="ddc"]');
self::assertNotEmpty($classifications);
self::assertEquals(1, count($classifications));
self::assertSecondClassificationForBookDocument($classifications[0]);
}

public function testGetNoClassificationsByQueryForBookDocument()
{
$classifications = $this->bookReader->getClassifications('[@generator="xyz"]');
self::assertEmpty($classifications);
}

public function testGetNoClassificationByQueryForBookDocument()
{
$classification = $this->bookReader->getClassification(1, '[@generator="xyz"]');
self::assertNull($classification);
}

public function testGetNoFirstClassificationByQueryForBookDocument()
{
$classification = $this->bookReader->getFirstClassification('[@generator="xyz"]');
self::assertNull($classification);

$lastClassification = $this->bookReader->getLastClassification('[@generator="xyz"]');
self::assertNull($lastClassification);
}

public function testGetNoLastClassificationByQueryForBookDocument()
{
$classification = $this->bookReader->getLastClassification('[@generator="xyz"]');
self::assertNull($classification);
}

public function testGetClassificationsForSerialDocument()
{
$classifications = $this->serialReader->getClassifications();
self::assertNotEmpty($classifications);
self::assertEquals(1, count($classifications));
self::assertClassificationForSerialDocument($classifications[0]);
}

public function testGetClassificationsByQueryForSerialDocument()
{
$classifications = $this->serialReader->getClassifications('[@authority="ddc"]');
self::assertNotEmpty($classifications);
self::assertEquals(1, count($classifications));
self::assertClassificationForSerialDocument($classifications[0]);
}

public function testGetNoClassificationsByQueryForSerialDocument()
{
$classifications = $this->serialReader->getClassifications('[@edition="22"]');
self::assertEmpty($classifications);
}

private static function assertFirstClassificationForBookDocument(Classification $classification)
{
self::assertNotEmpty($classification->getValue());
self::assertEquals('PN4888.P6 A48 1999', $classification->getValue());
self::assertNotEmpty($classification->getAuthority());
self::assertEquals('lcc', $classification->getAuthority());
self::assertEmpty($classification->getId());
self::assertEmpty($classification->getUsage());
}

private static function assertSecondClassificationForBookDocument(Classification $classification)
{
self::assertNotEmpty($classification->getValue());
self::assertEquals('071/.3', $classification->getValue());
self::assertNotEmpty($classification->getEdition());
self::assertEquals('21', $classification->getEdition());
self::assertEmpty($classification->getDisplayLabel());
self::assertEmpty($classification->getGenerator());
}

private static function assertClassificationForSerialDocument(Classification $classification)
{
self::assertNotEmpty($classification->getValue());
self::assertEquals('027.7/05', $classification->getValue());
self::assertNotEmpty($classification->getAuthority());
self::assertEquals('ddc', $classification->getAuthority());
self::assertNotEmpty($classification->getEdition());
self::assertEquals('21', $classification->getEdition());
self::assertEmpty($classification->getDisplayLabel());
self::assertEmpty($classification->getGenerator());
}
}
36 changes: 36 additions & 0 deletions tests/Mods/Reader/ExtensionReaderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?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 Extension element
*/
class ExtensionReaderTest extends ModsReaderTest
{

public function testGetExtensionsForBookDocument()
{
$extensions = $this->bookReader->getExtensions();

$this->assertTrue(true, 'WIP');
}

public function testGetExtensionsForSerialDocument()
{
$extensions = $this->serialReader->getExtensions();

$this->assertTrue(true, 'WIP');
}
}
Loading

0 comments on commit e9ff2fb

Please sign in to comment.