protected function setUp()
 {
     $this->testDb = new TestLiteDb();
     $this->testDb->createPlainTables(array('agent', 'ars_master'));
     $dbManager =& $this->testDb->getDbManager();
     $dbManager->queryOnce('ALTER TABLE ars_master RENAME TO nomos_ars');
     $this->testDb->insertData(array('agent', 'nomos_ars'));
     $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
 }
 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)));
 }
Пример #3
0
 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));
 }
 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));
 }