FOSSology  4.4.0
Open Source License Compliance by Open Source Software
PagedResultTest.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 
12 {
13 
18  protected function renderContentText($text)
19  {
20  return $text;
21  }
22 }
23 
24 class PagedResultTest extends \PHPUnit\Framework\TestCase
25 {
26 
27  const START_OFFSET = 12;
28  const META_TEXT = "<meta>";
29  const CONTENT_TEXT = "<content>";
30 
32  private $pagedResult;
33 
34  protected function setUp() : void
35  {
36  $this->pagedResult = new TestPagedResult(self::START_OFFSET);
37  }
38 
39  public function testGetStartOffset()
40  {
41  assertThat($this->pagedResult->getStartOffset(), is(self::START_OFFSET));
42  }
43 
44  public function testIsEmpty()
45  {
46  $this->assertTrue($this->pagedResult->isEmpty());
47 
48  $this->pagedResult->appendMetaText(self::META_TEXT);
49 
50  $this->assertTrue($this->pagedResult->isEmpty());
51 
52  $this->pagedResult->appendContentText(self::CONTENT_TEXT);
53 
54  $this->assertFalse($this->pagedResult->isEmpty());
55  }
56 
57  public function testAppendMetaText()
58  {
59  $this->pagedResult->appendMetaText(self::META_TEXT);
60 
61  assertThat($this->pagedResult->getCurrentOffset(), is(self::START_OFFSET));
62  assertThat($this->pagedResult->getText(), is(self::META_TEXT));
63  }
64 
65  public function testAppendContentText()
66  {
67  $this->pagedResult->appendContentText(self::CONTENT_TEXT);
68 
69  assertThat($this->pagedResult->getCurrentOffset(), is(self::START_OFFSET + strlen(self::CONTENT_TEXT)));
70  assertThat($this->pagedResult->getText(), is(self::CONTENT_TEXT));
71  }
72 
73  public function testAppendContentAndMetaText()
74  {
75  $this->pagedResult->appendContentText(self::CONTENT_TEXT);
76  $this->pagedResult->appendMetaText(self::META_TEXT);
77 
78  assertThat($this->pagedResult->getCurrentOffset(), is(self::START_OFFSET + strlen(self::CONTENT_TEXT)));
79  assertThat($this->pagedResult->getText(), is(self::CONTENT_TEXT . self::META_TEXT));
80  }
81 
82  public function testAppendMetaAndContentText()
83  {
84  $this->pagedResult->appendMetaText(self::META_TEXT);
85  $this->pagedResult->appendContentText(self::CONTENT_TEXT);
86 
87  assertThat($this->pagedResult->getCurrentOffset(), is(self::START_OFFSET + strlen(self::CONTENT_TEXT)));
88  assertThat($this->pagedResult->getText(), is(self::META_TEXT . self::CONTENT_TEXT));
89  }
90 }