9 namespace Fossology\Lib\View;
15 use Mockery\MockInterface;
25 private $splitPosition;
29 private $highlightRenderer;
33 function setUp() :
void
36 $this->colorMap = array(
'type1' =>
'red',
'type2' =>
'yellow',
'any' =>
'gray');
38 $this->prepareMocks();
41 function tearDown() :
void
46 public function prepareMocks()
48 $this->htmlElement = M::mock(SimpleHtmlElement::class);
49 $this->htmlElement->shouldReceive(
'getOpeningText')->andReturn(
'<element>');
50 $this->htmlElement->shouldReceive(
'getClosingText')->andReturn(
'</element>');
52 $this->highlight = M::mock(Highlight::class);
53 $this->highlight->shouldReceive(
'getType')->andReturn(Highlight::MATCH)->byDefault();
54 $this->highlight->shouldReceive(
'getInfoText')->andReturn(
"<infoText>")->byDefault();
55 $this->highlight->shouldReceive(
'getHtmlElement')->andReturn(
null)->byDefault();
57 $this->splitPosition = M::mock(SplitPosition::class);
58 $this->splitPosition->shouldReceive(
'getLevel')->andReturn($this->level)->byDefault();
59 $this->splitPosition->shouldReceive(
'getHighlight')->andReturn($this->highlight)->byDefault();
62 public function testCreateSpanStart()
64 $result = $this->highlightRenderer->createSpanStart($this->splitPosition);
66 assertThat($result, is(
"<span class=\"hi-match\" title=\"<infoText>\">"));
69 public function testCreateSpanStartWrappingHtmlElement()
71 $this->highlight->shouldReceive(
'getHtmlElement')->andReturn($this->htmlElement);
73 $result = $this->highlightRenderer->createSpanStart($this->splitPosition);
75 assertThat($result, is(
"<span class=\"hi-match\" title=\"<infoText>\"><element>"));
78 public function testCreateSpanStartWithUndefinedType()
80 $this->highlight->shouldReceive(
'getType')->andReturn(
"<anything>");
81 $this->highlight->shouldReceive(
'getInfoText')->andReturn(
null);
83 $result = $this->highlightRenderer->createSpanStart($this->splitPosition);
85 assertThat($result, is(
"<span class=\"hi-undefined\" title=\"\">"));
88 public function testCreateSpanStartWithPadding()
90 $this->splitPosition->shouldReceive(
'getLevel')->andReturn(-1);
92 $result = $this->highlightRenderer->createSpanStart($this->splitPosition);
94 assertThat($result, is(
"<span class=\"hi-match\" title=\"<infoText>\">"));
97 public function testCreateSpanEnd()
99 $result = $this->highlightRenderer->createSpanEnd($this->splitPosition);
101 assertThat($result, is(
"</span>"));
104 public function testCreateSpanEndWithWrappeingHtmlElement()
106 $this->highlight->shouldReceive(
'getHtmlElement')->andReturn($this->htmlElement);
108 $result = $this->highlightRenderer->createSpanEnd($this->splitPosition);
110 assertThat($result, is(
"</element></span>"));