FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
UploadTreeViewProxyTest.php
1 <?php
2 /*
3 Copyright (C) 2014, Siemens AG
4 
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 version 2 as published by the Free Software Foundation.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18 
19 namespace Fossology\Lib\Proxy;
20 
22 use Mockery as M;
23 
24 class UploadTreeViewProxyTest extends \PHPUnit\Framework\TestCase
25 {
26  private $viewSuffix = "<suffix>";
27 
29  private $itemTreeBounds;
30 
31  protected function setUp()
32  {
33  $this->itemTreeBounds = M::mock(ItemTreeBounds::class);
34  }
35 
36  public function testDefaultViewName()
37  {
38  $this->itemTreeBounds->shouldReceive("getUploadTreeTableName")->once()->withNoArgs()->andReturn("foo");
39 
40  $uploadTreeView = new UploadTreeViewProxy($this->itemTreeBounds);
41 
42  assertThat($uploadTreeView->getDbViewName(), is("UploadTreeView"));
43  }
44 
45  public function testViewName()
46  {
47  $this->itemTreeBounds->shouldReceive("getUploadTreeTableName")->once()->withNoArgs()->andReturn("foo");
48 
49  $uploadTreeView = new UploadTreeViewProxy($this->itemTreeBounds, array(), $this->viewSuffix);
50 
51  assertThat($uploadTreeView->getDbViewName(), is("UploadTreeView.<suffix>"));
52  }
53 
54  public function testWithoutCondition()
55  {
56  $this->itemTreeBounds->shouldReceive("getUploadTreeTableName")->once()->withNoArgs()->andReturn("foo");
57 
58  $uploadTreeView = new UploadTreeViewProxy($this->itemTreeBounds);
59 
60  assertThat($uploadTreeView->getDbViewQuery(), is("SELECT * FROM foo"));
61  }
62 
63  public function testWithoutConditionAndDefaultTable()
64  {
65  $this->itemTreeBounds->shouldReceive("getUploadTreeTableName")->once()->withNoArgs()->andReturn("uploadtree_a");
66  $this->itemTreeBounds->shouldReceive("getUploadId")->once()->withNoArgs()->andReturn(23);
67 
68  $uploadTreeView = new UploadTreeViewProxy($this->itemTreeBounds);
69 
70  assertThat($uploadTreeView->getDbViewQuery(), is("SELECT * FROM uploadtree_a WHERE upload_fk = 23"));
71  }
72 
73  public function testWithoutConditionAndMasterTable()
74  {
75  $this->itemTreeBounds->shouldReceive("getUploadTreeTableName")->once()->withNoArgs()->andReturn("uploadtree");
76  $this->itemTreeBounds->shouldReceive("getUploadId")->once()->withNoArgs()->andReturn(23);
77 
78  $uploadTreeView = new UploadTreeViewProxy($this->itemTreeBounds);
79 
80  assertThat($uploadTreeView->getDbViewQuery(), is("SELECT * FROM uploadtree WHERE upload_fk = 23"));
81  }
82 
83  public function testWithUploadCondition()
84  {
85  $this->itemTreeBounds->shouldReceive("getUploadTreeTableName")->once()->withNoArgs()->andReturn("foo");
86  $this->itemTreeBounds->shouldReceive("getUploadId")->once()->withNoArgs()->andReturn(76);
87 
88  $uploadTreeView = new UploadTreeViewProxy($this->itemTreeBounds, array(UploadTreeViewProxy::CONDITION_UPLOAD));
89 
90  assertThat($uploadTreeView->getDbViewQuery(), is("SELECT * FROM foo WHERE upload_fk = 76"));
91  }
92 
93  public function testWithDoubleUploadCondition()
94  {
95  $this->itemTreeBounds->shouldReceive("getUploadTreeTableName")->once()->withNoArgs()->andReturn("foo");
96  $this->itemTreeBounds->shouldReceive("getUploadId")->once()->withNoArgs()->andReturn(76);
97 
98  $uploadTreeView = new UploadTreeViewProxy($this->itemTreeBounds, array(UploadTreeViewProxy::CONDITION_UPLOAD, UploadTreeViewProxy::CONDITION_UPLOAD));
99 
100  assertThat($uploadTreeView->getDbViewQuery(), is("SELECT * FROM foo WHERE upload_fk = 76"));
101  }
102 
103  public function testWithRangeCondition()
104  {
105  $this->itemTreeBounds->shouldReceive("getUploadTreeTableName")->once()->withNoArgs()->andReturn("foo");
106  $this->itemTreeBounds->shouldReceive("getLeft")->once()->withNoArgs()->andReturn(25);
107  $this->itemTreeBounds->shouldReceive("getRight")->once()->withNoArgs()->andReturn(50);
108 
109  $uploadTreeView = new UploadTreeViewProxy($this->itemTreeBounds, array(UploadTreeViewProxy::CONDITION_RANGE));
110 
111  assertThat($uploadTreeView->getDbViewQuery(), is("SELECT * FROM foo WHERE lft BETWEEN 25 AND 50"));
112  }
113 
114  public function testWithPlainFilesCondition()
115  {
116  $this->itemTreeBounds->shouldReceive("getUploadTreeTableName")->once()->withNoArgs()->andReturn("foo");
117 
118  $uploadTreeView = new UploadTreeViewProxy($this->itemTreeBounds, array(UploadTreeViewProxy::CONDITION_PLAIN_FILES));
119 
120  assertThat($uploadTreeView->getDbViewQuery(), is("SELECT * FROM foo WHERE ((ufile_mode & (3<<28))=0) AND pfile_fk != 0"));
121  }
122 
123  public function testWithMultipleConditions()
124  {
125  $this->itemTreeBounds->shouldReceive("getUploadTreeTableName")->once()->withNoArgs()->andReturn("foo");
126  $this->itemTreeBounds->shouldReceive("getUploadId")->once()->withNoArgs()->andReturn(5);
127  $this->itemTreeBounds->shouldReceive("getLeft")->once()->withNoArgs()->andReturn(22);
128  $this->itemTreeBounds->shouldReceive("getRight")->once()->withNoArgs()->andReturn(43);
129 
130  $uploadTreeView = new UploadTreeViewProxy($this->itemTreeBounds, array(UploadTreeViewProxy::CONDITION_UPLOAD, UploadTreeViewProxy::CONDITION_PLAIN_FILES, UploadTreeViewProxy::CONDITION_RANGE));
131 
132  assertThat($uploadTreeView->getDbViewQuery(), is("SELECT * FROM foo WHERE upload_fk = 5 AND ((ufile_mode & (3<<28))=0) AND pfile_fk != 0 AND lft BETWEEN 22 AND 43"));
133  }
134 
140  {
141  $this->itemTreeBounds->shouldReceive("getUploadTreeTableName")->once()->withNoArgs()->andReturn("foo");
142 
143  new UploadTreeViewProxy($this->itemTreeBounds, array('bar'));
144  }
145 }