39 $this->license1 =
new License(10,
"shortName",
"fullName",
"licenseFullText", 4,
"URL", 2);
41 $this->licenseDao = M::mock(LicenseDao::class)
42 ->shouldReceive(
'getLicenseById')->with($this->license1->getId())
43 ->andReturn($this->license1)->getMock();
53 function testAddReferenceTexts()
55 $highlight1 =
new Highlight(5, 8,
'type1', 2, 6, $this->license1->getId());
56 $highlights = array($highlight1);
58 $this->highlight->addReferenceTexts($highlights);
60 assertThat($highlight1->getInfoText(), is(
"10"));
63 function testSplitOverlappingHighlightEntriesReordersByStart()
65 $highlight1 =
new Highlight(5, 8,
'type1',
'ref1', 0, 0);
66 $highlight2 =
new Highlight(4, 8,
'text2',
'ref2', 0, 0);
67 $highlightInfos = array($highlight1, $highlight2);
69 $splitOverlap = $this->highlight->calculateSplitPositions($highlightInfos);
71 assertThat($splitOverlap, anArray(
73 4 => array(
new SplitPosition(0, SplitPosition::START, $highlight2)),
74 5 => array(
new SplitPosition(1, SplitPosition::START, $highlight1)),
82 function testSplitHighlightEntriesContainingAnAtomAtStart()
84 $highlight1 =
new Highlight(5, 8,
'type1',
'ref1', 0, 0);
85 $highlight2 =
new Highlight(5, 5,
'type1',
'ref2', 0, 0);
86 $highlightInfos = array($highlight1, $highlight2);
88 $splitOverlap = $this->highlight->calculateSplitPositions($highlightInfos);
90 assertThat($splitOverlap, anArray(
95 8 => array(
new SplitPosition(0, SplitPosition::END, $highlight1))
99 function testSplitHighlightEntriesContainingAnAtomInTheMiddle()
101 $highlight1 =
new Highlight(5, 8,
'type1',
'ref1', 0, 0);
102 $highlight2 =
new Highlight(7, 7,
'type2',
'ref2', 0, 0);
103 $highlightInfos = array($highlight1, $highlight2);
105 $splitOverlap = $this->highlight->calculateSplitPositions($highlightInfos);
107 assertThat($splitOverlap, anArray(
109 5 => array(
new SplitPosition(0, SplitPosition::START, $highlight1)),
110 7 => array(
new SplitPosition(1, SplitPosition::ATOM, $highlight2)),
111 8 => array(
new SplitPosition(0, SplitPosition::END, $highlight1))
115 function testSplitOverlappingHightlightEntriesReordersByLengthIfStartIsIdentical()
117 $highlight1 =
new Highlight(5, 8,
'type1',
'ref1', 0, 0);
118 $highlight2 =
new Highlight(5, 9,
'type2',
'ref2', 0, 0);
119 $highlightInfos = array($highlight1, $highlight2);
121 $splitOverlap = $this->highlight->calculateSplitPositions($highlightInfos);
123 assertThat($splitOverlap, anArray(
125 5 => array(
new SplitPosition(0, SplitPosition::START, $highlight2),
127 8 => array(
new SplitPosition(1, SplitPosition::END, $highlight1)),
128 9 => array(
new SplitPosition(0, SplitPosition::END, $highlight2))
132 function testSplitOverlappingHightlightEntriesSplitsOverlappingEntries()
134 $highlight1 =
new Highlight(5, 8,
'type1',
'ref1', 0, 0);
135 $highlight2 =
new Highlight(7, 11,
'type2',
'ref2', 0, 0);
136 $highlightInfos = array($highlight1, $highlight2);
138 $splitOverlap = $this->highlight->calculateSplitPositions($highlightInfos);
140 assertThat($splitOverlap, anArray(
142 5 => array(
new SplitPosition(0, SplitPosition::START, $highlight1)),
143 7 => array(
new SplitPosition(1, SplitPosition::START, $highlight2)),
148 11 => array(
new SplitPosition(1, SplitPosition::END, $highlight2))
152 function testSplitOverlappingHightlightEntriesKeepsNonOverlappingEntriesInDepth()
154 $highlight1 =
new Highlight(5, 15,
'type1',
'ref1', 0, 0);
155 $highlight2 =
new Highlight(7, 13,
'type2',
'ref2', 0, 0);
156 $highlight3 =
new Highlight(9, 11,
'type3',
'ref3', 0, 0);
157 $highlightInfos = array($highlight1, $highlight2, $highlight3);
159 $splitOverlap = $this->highlight->calculateSplitPositions($highlightInfos);
161 assertThat($splitOverlap, anArray(
163 5 => array(
new SplitPosition(0, SplitPosition::START, $highlight1)),
164 7 => array(
new SplitPosition(1, SplitPosition::START, $highlight2)),
165 9 => array(
new SplitPosition(2, SplitPosition::START, $highlight3)),
166 11 => array(
new SplitPosition(2, SplitPosition::END, $highlight3)),
167 13 => array(
new SplitPosition(1, SplitPosition::END, $highlight2)),
168 15 => array(
new SplitPosition(0, SplitPosition::END, $highlight1))
172 function testSplitOverlappingHightlightEntriesSplitsOverlappingEntriesInDepth()
174 $highlight1 =
new Highlight(5, 11,
'type1',
'ref1', 0, 0);
175 $highlight2 =
new Highlight(7, 13,
'type2',
'ref2', 0, 0);
176 $highlight3 =
new Highlight(9, 15,
'type3',
'ref3', 0, 0);
177 $highlightInfos = array($highlight1, $highlight2, $highlight3);
179 $splitOverlap = $this->highlight->calculateSplitPositions($highlightInfos);
181 assertThat($splitOverlap, anArray(
183 5 => array(
new SplitPosition(0, SplitPosition::START, $highlight1)),
184 7 => array(
new SplitPosition(1, SplitPosition::START, $highlight2)),
185 9 => array(
new SplitPosition(2, SplitPosition::START, $highlight3)),
196 15 => array(
new SplitPosition(2, SplitPosition::END, $highlight3))
201 function testSplitOverlappingHightlightEntriesSplitsPartialOverlappingEntries()
203 $highlight1 =
new Highlight(5, 8,
'type1',
'ref1', 0, 0);
204 $highlight2 =
new Highlight(10, 13,
'type2',
'ref2', 0, 0);
205 $highlight3 =
new Highlight(7, 11,
'type3',
'ref3', 0, 0);
206 $highlightInfos = array($highlight1, $highlight2, $highlight3);
208 $splitOverlap = $this->highlight->calculateSplitPositions($highlightInfos);
210 assertThat($splitOverlap, anArray(
212 5 => array(
new SplitPosition(0, SplitPosition::START, $highlight1)),
213 7 => array(
new SplitPosition(1, SplitPosition::START, $highlight3)),
222 11 => array(
new SplitPosition(1, SplitPosition::END, $highlight3),),
223 13 => array(
new SplitPosition(0, SplitPosition::END, $highlight2))
227 function testFlattenHighlightWithSeparatedEntries()
229 $highlight1 =
new Highlight(5, 8,
'type1',
'ref1', 0, 0);
230 $highlight2 =
new Highlight(10, 13,
'type2',
'ref2', 0, 0);
231 $highlights = array($highlight1, $highlight2);
233 $this->highlight->flattenHighlights($highlights);
235 assertThat($highlights, anArray(
237 new Highlight(5, 8, Highlight::UNDEFINED,
'ref1', 0, 0),
238 new Highlight(10, 13, Highlight::UNDEFINED,
'ref2', 0, 0)
242 function testFlattenHighlightWithOverlappingEntries()
244 $highlight1 =
new Highlight(5, 10, Highlight::MATCH,
'ref1', 0, 0);
245 $highlight2 =
new Highlight(8, 13, Highlight::ADDED,
'ref2', 0, 0);
246 $highlights = array($highlight1, $highlight2);
248 $this->highlight->flattenHighlights($highlights);
250 assertThat($highlights, anArray(
252 new Highlight(5, 10, Highlight::UNDEFINED,
'ref1', 0, 0),
253 new Highlight(10, 13, Highlight::UNDEFINED,
'ref2', 0, 0)
257 function testFlattenHighlightWithFullyOverlappingEntries()
259 $highlight1 =
new Highlight(5, 10, Highlight::MATCH,
'ref1', 0, 0);
260 $highlight2 =
new Highlight(7, 9, Highlight::ADDED,
'ref2', 0, 0);
261 $highlights = array($highlight1, $highlight2);
263 $this->highlight->flattenHighlights($highlights);
265 assertThat($highlights, anArray(
267 new Highlight(5, 10, Highlight::UNDEFINED,
'ref1', 0, 0),
271 function testFlattenHighlightWithIgnoredEntries()
273 $highlight1 =
new Highlight(5, 10, Highlight::MATCH,
'ref1', 0, 0);
274 $highlight2 =
new Highlight(7, 9, Highlight::KEYWORD,
'ref2', 0, 0);
275 $highlights = array($highlight1, $highlight2);
277 $this->highlight->flattenHighlights($highlights, array(Highlight::KEYWORD));
279 assertThat($highlights, anArray(
281 new Highlight(5, 10, Highlight::UNDEFINED,
'ref1', 0, 0),
282 new Highlight(7, 9, Highlight::KEYWORD,
'ref2', 0, 0)
286 function testFlattenHighlightWithOverlappingEntriesThatHaveEqualEnd()
288 $highlight1 =
new Highlight(5, 10, Highlight::MATCH,
'ref1', 0, 0);
289 $highlight2 =
new Highlight(7, 10, Highlight::ADDED,
'ref2', 0, 0);
290 $highlights = array($highlight1, $highlight2);
292 $this->highlight->flattenHighlights($highlights);
294 assertThat($highlights, anArray(
296 new Highlight(5, 10, Highlight::UNDEFINED,
'ref1', 0, 0),