Passed
Pull Request — master (#123)
by
unknown
05:01
created

ModsTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 31
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 28
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 31
rs 9.472
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\Unit\Format;
14
15
use Kitodo\Dlf\Format\Mods;
16
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
17
18
class ModsTest extends UnitTestCase
19
{
20
    protected $metadata = [];
21
22
    public function setUp(): void
23
    {
24
        parent::setUp();
25
26
        $this->metadata = [
27
            'title' => [],
28
            'title_sorting' => [],
29
            'author' => [],
30
            'place' => [],
31
            'place_sorting' => [0 => []],
32
            'year' => [],
33
            'prod_id' => [],
34
            'record_id' => [],
35
            'opac_id' => [],
36
            'union_id' => [],
37
            'urn' => [],
38
            'purl' => [],
39
            'type' => [],
40
            'volume' => [],
41
            'volume_sorting' => [],
42
            'license' => [],
43
            'terms' => [],
44
            'restrictions' => [],
45
            'out_of_print' => [],
46
            'rights_info' => [],
47
            'collection' => [],
48
            'owner' => [],
49
            'mets_label' => [],
50
            'mets_orderlabel' => [],
51
            'document_format' => ['METS'],
52
            'year_sorting' => [0 => []],
53
        ];
54
55
    }
56
57
    /**
58
     * @test
59
     * @group extractMetadata
60
     */
61
    public function extractAuthorsIfNoAutRoleTermAssigned(): void
62
    {
63
        $xml = simplexml_load_file(__DIR__ . '/../../Fixtures/Format/modsAuthorNoAutRoleTerm.xml');
64
        $mods = new Mods();
65
66
        $mods->extractMetadata($xml, $this->metadata, false);
67
68
        self::assertEquals(
69
            [
70
                "AnonymousGiven1 AnonymousFamily1",
71
                "AnonymousFamily2, AnonymousGiven2"
72
            ],
73
            $this->metadata['author']
74
        );
75
    }
76
77
    /**
78
     * @test
79
     * @group extractMetadata
80
     */
81
    public function extractAuthorsWithAutRoleTermAssigned(): void
82
    {
83
        $xml = simplexml_load_file(__DIR__ . '/../../Fixtures/Format/modsAuthorWithAutRoleTerm.xml');
84
        $mods = new Mods();
85
86
        $mods->extractMetadata($xml, $this->metadata, false);
87
        self::assertEquals(
88
            [
89
                'May, Jack, I',
90
                'John Paul, Pope, 1920-2005',
91
                'Mattox, Douglas E., 1947-',
92
                '1882-1941, Woolf, Virginia',
93
                'Eric Alterman'
94
            ],
95
            $this->metadata['author']
96
        );
97
    }
98
99
    /**
100
     * @test
101
     * @group extractMetadata
102
     */
103
    public function extractPlaces(): void
104
    {
105
        $xml = simplexml_load_file(__DIR__ . '/../../Fixtures/Format/modsOriginInfo.xml');
106
        $mods = new Mods();
107
108
        $mods->extractMetadata($xml, $this->metadata, false);
109
110
        self::assertEquals(
111
            [
112
                "Dresden",
113
                "Hamburg",
114
                "Berlin",
115
                "München",
116
            ],
117
            $this->metadata['place']
118
        );
119
120
        self::assertEquals(
121
            [
122
                "Dresden",
123
            ],
124
            $this->metadata['place_sorting']
125
        );
126
    }
127
128
    /**
129
     * @test
130
     * @group extractMetadata
131
     */
132
    public function extractYears(): void
133
    {
134
        $xml = simplexml_load_file(__DIR__ . '/../../Fixtures/Format/modsOriginInfo.xml');
135
        $mods = new Mods();
136
137
        $mods->extractMetadata($xml, $this->metadata, false);
138
139
        self::assertEquals(
140
            [
141
                "2019",
142
                "2018",
143
                "2021",
144
                "2020",
145
            ],
146
            $this->metadata['year']
147
        );
148
149
        self::assertEquals(
150
            [
151
                "2019",
152
            ],
153
            $this->metadata['year_sorting']
154
        );
155
    }
156
157
    /**
158
     * @test
159
     * @group extractMetadata
160
     */
161
    public function extractPlacesWithElectronicEdInside(): void
162
    {
163
        $xml = simplexml_load_file(__DIR__ . '/../../Fixtures/Format/modsOriginInfoWithEditionElectronicEd.xml');
164
        $mods = new Mods();
165
166
        $mods->extractMetadata($xml, $this->metadata, false);
167
168
        self::assertEquals(
169
            [
170
                "Dresden",
171
                "Hamburg",
172
                "Berlin",
173
                "München",
174
            ],
175
            $this->metadata['place']
176
        );
177
178
        self::assertEquals(
179
            [
180
                "Dresden",
181
            ],
182
            $this->metadata['place_sorting']
183
        );
184
    }
185
186
    /**
187
     * @test
188
     * @group extractMetadata
189
     */
190
    public function extractYearsWithElectronicEdInside(): void
191
    {
192
        $xml = simplexml_load_file(__DIR__ . '/../../Fixtures/Format/modsOriginInfoWithEditionElectronicEd.xml');
193
        $mods = new Mods();
194
195
        $mods->extractMetadata($xml, $this->metadata, false);
196
197
        self::assertEquals(
198
            [
199
                "2019",
200
                "2018",
201
                "2021",
202
                "2020",
203
            ],
204
            $this->metadata['year']
205
        );
206
207
        self::assertEquals(
208
            [
209
                "2019",
210
            ],
211
            $this->metadata['year_sorting']
212
        );
213
    }
214
}
215