29 private $assertCountBefore;
32 protected function setUp()
35 $this->testDb->createPlainTables( array(
'agent',
'ars_master') );
36 $dbManager = &$this->testDb->getDbManager();
37 $dbManager->queryOnce(
'ALTER TABLE ars_master RENAME TO nomos_ars');
38 $this->testDb->insertData(array(
'agent',
'nomos_ars'));
39 $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
42 protected function tearDown()
44 $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount()-$this->assertCountBefore);
48 private function getAllColumns($sql,$params=array())
50 $backtrace = debug_backtrace();
51 $caller = $backtrace[1];
52 $stmt =
"$caller[class]::$caller[function]";
54 $dbManager = &$this->testDb->getDbManager();
55 $dbManager->prepare($stmt, $sql);
57 $res = $dbManager->execute($stmt,$params);
58 $result = $dbManager->fetchAll($res);
59 $dbManager->freeResult($res);
64 public function testQuery()
67 $agentNames = array(
'nomos');
68 $latestScannerProxy =
new LatestScannerProxy($uploadId,$agentNames,
'latest_scanner',
"AND agent_enabled='true'");
69 $sql = $latestScannerProxy->getDbViewQuery();
70 $scanners = $this->getAllColumns($sql);
71 assertThat($scanners,arrayContaining(array(array(
'agent_pk'=>6,
'agent_name'=>
'nomos'))));
74 public function testQueryTwoScanners()
76 $this->testDb->getDbManager()->queryOnce(
'CREATE TABLE monk_ars AS SELECT * FROM nomos_ars WHERE 0=1');
77 $this->testDb->insertData(array(
'monk_ars'));
79 $agentNames = array(
'nomos',
'monk');
80 $latestScannerProxy =
new LatestScannerProxy($uploadId,$agentNames,
'latest_scanner',
"AND agent_enabled='true'");
81 $sql = $latestScannerProxy->getDbViewQuery();
82 $scanners = $this->getAllColumns($sql);
83 assertThat($scanners,arrayContainingInAnyOrder(array(array(
'agent_pk'=>6,
'agent_name'=>
'nomos'),array(
'agent_pk'=>5,
'agent_name'=>
'monk'))));
92 $agentNames = array();
93 new LatestScannerProxy($uploadId,$agentNames,
'latest_scanner',
"AND agent_enabled='true'");
96 public function testQueryPrepared()
99 $agentNames = array(
'nomos');
100 $latestScannerProxy =
new LatestScannerProxy(
'$1',$agentNames,
'latest_scanner',
"AND agent_enabled='true'");
101 $sql = $latestScannerProxy->getDbViewQuery();
102 $scanners = $this->getAllColumns($sql,array($uploadId));
103 assertThat($scanners,arrayContaining(array(array(
'agent_pk'=>6,
'agent_name'=>
'nomos'))));
106 public function testMaterializePossibleForUnparameterizedQuery()
109 $agentNames = array(
'nomos');
110 $latestScannerProxy =
new LatestScannerProxy($uploadId,$agentNames,
'latest_scanner',
"AND agent_enabled='true'");
111 $latestScannerProxy->materialize();
119 $agentNames = array(
'nomos');
120 $latestScannerProxy =
new LatestScannerProxy(
'$1',$agentNames,
'latest_scanner',
"AND agent_enabled='true'");
121 $latestScannerProxy->materialize();
125 public function testGetNameToIdMap()
128 $agentNames = array(
'nomos');
129 $latestScannerProxy =
new LatestScannerProxy($uploadId,$agentNames,
'latest_scanner',
"AND agent_enabled='true'");
130 $map = $latestScannerProxy->getNameToIdMap();
131 assertThat($map,equalTo(array(
'nomos'=>6)));
139 $agentNames = array(
'nomos');
140 $latestScannerProxy =
new LatestScannerProxy(
'$1',$agentNames,
'latest_scanner',
"AND agent_enabled='true'");
141 $latestScannerProxy->getNameToIdMap();
testGetNameToIdMapNotPossibleForParameterizedQuery()
testMaterializeNotPossibleForParameterizedQuery()