ILIAS  release_8 Revision v8.24
ilBibtechParserTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
21use PHPUnit\Framework\TestCase;
24
25class ilBibtechParserTest 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 testParseBibtechAsArray(): void
46 {
47 $ilBiblEntryFactory = $this->createMock(ilBiblEntryFactoryInterface::class);
48 $ilBiblFieldFactory = $this->createMock(ilBiblFieldFactoryInterface::class);
49 $ilBiblAttributeFactory = $this->createMock(ilBiblAttributeFactoryInterface::class);
50 $reader = new ilBiblTexFileReader(
51 $ilBiblEntryFactory,
52 $ilBiblFieldFactory,
53 $ilBiblAttributeFactory
54 );
55 $reader->setFileContent($this->getBibtechContent());
56 $content = $reader->parseContent();
57 $this->assertIsArray($content);
58 $this->assertEquals(2, count($content));
59
60 // First item
61 $first_item = $content[0];
62 $this->assertEquals('book', $first_item['entryType']);
63 $this->assertEquals('Süß, Henrik http://www.testlink.ch', $first_item['author']);
64 $this->assertEquals('Last Minute Histologie: [Fit fürs Examen in 2 Tagen!]', $first_item['title']);
65 $this->assertEquals('München', $first_item['address']);
66 $this->assertEquals('2012', $first_item['year']);
67 $this->assertEquals('Elsevier, Urban & Fischer', $first_item['publisher']);
68 $this->assertEquals('Histologie. Lehrbuch', $first_item['keywords']);
69 $this->assertEquals('XIII, 103 S.', $first_item['pages']);
70 $this->assertEquals('1. Aufl.', $first_item['edition']);
71 $this->assertEquals('3-437-43015-7', $first_item['isbn']);
72
73 // Second item
74 $second_item = $content[1];
75 $this->assertEquals('journal', $second_item['entryType']);
76 $this->assertEquals('Voll, Markus http://de.wikipedia.org/wiki/a-z', $second_item['author']);
77 $this->assertEquals(
78 'Atlas of neuroanatomy for communication science and disorders: based on the work of Michael Schuenke, Erik Schulte, Udo Schumacher',
79 $second_item['title']
80 );
81 $this->assertEquals('New York', $second_item['address']);
82 $this->assertEquals('2012', $second_item['year']);
83 $this->assertEquals('Thieme', $second_item['publisher']);
84 $this->assertEquals(
85 'Sprachstörung. Zentralnervensystem. Neuroanatomie. Neuropathologie. Atlas',
86 $second_item['keywords']
87 );
88 $this->assertEquals('IX, 176 S.', $second_item['pages']);
89 $this->assertEquals('978-1-60406-649-4', $second_item['isbn']);
90 }
91
92 public function testParseBibtechAsItems(): void
93 {
94 $ilBiblEntryFactory = $this->createMock(ilBiblEntryFactoryInterface::class);
95 $ilBiblFieldFactory = $this->createMock(ilBiblFieldFactoryInterface::class);
96 $ilBiblAttributeFactory = $this->createMock(ilBiblAttributeFactoryInterface::class);
97 $ilObjBibliographic = $this->createMock(ilObjBibliographic::class);
98
99 $reader = new ilBiblTexFileReader(
100 $ilBiblEntryFactory,
101 $ilBiblFieldFactory,
102 $ilBiblAttributeFactory
103 );
104 $reader->setFileContent($this->getBibtechContent());
105
106 $ilBiblEntryFactory->expects($this->atLeast(2))
107 ->method('getEmptyInstance')
108 ->willReturnOnConsecutiveCalls(new ilBiblEntry(), new ilBiblEntry());
109
110
111 $content = $reader->parseContentToEntries($ilObjBibliographic);
112
113 $this->assertIsArray($content);
114 $this->assertEquals(2, count($content));
115 $this->assertContainsOnlyInstancesOf(ilBiblEntry::class, $content);
116
117 // First item
119 $first_item = $content[0];
120 $this->assertEquals('book', $first_item->getType());
121 // Second Item
123 $second_item = $content[1];
124 $this->assertEquals('journal', $second_item->getType());
125 }
126
127 protected function getBibtechContent(): string
128 {
129 return '@book {
130author = {Süß, Henrik http://www.testlink.ch},
131title = {Last Minute Histologie: [Fit fürs Examen in 2 Tagen!]},
132address = {München},
133year = {2012},
134publisher = {Elsevier, Urban & Fischer},
135keywords = {Histologie. Lehrbuch},
136pages = {XIII, 103 S.},
137edition = {1. Aufl.},
138ISBN = {978-3-437-43015-2},
139ISBN = {3-437-43015-7},
140}
141@journal {
142author = {Voll, Markus http://de.wikipedia.org/wiki/a-z},
143editor = {Voll, Markus},
144title = {Atlas of neuroanatomy for communication science and disorders: based on the work of Michael Schuenke, Erik Schulte, Udo Schumacher},
145address = {New York},
146year = {2012},
147publisher = {Thieme},
148keywords = {Sprachstörung. Zentralnervensystem. Neuroanatomie. Neuropathologie. Atlas},
149pages = {IX, 176 S.},
150ISBN = {978-1-60406-649-4},
151}';
152 }
153}
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