public function testCreateCsv() { $testDb = new TestLiteDb(); $testDb->createPlainTables(array('license_ref', 'license_map')); $dbManager = $testDb->getDbManager(); $licenses = array(); for ($i = 1; $i < 4; $i++) { $licenses[$i] = array('rf_pk' => $i, 'rf_shortname' => 'lic' . $i, 'rf_fullname' => 'lice' . $i, 'rf_text' => 'text' . $i, 'rf_url' => $i . $i, 'rf_notes' => 'note' . $i, 'rf_source' => 's' . $i, 'rf_detector_type' => 1, 'rf_risk' => $i - 1); $dbManager->insertTableRow('license_ref', $licenses[$i]); } $dbManager->insertTableRow('license_map', array('rf_fk' => 3, 'rf_parent' => 1, 'usage' => LicenseMap::CONCLUSION)); $dbManager->insertTableRow('license_map', array('rf_fk' => 3, 'rf_parent' => 2, 'usage' => LicenseMap::REPORT)); $licenseCsvExport = new LicenseCsvExport($dbManager); $head = array('shortname', 'fullname', 'text', 'parent_shortname', 'report_shortname', 'url', 'notes', 'source', 'risk'); $out = fopen('php://output', 'w'); $csv = $licenseCsvExport->createCsv(); ob_start(); fputcsv($out, $head); fputcsv($out, array($licenses[1]['rf_shortname'], $licenses[1]['rf_fullname'], $licenses[1]['rf_text'], null, null, $licenses[1]['rf_url'], $licenses[1]['rf_notes'], $licenses[1]['rf_source'], $licenses[1]['rf_risk'])); fputcsv($out, array($licenses[2]['rf_shortname'], $licenses[2]['rf_fullname'], $licenses[2]['rf_text'], null, null, $licenses[2]['rf_url'], $licenses[2]['rf_notes'], $licenses[2]['rf_source'], $licenses[2]['rf_risk'])); fputcsv($out, array($licenses[3]['rf_shortname'], $licenses[3]['rf_fullname'], $licenses[3]['rf_text'], $licenses[1]['rf_shortname'], $licenses[2]['rf_shortname'], $licenses[3]['rf_url'], $licenses[3]['rf_notes'], $licenses[3]['rf_source'], $licenses[3]['rf_risk'])); $expected = ob_get_contents(); ob_end_clean(); assertThat($csv, is(equalTo($expected))); $delimiter = '|'; $licenseCsvExport->setDelimiter($delimiter); $csv3 = $licenseCsvExport->createCsv(3); ob_start(); fputcsv($out, $head, $delimiter); fputcsv($out, array($licenses[3]['rf_shortname'], $licenses[3]['rf_fullname'], $licenses[3]['rf_text'], $licenses[1]['rf_shortname'], $licenses[2]['rf_shortname'], $licenses[3]['rf_url'], $licenses[3]['rf_notes'], $licenses[3]['rf_source'], $licenses[3]['rf_risk']), $delimiter); $expected3 = ob_get_contents(); ob_end_clean(); assertThat($csv3, is(equalTo($expected3))); }
public function testQueryTwoScanners() { $this->testDb->getDbManager()->queryOnce('CREATE TABLE monk_ars AS SELECT * FROM nomos_ars WHERE 0=1'); $this->testDb->insertData(array('monk_ars')); $uploadId = 2; $agentNames = array('nomos', 'monk'); $latestScannerProxy = new LatestScannerProxy($uploadId, $agentNames, 'latest_scanner', "AND agent_enabled='true'"); $sql = $latestScannerProxy->getDbViewQuery(); $scanners = $this->getAllColumns($sql); assertThat($scanners, arrayContainingInAnyOrder(array(array('agent_pk' => 6, 'agent_name' => 'nomos'), array('agent_pk' => 5, 'agent_name' => 'monk')))); }
public function testGetKeyFromShortname() { $testDb = new TestLiteDb(); $testDb->createPlainTables(array('license_ref')); $shortname = 'licA'; $knownId = 101; /** @var DbManager */ $dbManager =& $testDb->getDbManager(); $dbManager->insertTableRow('license_ref', array('rf_pk' => $knownId, 'rf_shortname' => $shortname)); $licenseCsvImport = new LicenseCsvImport($dbManager); assertThat(Reflectory::invokeObjectsMethodnameWith($licenseCsvImport, 'getKeyFromShortname', array($shortname)), equalTo($knownId)); assertThat(Reflectory::invokeObjectsMethodnameWith($licenseCsvImport, 'getKeyFromShortname', array("no {$shortname}")), equalTo(false)); }
public function testAddGroupMembership() { $this->testDb->createPlainTables(array('users', 'groups', 'group_user_member')); $this->testDb->insertData(array('users', 'groups', 'group_user_member')); $this->userDao->addGroupMembership($groupId = 2, $userId = 1); $map = $this->userDao->getUserGroupMap($userId); assertThat($map, hasKey($groupId)); }