FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
PagedResultTest.php
1 <?php
2 /*
3 Copyright (C) 2014, Siemens AG
4 Author: Andreas Würl
5 
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 version 2 as published by the Free Software Foundation.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19 
20 namespace Fossology\Lib\View;
21 
23 {
24 
29  protected function renderContentText($text)
30  {
31  return $text;
32  }
33 }
34 
35 class PagedResultTest extends \PHPUnit\Framework\TestCase
36 {
37 
38  const START_OFFSET = 12;
39  const META_TEXT = "<meta>";
40  const CONTENT_TEXT = "<content>";
41 
43  private $pagedResult;
44 
45  protected function setUp()
46  {
47  $this->pagedResult = new TestPagedResult(self::START_OFFSET);
48  }
49 
50  public function testGetStartOffset()
51  {
52  assertThat($this->pagedResult->getStartOffset(), is(self::START_OFFSET));
53  }
54 
55  public function testIsEmpty()
56  {
57  $this->assertTrue($this->pagedResult->isEmpty());
58 
59  $this->pagedResult->appendMetaText(self::META_TEXT);
60 
61  $this->assertTrue($this->pagedResult->isEmpty());
62 
63  $this->pagedResult->appendContentText(self::CONTENT_TEXT);
64 
65  $this->assertFalse($this->pagedResult->isEmpty());
66  }
67 
68  public function testAppendMetaText()
69  {
70  $this->pagedResult->appendMetaText(self::META_TEXT);
71 
72  assertThat($this->pagedResult->getCurrentOffset(), is(self::START_OFFSET));
73  assertThat($this->pagedResult->getText(), is(self::META_TEXT));
74  }
75 
76  public function testAppendContentText()
77  {
78  $this->pagedResult->appendContentText(self::CONTENT_TEXT);
79 
80  assertThat($this->pagedResult->getCurrentOffset(), is(self::START_OFFSET + strlen(self::CONTENT_TEXT)));
81  assertThat($this->pagedResult->getText(), is(self::CONTENT_TEXT));
82  }
83 
84  public function testAppendContentAndMetaText()
85  {
86  $this->pagedResult->appendContentText(self::CONTENT_TEXT);
87  $this->pagedResult->appendMetaText(self::META_TEXT);
88 
89  assertThat($this->pagedResult->getCurrentOffset(), is(self::START_OFFSET + strlen(self::CONTENT_TEXT)));
90  assertThat($this->pagedResult->getText(), is(self::CONTENT_TEXT . self::META_TEXT));
91  }
92 
93  public function testAppendMetaAndContentText()
94  {
95  $this->pagedResult->appendMetaText(self::META_TEXT);
96  $this->pagedResult->appendContentText(self::CONTENT_TEXT);
97 
98  assertThat($this->pagedResult->getCurrentOffset(), is(self::START_OFFSET + strlen(self::CONTENT_TEXT)));
99  assertThat($this->pagedResult->getText(), is(self::META_TEXT . self::CONTENT_TEXT));
100  }
101 }