FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
PagedHexResultTest.php
1 <?php
2 
3 /*
4 Copyright (C) 2014, Siemens AG
5 Author: Andreas Würl
6 
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 version 2 as published by the Free Software Foundation.
10 
11 This program 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 General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20 
21 namespace Fossology\Lib\View;
22 
23 use Mockery as M;
24 
25 class PagedHexResultTest extends \PHPUnit\Framework\TestCase
26 {
27 
28  const START_OFFSET = 5;
29 
33  private $result;
34 
35  protected function setUp()
36  {
37  $highlightState = M::mock(HighlightState::class);
38  $highlightState->shouldReceive("openExistingElements")->withAnyArgs()->andReturn("");
39  $highlightState->shouldReceive("closeOpenElements")->withAnyArgs()->andReturn("");
40  $this->result = new PagedHexResult(self::START_OFFSET, $highlightState);
41  }
42 
43  protected function tearDown()
44  {
45  M::close();
46  }
47 
48  public function testAddSmallAmountOfText()
49  {
50  $this->result->appendContentText("foo bar");
51 
52  assertThat(
53  $this->result->getText(),
54  is("0x00000005 |66 6f 6f 20 62 61 72 __ __ __ __ __ __ __ __ __| |foo&nbsp;bar&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|"));
55  }
56 
57  public function testAddOneHexLineOfText()
58  {
59  $this->result->appendContentText("foo bar baz done");
60 
61  assertThat(
62  $this->result->getText(),
63  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"));
64  }
65 
66  public function testAddMoreThanOneHexLineOfText()
67  {
68  $this->result->appendContentText("foo bar baz donefoo bar");
69 
70  assertThat(
71  $this->result->getText(),
72  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" .
73  "0x00000015 |66 6f 6f 20 62 61 72 __ __ __ __ __ __ __ __ __| |foo&nbsp;bar&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|"));
74  }
75 
76  public function testAddMetaText()
77  {
78  $this->result->appendContentText("foo ");
79  $this->result->appendMetaText("<b>");
80  $this->result->appendContentText("bar");
81  $this->result->appendMetaText("</b>");
82  $this->result->appendContentText("baz done");
83 
84  assertThat(
85  $this->result->getText(),
86  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;|"));
87  }
88 }