Completed
Push — master ( 1e45e0...9c8682 )
by
unknown
17s queued 14s
created

MetsDocumentTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 122
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 55
c 3
b 0
f 0
dl 0
loc 122
rs 10
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A returnsEmptyMetadataWhenNoDmdSec() 0 15 1
A doc() 0 6 1
A canReadFileMetadata() 0 11 1
A canParseDmdAndAmdSec() 0 14 1
A doesNotOverwriteFirstDmdSec() 0 9 1
A canGetLogicalStructure() 0 32 1
1
<?php
2
3
namespace Kitodo\Dlf\Tests\Functional\Common;
4
5
use Kitodo\Dlf\Common\Doc;
6
use Kitodo\Dlf\Tests\Functional\FunctionalTestCase;
7
8
class MetsDocumentTest extends FunctionalTestCase
9
{
10
    public function setUp(): void
11
    {
12
        parent::setUp();
13
14
        $this->importDataSet(__DIR__ . '/../../Fixtures/Common/metadata.xml');
0 ignored issues
show
Deprecated Code introduced by
The function TYPO3\TestingFramework\C...stCase::importDataSet() has been deprecated: Will be removed with core v12 compatible testing-framework. Importing database fixtures based on XML format is discouraged. Switch to CSV format instead. See core functional tests or styleguide for many examples how these look like. Use method importCSVDataSet() to import such fixture files and assertCSVDataSet() to compare database state with fixture files. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

14
        /** @scrutinizer ignore-deprecated */ $this->importDataSet(__DIR__ . '/../../Fixtures/Common/metadata.xml');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
15
        $this->importDataSet(__DIR__ . '/../../Fixtures/MetsDocument/metadata_mets.xml');
0 ignored issues
show
Deprecated Code introduced by
The function TYPO3\TestingFramework\C...stCase::importDataSet() has been deprecated: Will be removed with core v12 compatible testing-framework. Importing database fixtures based on XML format is discouraged. Switch to CSV format instead. See core functional tests or styleguide for many examples how these look like. Use method importCSVDataSet() to import such fixture files and assertCSVDataSet() to compare database state with fixture files. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

15
        /** @scrutinizer ignore-deprecated */ $this->importDataSet(__DIR__ . '/../../Fixtures/MetsDocument/metadata_mets.xml');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
16
    }
17
18
    protected function doc(string $file)
19
    {
20
        $url = 'http://web:8001/Tests/Fixtures/MetsDocument/' . $file;
21
        $doc = Doc::getInstance($url);
22
        $this->assertNotNull($doc);
23
        return $doc;
24
    }
25
26
    /**
27
     * @test
28
     */
29
    public function canParseDmdAndAmdSec()
30
    {
31
        $doc = $this->doc('av_beispiel.xml');
32
33
        $titledata = $doc->getTitledata(20000);
34
35
        $this->assertEquals(['Odol-Mundwasser, 3 Werbespots'], $titledata['title']);
36
        $this->assertEquals(['24'], $titledata['frame_rate']);
37
        $this->assertEquals(['Sächsische Landesbibliothek - Staats- und Universitätsbibliothek Dresden'], $titledata['dvrights_owner']);
38
        $this->assertEquals(['https://katalog.slub-dresden.de/id/0-1703800435'], $titledata['dvlinks_reference']);
39
40
        $this->assertEquals([
41
            'DMDLOG_0000' => $doc->mdSec['DMDLOG_0000'],
0 ignored issues
show
Bug Best Practice introduced by
The property mdSec does not exist on Kitodo\Dlf\Common\Doc. Since you implemented __get, consider adding a @property annotation.
Loading history...
42
        ], $doc->dmdSec);
0 ignored issues
show
Bug Best Practice introduced by
The property dmdSec does not exist on Kitodo\Dlf\Common\Doc. Since you implemented __get, consider adding a @property annotation.
Loading history...
43
    }
44
45
    /**
46
     * @test
47
     */
48
    public function canReadFileMetadata()
49
    {
50
        $doc = $this->doc('av_beispiel.xml');
51
52
        $thumbsMeta = $doc->getMetadata('FILE_0000_THUMBS', 20000);
53
        $this->assertEquals($thumbsMeta, []);
54
55
        $videoMeta = $doc->getMetadata('FILE_0000_DEFAULT', 20000);
56
        $this->assertArrayMatches([
57
            'frame_rate' => ['24'],
58
        ], $videoMeta);
59
    }
60
61
    /**
62
     * @test
63
     */
64
    public function canGetLogicalStructure()
65
    {
66
        $doc = $this->doc('av_beispiel.xml');
67
68
        $toc = $doc->tableOfContents[0] ?? [];
69
70
        $this->assertArrayMatches([
71
            'dmdId' => 'DMDLOG_0000',
72
            'admId' => 'AMD',
73
            'children' => [
74
                [
75
                    'id' => 'LOG_0001',
76
                    'dmdId' => '',
77
                    'admId' => '',
78
                ],
79
                [
80
                    'id' => 'LOG_0002',
81
                    'dmdId' => '',
82
                    'admId' => '',
83
                ],
84
                [
85
                    'id' => 'LOG_0003',
86
                    'dmdId' => '',
87
                    'admId' => '',
88
                ],
89
                [
90
                    'id' => 'LOG_0004',
91
                    'dmdId' => '',
92
                    'admId' => '',
93
                ],
94
            ],
95
        ], $toc, 'Expected TOC to contain the specified values');
96
    }
97
98
    /**
99
     * @test
100
     */
101
    public function doesNotOverwriteFirstDmdSec()
102
    {
103
        $doc = $this->doc('two_dmdsec.xml');
104
105
        $titledata = $doc->getTitledata(20000);
106
        $toc = $doc->tableOfContents[0] ?? [];
107
108
        $this->assertEquals('DMDLOG_0000 DMDLOG_0000b', $toc['dmdId']); // TODO: Do we want the raw (non-split) value here?
109
        $this->assertEquals('Test Value in DMDLOG_0000', $titledata['test_value'][0]);
110
    }
111
112
    /**
113
     * @test
114
     */
115
    public function returnsEmptyMetadataWhenNoDmdSec()
116
    {
117
        $doc = $this->doc('two_dmdsec.xml');
118
119
        // DMD and AMD works
120
        $metadata = $doc->getMetadata('LOG_0000', 20000);
121
        $this->assertEquals('Test Value in DMDLOG_0000', $metadata['test_value'][0]);
122
123
        // DMD only works
124
        $metadata = $doc->getMetadata('LOG_0001', 20000);
125
        $this->assertEquals(['Test Value in DMDLOG_0000b'], $metadata['test_value']);
126
127
        // AMD only does not work
128
        $metadata = $doc->getMetadata('LOG_0002', 20000);
129
        $this->assertEquals([], $metadata);
130
    }
131
}
132