8 namespace Fossology\Lib\Proxy;
15 private $viewSuffix =
"<suffix>";
18 private $itemTreeBounds;
20 protected function setUp() :
void
22 $this->itemTreeBounds = M::mock(ItemTreeBounds::class);
25 public function testDefaultViewName()
27 $this->itemTreeBounds->shouldReceive(
"getUploadTreeTableName")->once()->withNoArgs()->andReturn(
"foo");
31 assertThat($uploadTreeView->getDbViewName(), is(
"UploadTreeView"));
34 public function testViewName()
36 $this->itemTreeBounds->shouldReceive(
"getUploadTreeTableName")->once()->withNoArgs()->andReturn(
"foo");
38 $uploadTreeView =
new UploadTreeViewProxy($this->itemTreeBounds, array(), $this->viewSuffix);
40 assertThat($uploadTreeView->getDbViewName(), is(
"UploadTreeView.<suffix>"));
43 public function testWithoutCondition()
45 $this->itemTreeBounds->shouldReceive(
"getUploadTreeTableName")->once()->withNoArgs()->andReturn(
"foo");
49 assertThat($uploadTreeView->getDbViewQuery(), is(
"SELECT * FROM foo"));
52 public function testWithoutConditionAndDefaultTable()
54 $this->itemTreeBounds->shouldReceive(
"getUploadTreeTableName")->once()->withNoArgs()->andReturn(
"uploadtree_a");
55 $this->itemTreeBounds->shouldReceive(
"getUploadId")->once()->withNoArgs()->andReturn(23);
59 assertThat($uploadTreeView->getDbViewQuery(), is(
"SELECT * FROM uploadtree_a WHERE upload_fk = 23"));
62 public function testWithoutConditionAndMasterTable()
64 $this->itemTreeBounds->shouldReceive(
"getUploadTreeTableName")->once()->withNoArgs()->andReturn(
"uploadtree");
65 $this->itemTreeBounds->shouldReceive(
"getUploadId")->once()->withNoArgs()->andReturn(23);
69 assertThat($uploadTreeView->getDbViewQuery(), is(
"SELECT * FROM uploadtree WHERE upload_fk = 23"));
72 public function testWithUploadCondition()
74 $this->itemTreeBounds->shouldReceive(
"getUploadTreeTableName")->once()->withNoArgs()->andReturn(
"foo");
75 $this->itemTreeBounds->shouldReceive(
"getUploadId")->once()->withNoArgs()->andReturn(76);
77 $uploadTreeView =
new UploadTreeViewProxy($this->itemTreeBounds, array(UploadTreeViewProxy::CONDITION_UPLOAD));
79 assertThat($uploadTreeView->getDbViewQuery(), is(
"SELECT * FROM foo WHERE upload_fk = 76"));
82 public function testWithDoubleUploadCondition()
84 $this->itemTreeBounds->shouldReceive(
"getUploadTreeTableName")->once()->withNoArgs()->andReturn(
"foo");
85 $this->itemTreeBounds->shouldReceive(
"getUploadId")->once()->withNoArgs()->andReturn(76);
87 $uploadTreeView =
new UploadTreeViewProxy($this->itemTreeBounds, array(UploadTreeViewProxy::CONDITION_UPLOAD, UploadTreeViewProxy::CONDITION_UPLOAD));
89 assertThat($uploadTreeView->getDbViewQuery(), is(
"SELECT * FROM foo WHERE upload_fk = 76"));
92 public function testWithRangeCondition()
94 $this->itemTreeBounds->shouldReceive(
"getUploadTreeTableName")->once()->withNoArgs()->andReturn(
"foo");
95 $this->itemTreeBounds->shouldReceive(
"getLeft")->once()->withNoArgs()->andReturn(25);
96 $this->itemTreeBounds->shouldReceive(
"getRight")->once()->withNoArgs()->andReturn(50);
98 $uploadTreeView =
new UploadTreeViewProxy($this->itemTreeBounds, array(UploadTreeViewProxy::CONDITION_RANGE));
100 assertThat($uploadTreeView->getDbViewQuery(), is(
"SELECT * FROM foo WHERE lft BETWEEN 25 AND 50"));
103 public function testWithPlainFilesCondition()
105 $this->itemTreeBounds->shouldReceive(
"getUploadTreeTableName")->once()->withNoArgs()->andReturn(
"foo");
107 $uploadTreeView =
new UploadTreeViewProxy($this->itemTreeBounds, array(UploadTreeViewProxy::CONDITION_PLAIN_FILES));
109 assertThat($uploadTreeView->getDbViewQuery(), is(
"SELECT * FROM foo WHERE ((ufile_mode & (3<<28))=0) AND pfile_fk != 0"));
112 public function testWithMultipleConditions()
114 $this->itemTreeBounds->shouldReceive(
"getUploadTreeTableName")->once()->withNoArgs()->andReturn(
"foo");
115 $this->itemTreeBounds->shouldReceive(
"getUploadId")->once()->withNoArgs()->andReturn(5);
116 $this->itemTreeBounds->shouldReceive(
"getLeft")->once()->withNoArgs()->andReturn(22);
117 $this->itemTreeBounds->shouldReceive(
"getRight")->once()->withNoArgs()->andReturn(43);
119 $uploadTreeView =
new UploadTreeViewProxy($this->itemTreeBounds, array(UploadTreeViewProxy::CONDITION_UPLOAD, UploadTreeViewProxy::CONDITION_PLAIN_FILES, UploadTreeViewProxy::CONDITION_RANGE));
121 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"));
124 public function testExcpetionWithUnknownConstraint()
126 $this->expectException(\InvalidArgumentException::class);
127 $this->expectExceptionMessage(
"constraint bar is not defined");
128 $this->itemTreeBounds->shouldReceive(
"getUploadTreeTableName")->once()->withNoArgs()->andReturn(
"foo");