26 private $dbManagerMock;
28 protected function setUp()
31 $container = M::mock(
'ContainerBuilder');
32 $this->dbManagerMock = M::mock(DbManager::class);
33 $container->shouldReceive(
'get')->withArgs(array(
'db.manager'))->andReturn($this->dbManagerMock);
34 $this->almostAllColumns =
'rf_pk,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';
37 protected function tearDown()
42 public function testQueryOnlyLicenseRef()
46 $reflection = new \ReflectionClass(get_class($licenseViewProxy));
47 $method = $reflection->getMethod(
'queryOnlyLicenseRef');
48 $method->setAccessible(
true);
50 $options1 = array(
'columns'=>array(
'rf_pk',
'rf_shortname'));
51 $query1 = $method->invoke($licenseViewProxy,$options1);
52 assertThat($query1, is(
"SELECT rf_pk,rf_shortname FROM ONLY license_ref"));
54 $options2 = array(
'extraCondition'=>
'rf_pk<100');
55 $query2 = $method->invoke($licenseViewProxy,$options2);
56 assertThat($query2, is(
"SELECT $this->almostAllColumns,0 AS group_fk FROM ONLY license_ref WHERE rf_pk<100"));
59 public function testQueryLicenseCandidate()
64 $reflection = new \ReflectionClass(get_class($licenseViewProxy));
65 $method = $reflection->getMethod(
'queryLicenseCandidate');
66 $method->setAccessible(
true);
68 $options1 = array(
'columns'=>array(
'rf_pk',
'rf_shortname'));
69 $query1 = $method->invoke($licenseViewProxy,$options1);
70 assertThat($query1, is(
"SELECT rf_pk,rf_shortname FROM license_candidate WHERE group_fk=$groupId"));
72 $options2 = array(
'extraCondition'=>
'rf_pk<100');
73 $query2 = $method->invoke($licenseViewProxy,$options2);
74 assertThat($query2, is(
"SELECT $this->almostAllColumns,group_fk FROM license_candidate WHERE group_fk=$groupId AND rf_pk<100"));
77 $options3 = array(LicenseViewProxy::CANDIDATE_PREFIX=>$prefix,
'columns'=>array(
'rf_shortname'));
78 $query3 = $method->invoke($licenseViewProxy,$options3);
79 assertThat($query3, is(
"SELECT '". pg_escape_string($prefix).
"'||rf_shortname AS rf_shortname FROM license_candidate WHERE group_fk=$groupId"));
82 public function testConstruct()
85 $query0 = $licenseViewProxy0->getDbViewQuery();
86 $expected0 =
"SELECT $this->almostAllColumns,0 AS group_fk FROM ONLY license_ref";
87 assertThat($query0,is($expected0));
90 $query123 = $licenseViewProxy123->getDbViewQuery();
91 $expected123 =
"SELECT $this->almostAllColumns,group_fk FROM license_candidate WHERE group_fk=123";
92 assertThat($query123,is($expected123));
95 $query0123 = $licenseViewProxy0123->getDbViewQuery();
96 $expected0123 =
"$expected123 UNION $expected0";
97 assertThat($query0123,is($expected0123));