8 namespace Fossology\Lib\Proxy;
15 private $dbManagerMock;
17 protected function setUp() :
void
20 $container = M::mock(
'ContainerBuilder');
21 $this->dbManagerMock = M::mock(DbManager::class);
22 $container->shouldReceive(
'get')->withArgs(array(
'db.manager'))->andReturn($this->dbManagerMock);
23 $this->almostAllColumns =
'rf_pk,rf_spdx_id,rf_shortname,rf_text,rf_url,rf_add_date,rf_copyleft,rf_fullname,rf_notes,marydone,rf_active,rf_text_updatable,rf_md5,rf_detector_type,rf_source';
26 protected function tearDown() :
void
31 public function testQueryOnlyLicenseRef()
35 $reflection = new \ReflectionClass(get_class($licenseViewProxy));
36 $method = $reflection->getMethod(
'queryOnlyLicenseRef');
37 $method->setAccessible(
true);
39 $options1 = array(
'columns'=>array(
'rf_pk',
'rf_shortname'));
40 $query1 = $method->invoke($licenseViewProxy,$options1);
41 assertThat($query1, is(
"SELECT rf_pk,rf_shortname FROM ONLY license_ref"));
43 $options2 = array(
'extraCondition'=>
'rf_pk<100');
44 $query2 = $method->invoke($licenseViewProxy,$options2);
45 assertThat($query2, is(
"SELECT $this->almostAllColumns,0 AS group_fk FROM ONLY license_ref WHERE rf_pk<100"));
48 public function testQueryLicenseCandidate()
53 $reflection = new \ReflectionClass(get_class($licenseViewProxy));
54 $method = $reflection->getMethod(
'queryLicenseCandidate');
55 $method->setAccessible(
true);
57 $options1 = array(
'columns'=>array(
'rf_pk',
'rf_shortname'));
58 $query1 = $method->invoke($licenseViewProxy,$options1);
59 assertThat($query1, is(
"SELECT rf_pk,rf_shortname FROM license_candidate WHERE group_fk=$groupId"));
61 $options2 = array(
'extraCondition'=>
'rf_pk<100');
62 $query2 = $method->invoke($licenseViewProxy,$options2);
63 assertThat($query2, is(
"SELECT $this->almostAllColumns,group_fk FROM license_candidate WHERE group_fk=$groupId AND rf_pk<100"));
66 $options3 = array(LicenseViewProxy::CANDIDATE_PREFIX=>$prefix,
'columns'=>array(
'rf_shortname'));
67 $query3 = $method->invoke($licenseViewProxy,$options3);
68 assertThat($query3, is(
"SELECT '". pg_escape_string($prefix).
"'||rf_shortname AS rf_shortname FROM license_candidate WHERE group_fk=$groupId"));
71 public function testConstruct()
74 $query0 = $licenseViewProxy0->getDbViewQuery();
75 $expected0 =
"SELECT $this->almostAllColumns,0 AS group_fk FROM ONLY license_ref";
76 assertThat($query0,is($expected0));
79 $query123 = $licenseViewProxy123->getDbViewQuery();
80 $expected123 =
"SELECT $this->almostAllColumns,group_fk FROM license_candidate WHERE group_fk=123";
81 assertThat($query123,is($expected123));
84 $query0123 = $licenseViewProxy0123->getDbViewQuery();
85 $expected0123 =
"$expected123 UNION $expected0";
86 assertThat($query0123,is($expected0123));