27 public $EXE_PATH =
"";
38 private $testInstaller;
44 protected function setUp() : void {
49 $cwd = dirname(__DIR__, 4).
'/build/src/mimetype/agent_tests';
50 $this->testDb =
new TestPgDb(
"fossmimetypetest");
51 $tables = array(
'mimetype',
'agent');
52 $this->testDb->createPlainTables($tables);
53 $this->testDb->createSequences([
'mimetype_mimetype_pk_seq',
'agent_agent_pk_seq']);
54 $this->testDb->createConstraints([
'mimetype_pk',
'dirmodemask',
'agent_pkey']);
55 $this->testDb->alterTables($tables);
56 $this->
dbManager = $this->testDb->getDbManager();
57 $DB_CONF = $this->testDb->getFossSysConf();
59 $this->testInstaller->init();
60 $this->testInstaller->cpRepo();
61 $this->testInstaller->install($cwd.
'/..');
63 $sql =
"INSERT INTO public.mimetype (mimetype_pk, mimetype_name) VALUES (2, 'application/gzip'),"
64 .
" (3, 'application/x-gzip'), (4, 'application/x-compress'), (5, 'application/x-bzip'), (6, 'application/x-bzip2'),"
65 .
" (7, 'application/x-upx'), (8, 'application/pdf'), (9, 'application/x-pdf'), (10, 'application/x-zip'),"
66 .
" (11, 'application/zip'), (12, 'application/x-tar'), (13, 'application/x-gtar'), (14, 'application/x-cpio'),"
67 .
" (15, 'application/x-rar'), (16, 'application/x-cab'), (17, 'application/x-7z-compressed'),"
68 .
" (18, 'application/x-7z-w-compressed'), (19, 'application/x-rpm'), (20, 'application/x-archive'),"
69 .
" (21, 'application/x-debian-package'), (22, 'application/x-iso'), (23, 'application/x-iso9660-image'),"
70 .
" (24, 'application/x-fat'), (25, 'application/x-ntfs'), (26, 'application/x-ext2'), (27, 'application/x-ext3'),"
71 .
" (28, 'application/x-x86_boot'), (29, 'application/x-debian-source'), (30, 'application/x-xz'),"
72 .
" (31, 'application/jar'), (32, 'application/java-archive'), (33, 'application/x-dosexec'),"
73 .
" (34, 'text/plain');";
74 $result = $this->
dbManager->getSingleRow($sql, [], __METHOD__ .
"insert.mimetype");
76 $EXE_PATH = $cwd .
'/../agent/mimetype';
78 if(file_exists($EXE_PATH))
80 $usage =
'Usage: '.$EXE_PATH.
' [options] [file [file [...]]';
84 $this->assertFileExists($EXE_PATH,
85 $message =
'FATAL: cannot find executable file, stop testing\n');
88 $EXE_PATH .=
" -C -c $DB_CONF";
89 $last = exec(
"$EXE_PATH -h 2>&1", $out, $rtn);
90 $this->assertEquals($usage, $out[0]);
104 $mimeType1 =
"application/x-msi";
106 $sql =
"DELETE FROM mimetype where mimetype_name in ('$mimeType1');";
107 $result = $this->
dbManager->getSingleRow($sql, [], __METHOD__ .
"delete.mimetype");
111 $filePath = dirname(__DIR__, 4).
'/build/src/ununpack/agent_tests/testdata/test.msi';
112 $command =
"$EXE_PATH $filePath";
113 exec($command, $out, $rtn);
114 $this->assertStringStartsWith($mimeType1, $out[0]);
117 $filePath = dirname(__DIR__, 2).
"/mimetype.conf";
118 $command =
"$EXE_PATH $filePath";
120 exec($command, $out, $rtn);
121 $mimeType2 =
"text/plain";
122 $this->assertStringStartsWith($mimeType2, $out[0]);
124 $sql =
"DELETE FROM mimetype where mimetype_name in ('$mimeType1');";
125 $result = $this->
dbManager->getSingleRow($sql, [], __METHOD__ .
"delete.mimetype");
138 $mimeType =
"text/plain";
140 $sql =
"DELETE FROM mimetype where mimetype_name in ('$mimeType');";
141 $result = $this->
dbManager->getSingleRow($sql, [], __METHOD__ .
"delete.mimetype");
143 $sql =
"INSERT INTO mimetype(mimetype_pk, mimetype_name) VALUES(10000, '$mimeType');";
144 $result = $this->
dbManager->getSingleRow($sql, [], __METHOD__ .
"insert.mimetype");
146 $filePath = dirname(__DIR__).
"/CMakeLists.txt";
147 $command =
"$EXE_PATH $filePath";
148 exec($command, $out, $rtn);
149 $expected_string =
"text/plain : mimetype_pk=10000";
150 $this->assertStringStartsWith($expected_string, $out[0]);
153 $sql =
"DELETE FROM mimetype where mimetype_name in ('$mimeType');";
154 $result = $this->
dbManager->getSingleRow($sql, [], __METHOD__ .
"delete.mimetype");
162 if (!is_callable(
'cwdect')) {
165 $this->testDb->fullDestruct();
166 $this->testDb =
null;
168 $this->testInstaller->uninstall($cwd.
'/..');
Test mimetype agent from cli.
testMimetypeInDB()
The mimetype name is in table mimetype.
testMimetypeNotInDB()
Test mimetype name is not in table mimetype.
fo_dbManager * dbManager
fo_dbManager object