We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | /** |
||||||
| 4 | * (c) Kitodo. Key to digital objects e.V. <[email protected]> |
||||||
| 5 | * |
||||||
| 6 | * This file is part of the Kitodo and TYPO3 projects. |
||||||
| 7 | * |
||||||
| 8 | * @license GNU General Public License version 3 or later. |
||||||
| 9 | * For the full copyright and license information, please read the |
||||||
| 10 | * LICENSE.txt file that was distributed with this source code. |
||||||
| 11 | */ |
||||||
| 12 | |||||||
| 13 | namespace Kitodo\Dlf\Tests\Functional\Common; |
||||||
| 14 | |||||||
| 15 | use Kitodo\Dlf\Common\AbstractDocument; |
||||||
| 16 | use Kitodo\Dlf\Tests\Functional\FunctionalTestCase; |
||||||
| 17 | |||||||
| 18 | class MetsDocumentTest extends FunctionalTestCase |
||||||
| 19 | { |
||||||
| 20 | public function setUp(): void |
||||||
| 21 | { |
||||||
| 22 | parent::setUp(); |
||||||
| 23 | |||||||
| 24 | $this->importCSVDataSet(__DIR__ . '/../../Fixtures/Common/documents_1.csv'); |
||||||
| 25 | $this->importCSVDataSet(__DIR__ . '/../../Fixtures/Common/metadata.csv'); |
||||||
| 26 | $this->importCSVDataSet(__DIR__ . '/../../Fixtures/MetsDocument/metadata_mets.csv'); |
||||||
| 27 | } |
||||||
| 28 | |||||||
| 29 | protected function doc(string $file) |
||||||
| 30 | { |
||||||
| 31 | $url = 'http://web:8001/Tests/Fixtures/MetsDocument/' . $file; |
||||||
| 32 | $doc = AbstractDocument::getInstance($url, ['general' => ['useExternalApisForMetadata' => 0]]); |
||||||
| 33 | self::assertNotNull($doc); |
||||||
| 34 | return $doc; |
||||||
| 35 | } |
||||||
| 36 | |||||||
| 37 | /** |
||||||
| 38 | * @test |
||||||
| 39 | */ |
||||||
| 40 | public function canParseDmdAndAmdSec() |
||||||
| 41 | { |
||||||
| 42 | $doc = $this->doc('av_beispiel.xml'); |
||||||
| 43 | |||||||
| 44 | $toplevelMetadata = $doc->getToplevelMetadata(20000); |
||||||
| 45 | |||||||
| 46 | self::assertEquals(['Odol-Mundwasser, 3 Werbespots'], $toplevelMetadata['title']); |
||||||
| 47 | self::assertEquals(['24'], $toplevelMetadata['frame_rate']); |
||||||
| 48 | self::assertEquals(['Sächsische Landesbibliothek - Staats- und Universitätsbibliothek Dresden'], $toplevelMetadata['dvrights_owner']); |
||||||
| 49 | self::assertEquals(['https://katalog.slub-dresden.de/id/0-1703800435'], $toplevelMetadata['dvlinks_reference']); |
||||||
| 50 | |||||||
| 51 | self::assertEquals([ |
||||||
| 52 | 'DMDLOG_0000' => $doc->mdSec['DMDLOG_0000'], |
||||||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||||||
| 53 | ], $doc->dmdSec); |
||||||
|
0 ignored issues
–
show
The property
dmdSec does not exist on Kitodo\Dlf\Common\AbstractDocument. Since you implemented __get, consider adding a @property annotation.
Loading history...
|
|||||||
| 54 | } |
||||||
| 55 | |||||||
| 56 | /** |
||||||
| 57 | * @test |
||||||
| 58 | */ |
||||||
| 59 | public function canReadFileMetadata() |
||||||
| 60 | { |
||||||
| 61 | $doc = $this->doc('av_beispiel.xml'); |
||||||
| 62 | |||||||
| 63 | $thumbsMeta = $doc->getMetadata('FILE_0000_THUMBS', 20000); |
||||||
| 64 | self::assertEquals($thumbsMeta, []); |
||||||
| 65 | |||||||
| 66 | $videoMeta = $doc->getMetadata('FILE_0000_DEFAULT', 20000); |
||||||
| 67 | self::assertArrayMatches([ |
||||||
|
0 ignored issues
–
show
The method
Kitodo\Dlf\Tests\Functio...e::assertArrayMatches() is not static, but was called statically.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 68 | 'frame_rate' => ['24'], |
||||||
| 69 | ], $videoMeta); |
||||||
| 70 | } |
||||||
| 71 | |||||||
| 72 | /** |
||||||
| 73 | * @test |
||||||
| 74 | */ |
||||||
| 75 | public function canGetLogicalStructure() |
||||||
| 76 | { |
||||||
| 77 | $doc = $this->doc('av_beispiel.xml'); |
||||||
| 78 | |||||||
| 79 | $toc = $doc->tableOfContents[0] ?? []; |
||||||
| 80 | |||||||
| 81 | self::assertArrayMatches([ |
||||||
|
0 ignored issues
–
show
The method
Kitodo\Dlf\Tests\Functio...e::assertArrayMatches() is not static, but was called statically.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 82 | 'dmdId' => 'DMDLOG_0000', |
||||||
| 83 | 'admId' => 'AMD', |
||||||
| 84 | 'children' => [ |
||||||
| 85 | [ |
||||||
| 86 | 'id' => 'LOG_0001', |
||||||
| 87 | 'dmdId' => '', |
||||||
| 88 | 'admId' => '', |
||||||
| 89 | ], |
||||||
| 90 | [ |
||||||
| 91 | 'id' => 'LOG_0002', |
||||||
| 92 | 'dmdId' => '', |
||||||
| 93 | 'admId' => '', |
||||||
| 94 | ], |
||||||
| 95 | [ |
||||||
| 96 | 'id' => 'LOG_0003', |
||||||
| 97 | 'dmdId' => '', |
||||||
| 98 | 'admId' => '', |
||||||
| 99 | ], |
||||||
| 100 | [ |
||||||
| 101 | 'id' => 'LOG_0004', |
||||||
| 102 | 'dmdId' => '', |
||||||
| 103 | 'admId' => '', |
||||||
| 104 | ], |
||||||
| 105 | ], |
||||||
| 106 | ], $toc, 'Expected TOC to contain the specified values'); |
||||||
| 107 | } |
||||||
| 108 | |||||||
| 109 | /** |
||||||
| 110 | * @test |
||||||
| 111 | */ |
||||||
| 112 | public function doesNotOverwriteFirstDmdSec() |
||||||
| 113 | { |
||||||
| 114 | $doc = $this->doc('two_dmdsec.xml'); |
||||||
| 115 | |||||||
| 116 | $toplevelMetadata = $doc->getToplevelMetadata(20000); |
||||||
| 117 | $toc = $doc->tableOfContents[0] ?? []; |
||||||
| 118 | |||||||
| 119 | self::assertEquals('DMDLOG_0000 DMDLOG_0000b', $toc['dmdId']); // TODO: Do we want the raw (non-split) value here? |
||||||
| 120 | self::assertEquals('Test Value in DMDLOG_0000', $toplevelMetadata['test_value'][0]); |
||||||
| 121 | } |
||||||
| 122 | |||||||
| 123 | /** |
||||||
| 124 | * @test |
||||||
| 125 | */ |
||||||
| 126 | public function returnsEmptyMetadataWhenNoDmdSec() |
||||||
| 127 | { |
||||||
| 128 | $doc = $this->doc('two_dmdsec.xml'); |
||||||
| 129 | |||||||
| 130 | // DMD and AMD works |
||||||
| 131 | $metadata = $doc->getMetadata('LOG_0000', 20000); |
||||||
| 132 | self::assertEquals('Test Value in DMDLOG_0000', $metadata['test_value'][0]); |
||||||
| 133 | |||||||
| 134 | // DMD only works |
||||||
| 135 | $metadata = $doc->getMetadata('LOG_0001', 20000); |
||||||
| 136 | self::assertEquals(['Test Value in DMDLOG_0000b'], $metadata['test_value']); |
||||||
| 137 | |||||||
| 138 | // AMD only does not work |
||||||
| 139 | $metadata = $doc->getMetadata('LOG_0002', 20000); |
||||||
| 140 | self::assertEquals([], $metadata); |
||||||
| 141 | } |
||||||
| 142 | |||||||
| 143 | /** |
||||||
| 144 | * @test |
||||||
| 145 | */ |
||||||
| 146 | public function canGetDownloadLocation() |
||||||
| 147 | { |
||||||
| 148 | $doc = $this->doc('two_dmdsec.xml'); |
||||||
| 149 | |||||||
| 150 | $correct = $doc->getDownloadLocation('FILE_0000_DOWNLOAD'); |
||||||
| 151 | self::assertEquals('https://example.com/download?&CVT=jpeg', $correct); |
||||||
| 152 | |||||||
| 153 | /* |
||||||
| 154 | * The method `getDownloadLocation` should return a string, but returns null in some cases. |
||||||
| 155 | * Therefore, a TypeError must be expected here. |
||||||
| 156 | */ |
||||||
| 157 | $this->expectException('TypeError'); |
||||||
| 158 | $doc->getDownloadLocation('ID_DOES_NOT_EXIST'); |
||||||
| 159 | } |
||||||
| 160 | |||||||
| 161 | |||||||
| 162 | /** |
||||||
| 163 | * @test |
||||||
| 164 | */ |
||||||
| 165 | public function canGetFileLocation() |
||||||
| 166 | { |
||||||
| 167 | $doc = $this->doc('two_dmdsec.xml'); |
||||||
| 168 | |||||||
| 169 | $correct = $doc->getFileLocation('FILE_0000_DEFAULT'); |
||||||
| 170 | self::assertEquals('https://digital.slub-dresden.de/data/kitodo/1703800435/video.mov', $correct); |
||||||
| 171 | |||||||
| 172 | $incorrect = $doc->getFileLocation('ID_DOES_NOT_EXIST'); |
||||||
| 173 | self::assertEquals('', $incorrect); |
||||||
| 174 | } |
||||||
| 175 | |||||||
| 176 | /** |
||||||
| 177 | * @test |
||||||
| 178 | */ |
||||||
| 179 | public function canGetFileMimeType() |
||||||
| 180 | { |
||||||
| 181 | $doc = $this->doc('two_dmdsec.xml'); |
||||||
| 182 | |||||||
| 183 | $correct = $doc->getFileMimeType('FILE_0000_DEFAULT'); |
||||||
| 184 | self::assertEquals('video/quicktime', $correct); |
||||||
| 185 | |||||||
| 186 | $incorrect = $doc->getFileMimeType('ID_DOES_NOT_EXIST'); |
||||||
| 187 | self::assertEquals('', $incorrect); |
||||||
| 188 | } |
||||||
| 189 | |||||||
| 190 | // FIXME: Method getPhysicalPage does not work as expected |
||||||
| 191 | /** |
||||||
| 192 | * @test |
||||||
| 193 | */ |
||||||
| 194 | public function canGetPhysicalPage() |
||||||
| 195 | { |
||||||
| 196 | $doc = $this->doc('mets_with_pages.xml'); |
||||||
| 197 | |||||||
| 198 | // pass orderlabel and retrieve order |
||||||
| 199 | $physicalPage = $doc->getPhysicalPage('1'); |
||||||
| 200 | self::assertEquals(1, $physicalPage); |
||||||
| 201 | } |
||||||
| 202 | |||||||
| 203 | /** |
||||||
| 204 | * @test |
||||||
| 205 | */ |
||||||
| 206 | public function canGetTitle() |
||||||
| 207 | { |
||||||
| 208 | $doc = $this->doc('mets_with_pages.xml'); |
||||||
| 209 | |||||||
| 210 | $correct = $doc->getTitle(1001); |
||||||
| 211 | self::assertEquals('10 Keyboard pieces - Go. S. 658', $correct); |
||||||
| 212 | |||||||
| 213 | $incorrect = $doc->getTitle(1234); |
||||||
| 214 | self::assertEquals('', $incorrect); |
||||||
| 215 | } |
||||||
| 216 | |||||||
| 217 | /** |
||||||
| 218 | * @test |
||||||
| 219 | */ |
||||||
| 220 | public function canGetFullText() |
||||||
| 221 | { |
||||||
| 222 | $doc = $this->doc('mets_with_pages.xml'); |
||||||
| 223 | |||||||
| 224 | $fulltext = $doc->getFullText('PHYS_0003'); |
||||||
| 225 | $expected = '<?xml version="1.0"?> |
||||||
| 226 | <ocr><b/><b/></ocr> |
||||||
| 227 | '; |
||||||
| 228 | self::assertEquals($expected, $fulltext); |
||||||
| 229 | |||||||
| 230 | $incorrect = $doc->getFullText('ID_DOES_NOT_EXIST'); |
||||||
| 231 | self::assertEquals('', $incorrect); |
||||||
| 232 | } |
||||||
| 233 | |||||||
| 234 | /** |
||||||
| 235 | * @test |
||||||
| 236 | */ |
||||||
| 237 | public function canGetStructureDepth() |
||||||
| 238 | { |
||||||
| 239 | $doc = $this->doc('mets_with_pages.xml'); |
||||||
| 240 | |||||||
| 241 | $correct = $doc->getStructureDepth('LOG_0001'); |
||||||
| 242 | self::assertEquals(3, $correct); |
||||||
| 243 | |||||||
| 244 | $incorrect = $doc->getStructureDepth('ID_DOES_NOT_EXIST'); |
||||||
| 245 | self::assertEquals(0, $incorrect); |
||||||
| 246 | } |
||||||
| 247 | } |
||||||
| 248 |