|
1
|
|
|
<?php |
|
2
|
|
|
/* Copyright (C) 2017 Michael Giesler |
|
3
|
|
|
* |
|
4
|
|
|
* This file is part of Dembelo. |
|
5
|
|
|
* |
|
6
|
|
|
* Dembelo is free software: you can redistribute it and/or modify |
|
7
|
|
|
* it under the terms of the GNU Affero General Public License as published by |
|
8
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
9
|
|
|
* (at your option) any later version. |
|
10
|
|
|
* |
|
11
|
|
|
* Dembelo is distributed in the hope that it will be useful, |
|
12
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14
|
|
|
* GNU Affero General Public License 3 for more details. |
|
15
|
|
|
* |
|
16
|
|
|
* You should have received a copy of the GNU Affero General Public License 3 |
|
17
|
|
|
* along with Dembelo. If not, see <http://www.gnu.org/licenses/>. |
|
18
|
|
|
*/ |
|
19
|
|
|
namespace AdminBundle\Tests\Service\TwineImport; |
|
20
|
|
|
|
|
21
|
|
|
use AdminBundle\Service\TwineImport\ParserContext; |
|
22
|
|
|
use DembeloMain\Document\Importfile; |
|
23
|
|
|
use DembeloMain\Document\Textnode; |
|
24
|
|
|
use PHP_CodeSniffer\Generators\Text; |
|
25
|
|
|
use PHPUnit\Framework\TestCase; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Class ParserContextTest |
|
29
|
|
|
*/ |
|
30
|
|
|
class ParserContextTest extends TestCase |
|
31
|
|
|
{ |
|
32
|
|
|
/** |
|
33
|
|
|
* @return void |
|
34
|
|
|
*/ |
|
35
|
|
|
public function testInit(): void |
|
36
|
|
|
{ |
|
37
|
|
|
/* @var $importFileMock \PHPUnit_Framework_MockObject_MockObject|Importfile*/ |
|
38
|
|
|
$importFileMock = $this->createMock(Importfile::class); |
|
39
|
|
|
$importFileMock->expects(self::once()) |
|
40
|
|
|
->method('getLicenseeId') |
|
41
|
|
|
->willReturn('someId'); |
|
42
|
|
|
$importFileMock->expects(self::once()) |
|
43
|
|
|
->method('getFilename') |
|
44
|
|
|
->willReturn('someFilename'); |
|
45
|
|
|
|
|
46
|
|
|
$parserContext = new ParserContext(); |
|
47
|
|
|
$parserContext->init($importFileMock); |
|
48
|
|
|
self::assertSame($importFileMock, $parserContext->getImportfile()); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @expectedException \Exception |
|
53
|
|
|
* |
|
54
|
|
|
* @expectedExceptionMessage no licensee available |
|
55
|
|
|
*/ |
|
56
|
|
|
public function testInitWithoutLicenseeId(): void |
|
57
|
|
|
{ |
|
58
|
|
|
/* @var $importFileMock \PHPUnit_Framework_MockObject_MockObject|Importfile*/ |
|
59
|
|
|
$importFileMock = $this->createMock(Importfile::class); |
|
60
|
|
|
$importFileMock->expects(self::any()) |
|
61
|
|
|
->method('getLicenseeId') |
|
62
|
|
|
->willReturn(null); |
|
63
|
|
|
$importFileMock->expects(self::any()) |
|
64
|
|
|
->method('getFilename') |
|
65
|
|
|
->willReturn('someFilename'); |
|
66
|
|
|
|
|
67
|
|
|
$parserContext = new ParserContext(); |
|
68
|
|
|
$parserContext->init($importFileMock); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @expectedException \Exception |
|
73
|
|
|
* |
|
74
|
|
|
* @expectedExceptionMessage no filename available |
|
75
|
|
|
*/ |
|
76
|
|
|
public function testInitWithoutFilename(): void |
|
77
|
|
|
{ |
|
78
|
|
|
/* @var $importFileMock \PHPUnit_Framework_MockObject_MockObject|Importfile*/ |
|
79
|
|
|
$importFileMock = $this->createMock(Importfile::class); |
|
80
|
|
|
$importFileMock->expects(self::any()) |
|
81
|
|
|
->method('getLicenseeId') |
|
82
|
|
|
->willReturn('someId'); |
|
83
|
|
|
$importFileMock->expects(self::any()) |
|
84
|
|
|
->method('getFilename') |
|
85
|
|
|
->willReturn(null); |
|
86
|
|
|
|
|
87
|
|
|
$parserContext = new ParserContext(); |
|
88
|
|
|
$parserContext->init($importFileMock); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @return void |
|
93
|
|
|
*/ |
|
94
|
|
|
public function testGetFilename(): void |
|
95
|
|
|
{ |
|
96
|
|
|
/* @var $importFileMock \PHPUnit_Framework_MockObject_MockObject|Importfile*/ |
|
97
|
|
|
$importFileMock = $this->createMock(Importfile::class); |
|
98
|
|
|
$importFileMock->expects(self::any()) |
|
99
|
|
|
->method('getLicenseeId') |
|
100
|
|
|
->willReturn('someId'); |
|
101
|
|
|
$importFileMock->expects(self::any()) |
|
102
|
|
|
->method('getFilename') |
|
103
|
|
|
->willReturn('someFilename'); |
|
104
|
|
|
|
|
105
|
|
|
$parserContext = new ParserContext(); |
|
106
|
|
|
$parserContext->init($importFileMock); |
|
107
|
|
|
self::assertEquals('someFilename', $parserContext->getFilename()); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* @return void |
|
112
|
|
|
*/ |
|
113
|
|
|
public function testIsTwineRelevant(): void |
|
114
|
|
|
{ |
|
115
|
|
|
$parserContext = new ParserContext(); |
|
116
|
|
|
self::assertFalse($parserContext->isTwineRelevant()); |
|
117
|
|
|
$parserContext->setTwineRelevant(true); |
|
118
|
|
|
self::assertTrue($parserContext->isTwineRelevant()); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* @return void |
|
123
|
|
|
*/ |
|
124
|
|
|
public function testGetCurrentTextnode(): void |
|
125
|
|
|
{ |
|
126
|
|
|
/* @var $textnodeMock \PHPUnit_Framework_MockObject_MockObject|Textnode*/ |
|
127
|
|
|
$textnodeMock = $this->createMock(Textnode::class); |
|
128
|
|
|
$textnodeMock->expects(self::once()) |
|
129
|
|
|
->method('getTwineId') |
|
130
|
|
|
->willReturn('someTwineId'); |
|
131
|
|
|
|
|
132
|
|
|
$expectedTextnodeMapping = [ |
|
133
|
|
|
'someTwineId' => $textnodeMock, |
|
134
|
|
|
]; |
|
135
|
|
|
|
|
136
|
|
|
$parserContext = new ParserContext(); |
|
137
|
|
|
self::assertNull($parserContext->getCurrentTextnode()); |
|
138
|
|
|
$parserContext->setCurrentTextnode($textnodeMock); |
|
139
|
|
|
self::assertSame($textnodeMock, $parserContext->getCurrentTextnode()); |
|
140
|
|
|
self::assertEquals($expectedTextnodeMapping, $parserContext->getTextnodeMapping()); |
|
141
|
|
|
$parserContext->clearTextnodeMapping(); |
|
142
|
|
|
self::assertEquals([], $parserContext->getTextnodeMapping()); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* @return void |
|
147
|
|
|
*/ |
|
148
|
|
|
public function testIsTwineText(): void |
|
149
|
|
|
{ |
|
150
|
|
|
$parserContext = new ParserContext(); |
|
151
|
|
|
self::assertFalse($parserContext->isTwineText()); |
|
152
|
|
|
$parserContext->setTwineText(true); |
|
153
|
|
|
self::assertTrue($parserContext->isTwineText()); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* @return void |
|
158
|
|
|
*/ |
|
159
|
|
|
public function testGetTwineStartnodeId(): void |
|
160
|
|
|
{ |
|
161
|
|
|
$parserContext = new ParserContext(); |
|
162
|
|
|
self::assertNull($parserContext->getTwineStartnodeId()); |
|
163
|
|
|
$parserContext->setTwineStartnodeId(13); |
|
164
|
|
|
self::assertEquals(13, $parserContext->getTwineStartnodeId()); |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* @return void |
|
169
|
|
|
*/ |
|
170
|
|
|
public function testIsAccessSet(): void |
|
171
|
|
|
{ |
|
172
|
|
|
$parserContext = new ParserContext(); |
|
173
|
|
|
self::assertFalse($parserContext->isAccessSet()); |
|
174
|
|
|
$parserContext->setAccessSet(true); |
|
175
|
|
|
self::assertTrue($parserContext->isAccessSet()); |
|
176
|
|
|
} |
|
177
|
|
|
} |
|
178
|
|
|
|