ILIAS  release_8 Revision v8.24
ilRisParserTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
21use PHPUnit\Framework\TestCase;
24
25class ilRisParserTest extends TestCase
26{
28
29 protected function setUp(): void
30 {
31 global $DIC;
32 $this->dic_backup = is_object($DIC) ? clone $DIC : $DIC;
33
34 $DIC = new Container();
35 $DIC['resource_storage'] = $this->createMock(Services::class);
36 $DIC['ilDB'] = $this->createMock(ilDBInterface::class);
37 }
38
39 protected function tearDown(): void
40 {
41 global $DIC;
43 }
44
45 public function testParseRisAsArray(): void
46 {
47 $ilBiblEntryFactory = $this->createMock(ilBiblEntryFactoryInterface::class);
48 $ilBiblFieldFactory = $this->createMock(ilBiblFieldFactoryInterface::class);
49 $ilBiblAttributeFactory = $this->createMock(ilBiblAttributeFactoryInterface::class);
50 $reader = new ilBiblRisFileReader(
51 $ilBiblEntryFactory,
52 $ilBiblFieldFactory,
53 $ilBiblAttributeFactory
54 );
55 $reader->setFileContent($this->getRisContent());
56 $content = $reader->parseContent();
57
58 $this->assertIsArray($content);
59 $this->assertEquals(2, count($content));
60
61 // First item
62 $first_item = $content[0];
63
64 $this->assertEquals('BOOK', $first_item['TY']);
65 $this->assertEquals('Schrode, Paula, Simon, Udo Gerald', $first_item['A2']);
66 $this->assertEquals('Die Sunna leben', $first_item['T1']);
67 $this->assertEquals('zur Dynamik islamischer Religionspraxis in Deutschland', $first_item['T2']);
68 $this->assertEquals('Würzburg', $first_item['CY']);
69 $this->assertEquals('2012', $first_item['Y1']);
70 $this->assertEquals('Egon', $first_item['PB']);
71 $this->assertEquals('Deutschland, Islam, Religionsausübung, Kongress', $first_item['KW']);
72 $this->assertEquals('250 S.', $first_item['EP']);
73 $this->assertEquals('978-3-89913-722-4', $first_item['SN']);
74
75 // Second item
76 $second_item = $content[1];
77
78 $this->assertEquals('JOURNAL', $second_item['TY']);
79 $this->assertEquals('Gienow-Hecht, Jessica C. E.', $second_item['A2']);
80 $this->assertEquals('Searching for a cultural diplomacy', $second_item['T1']);
81 $this->assertEquals('New York [u.a.]', $second_item['CY']);
82 $this->assertEquals('2010', $second_item['Y1']);
83 $this->assertEquals('Berghahn', $second_item['PB']);
84 $this->assertEquals('Sowjetunion, Mitteleuropa, Naher Osten, Japan, Kulturbeziehungen, Diplomatie, Geschichte 1900-2000, Aufsatzsammlung', $second_item['KW']);
85 $this->assertEquals('XII, 265 S.', $second_item['EP']);
86 $this->assertEquals('978-1-84545-746-4', $second_item['SN']);
87 }
88
89 public function testParseRisAsItems(): void
90 {
91 $ilBiblEntryFactory = $this->createMock(ilBiblEntryFactoryInterface::class);
92 $ilBiblFieldFactory = $this->createMock(ilBiblFieldFactoryInterface::class);
93 $ilBiblAttributeFactory = $this->createMock(ilBiblAttributeFactoryInterface::class);
94 $ilObjBibliographic = $this->createMock(ilObjBibliographic::class);
95
96 $reader = new ilBiblRisFileReader(
97 $ilBiblEntryFactory,
98 $ilBiblFieldFactory,
99 $ilBiblAttributeFactory
100 );
101 $reader->setFileContent($this->getRisContent());
102
103 $ilBiblEntryFactory->expects($this->atLeast(2))
104 ->method('getEmptyInstance')
105 ->willReturnOnConsecutiveCalls(new ilBiblEntry(), new ilBiblEntry());
106
107
108 $content = $reader->parseContentToEntries($ilObjBibliographic);
109
110 $this->assertIsArray($content);
111 $this->assertEquals(2, count($content));
112 $this->assertContainsOnlyInstancesOf(ilBiblEntry::class, $content);
113
114 // First item
116 $first_item = $content[0];
117 $this->assertEquals('BOOK', $first_item->getType());
118 // Second Item
120 $second_item = $content[1];
121 $this->assertEquals('JOURNAL', $second_item->getType());
122 }
123
124 protected function getRisContent(): string
125 {
126 return 'TY - BOOK
127A2 - Schrode, Paula
128A2 - Simon, Udo Gerald
129T1 - Die Sunna leben
130T2 - zur Dynamik islamischer Religionspraxis in Deutschland
131CY - Würzburg
132Y1 - 2012
133PB - Egon
134KW - Deutschland
135KW - Islam
136KW - Religionsausübung
137KW - Kongress
138EP - 250 S.
139SN - 978-3-89913-722-4
140U1 - Wilhelmstraße
141ER -
142TY - JOURNAL
143A2 - Gienow-Hecht, Jessica C. E.
144T1 - Searching for a cultural diplomacy
145CY - New York [u.a.]
146Y1 - 2010
147PB - Berghahn
148KW - Sowjetunion
149KW - Mitteleuropa
150KW - Naher Osten
151KW - Japan
152KW - Kulturbeziehungen
153KW - Diplomatie
154KW - Geschichte 1900-2000
155KW - Aufsatzsammlung
156EP - XII, 265 S.
157SN - 978-1-84545-746-4
158U1 - Wilhelmstraße
159ER - ';
160 }
161}
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:32
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ILIAS DI Container $dic_backup
global $DIC
Definition: feed.php:28