FOSSology  4.4.0
Open Source License Compliance by Open Source Software
PagedHexResultTest.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2014 Siemens AG
4  Author: Andreas Würl
5 
6  SPDX-License-Identifier: GPL-2.0-only
7 */
8 
9 namespace Fossology\Lib\View;
10 
11 use Mockery as M;
12 
13 class PagedHexResultTest extends \PHPUnit\Framework\TestCase
14 {
15 
16  const START_OFFSET = 5;
17 
21  private $result;
22 
23  protected function setUp() : void
24  {
25  $highlightState = M::mock(HighlightState::class);
26  $highlightState->shouldReceive("openExistingElements")->withAnyArgs()->andReturn("");
27  $highlightState->shouldReceive("closeOpenElements")->withAnyArgs()->andReturn("");
28  $this->result = new PagedHexResult(self::START_OFFSET, $highlightState);
29  }
30 
31  protected function tearDown() : void
32  {
33  M::close();
34  }
35 
36  public function testAddSmallAmountOfText()
37  {
38  $this->result->appendContentText("foo bar");
39 
40  assertThat(
41  $this->result->getText(),
42  is("0x00000005 |66 6f 6f 20 62 61 72 __ __ __ __ __ __ __ __ __| |foo&nbsp;bar&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|"));
43  }
44 
45  public function testAddOneHexLineOfText()
46  {
47  $this->result->appendContentText("foo bar baz done");
48 
49  assertThat(
50  $this->result->getText(),
51  is("0x00000005 |66 6f 6f 20 62 61 72 20 62 61 7a 20 64 6f 6e 65| |foo&nbsp;bar&nbsp;baz&nbsp;done|<br/>\n"));
52  }
53 
54  public function testAddMoreThanOneHexLineOfText()
55  {
56  $this->result->appendContentText("foo bar baz donefoo bar");
57 
58  assertThat(
59  $this->result->getText(),
60  is("0x00000005 |66 6f 6f 20 62 61 72 20 62 61 7a 20 64 6f 6e 65| |foo&nbsp;bar&nbsp;baz&nbsp;done|<br/>\n" .
61  "0x00000015 |66 6f 6f 20 62 61 72 __ __ __ __ __ __ __ __ __| |foo&nbsp;bar&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|"));
62  }
63 
64  public function testAddMetaText()
65  {
66  $this->result->appendContentText("foo ");
67  $this->result->appendMetaText("<b>");
68  $this->result->appendContentText("bar");
69  $this->result->appendMetaText("</b>");
70  $this->result->appendContentText("baz done");
71 
72  assertThat(
73  $this->result->getText(),
74  is("0x00000005 |66 6f 6f 20 <b>62 61 72 </b>62 61 7a 20 64 6f 6e 65 __| |foo&nbsp;<b>bar</b>baz&nbsp;done&nbsp;|"));
75  }
76 }