FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
ItemTest.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\Data\Tree;
21 
22 use Mockery as M;
23 
24 require_once(__DIR__ . '/../../../common-dir.php');
25 
26 class ItemTest extends \PHPUnit\Framework\TestCase
27 {
28  private $id = 234;
29  private $parentId = 432;
30  private $fileId = 123;
31  private $fileMode = 21;
32  private $fileName = "<fileName>";
34  private $itemTreeBounds;
36  private $item;
37 
38  protected function setUp()
39  {
40  $this->itemTreeBounds = M::mock(ItemTreeBounds::class);
41 
42  $this->item = new Item($this->itemTreeBounds, $this->parentId, $this->fileId, $this->fileMode, $this->fileName);
43  }
44 
45  protected function tearDown()
46  {
47  M::close();
48  }
49 
50  public function testGetId()
51  {
52  $this->itemTreeBounds->shouldReceive("getItemId")->once()->withNoArgs()->andReturn($this->id);
53 
54  assertThat($this->item->getId(), is($this->id));
55  }
56 
57  public function testGetParentId()
58  {
59  assertThat($this->item->getParentId(), is($this->parentId));
60  }
61 
62  public function testGetFileMode()
63  {
64  assertThat($this->item->getFileMode(), is($this->fileMode));
65  }
66 
67  public function testGetFileName()
68  {
69  assertThat($this->item->getFileName(), is($this->fileName));
70  }
71 
72  public function testGetFileId()
73  {
74  assertThat($this->item->getFileId(), is($this->fileId));
75  }
76 
77  public function testGetItemTreeBounds()
78  {
79  assertThat($this->item->getItemTreeBounds(), is($this->itemTreeBounds));
80  }
81 
82  public function testContainsFileTreeItems()
83  {
84  $this->itemTreeBounds->shouldReceive("containsFiles")->withNoArgs()->andReturn(true);
85 
86  $this->assertTrue($this->item->containsFileTreeItems());
87  }
88 
89  public function testDoesNotContainFileTreeItems()
90  {
91  $this->itemTreeBounds->shouldReceive("containsFiles")->withNoArgs()->andReturn(false);
92 
93  $this->assertFalse($this->item->containsFileTreeItems());
94  }
95 
96  public function testHasParent()
97  {
98  $this->assertTrue($this->item->hasParent());
99  }
100 
101  public function testHasNoParent()
102  {
103  $this->item = new Item($this->itemTreeBounds, null, $this->fileId,
104  $this->fileMode, $this->fileName);
105  $this->assertFalse($this->item->hasParent());
106  }
107 
108  public function testIsContainer()
109  {
110  $this->assertFalse($this->item->isContainer());
111  }
112 
113  public function testIsFile()
114  {
115  $this->assertTrue($this->item->isFile());
116  }
117 }