ILIAS  release_8 Revision v8.23
ilRisParserTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
24 
25 class 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;
42  $DIC = $this->dic_backup;
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
127 A2 - Schrode, Paula
128 A2 - Simon, Udo Gerald
129 T1 - Die Sunna leben
130 T2 - zur Dynamik islamischer Religionspraxis in Deutschland
131 CY - Würzburg
132 Y1 - 2012
133 PB - Egon
134 KW - Deutschland
135 KW - Islam
136 KW - Religionsausübung
137 KW - Kongress
138 EP - 250 S.
139 SN - 978-3-89913-722-4
140 U1 - Wilhelmstraße
141 ER -
142 TY - JOURNAL
143 A2 - Gienow-Hecht, Jessica C. E.
144 T1 - Searching for a cultural diplomacy
145 CY - New York [u.a.]
146 Y1 - 2010
147 PB - Berghahn
148 KW - Sowjetunion
149 KW - Mitteleuropa
150 KW - Naher Osten
151 KW - Japan
152 KW - Kulturbeziehungen
153 KW - Diplomatie
154 KW - Geschichte 1900-2000
155 KW - Aufsatzsammlung
156 EP - XII, 265 S.
157 SN - 978-1-84545-746-4
158 U1 - Wilhelmstraße
159 ER - ';
160  }
161 }
ILIAS DI Container $dic_backup
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:31
global $DIC
Definition: feed.php:28
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...