Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
47.06% |
8 / 17 |
|
25.00% |
1 / 4 |
CRAP | |
0.00% |
0 / 1 |
WorkspaceInitializer | |
47.06% |
8 / 17 |
|
25.00% |
1 / 4 |
14.27 | |
0.00% |
0 / 1 |
importSampleFile | |
75.00% |
6 / 8 |
|
0.00% |
0 / 1 |
3.14 | |||
importSampleFiles | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
cleanWorkspace | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
createSampleScanImage | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** @noinspection PhpUnhandledExceptionInspection */ |
3 | declare(strict_types=1); |
4 | // TODO unit test |
5 | |
6 | class WorkspaceInitializer { |
7 | const sampleDataPaths = [ |
8 | "default" => [ |
9 | "sampledata/Booklet.xml" => "Booklet/SAMPLE_BOOKLET.XML", |
10 | "sampledata/Booklet2.xml" => "Booklet/SAMPLE_BOOKLET2.XML", |
11 | "sampledata/Booklet3.xml" => "Booklet/SAMPLE_BOOKLET3.XML", |
12 | "sampledata/Testtakers.xml" => "Testtakers/SAMPLE_TESTTAKERS.XML", |
13 | "sampledata/SysCheck.xml" => "SysCheck/SAMPLE_SYSCHECK.XML", |
14 | "sampledata/Unit.xml" => "Unit/SAMPLE_UNIT.XML", |
15 | "sampledata/SAMPLE_UNITCONTENTS.HTM" => "Resource/SAMPLE_UNITCONTENTS.HTM", |
16 | "sampledata/Unit2.xml" => "Unit/SAMPLE_UNIT2.XML", |
17 | "sampledata/SysCheck-Report.json" => "SysCheck/reports/SAMPLE_SYSCHECK-REPORT.JSON", |
18 | "sampledata/sample_resource_package.itcr.zip" => "Resource/sample_resource_package.itcr.zip", |
19 | "sampledata/verona-player-simple-6.0.html" => "Resource/verona-player-simple-6.0.html", |
20 | ], |
21 | "system-test" => [ |
22 | "sampledata/system-test/CY_BKL_Mode_Demo.xml" => "Booklet/CY_BKL_Mode_Demo.xml", |
23 | "sampledata/system-test/CY_BKL_Mode_Review.xml" => "Booklet/CY_BKL_Mode_Review.xml", |
24 | "sampledata/system-test/CY_BKL_Mode_RunHotReturn.xml" => "Booklet/CY_BKL_Mode_RunHotReturn.xml", |
25 | "sampledata/system-test/CY_BKL_Mode_RunHotRestart.xml" => "Booklet/CY_BKL_Mode_RunHotRestart.xml", |
26 | "sampledata/system-test/CY_BKL_SessionManagement_HotModi.xml" => "Booklet/CY_BKL_SessionManagement_HotModi.xml", |
27 | "sampledata/system-test/CY_Test_Logins.xml" => "Testtakers/CY_Test_Logins.xml", |
28 | "sampledata/system-test/CY_Unit100.xml" => "Unit/CY_SAMPLE_UNIT100.XML", |
29 | "sampledata/system-test/CY_Unit101.xml" => "Unit/CY_SAMPLE_UNIT101.XML", |
30 | "sampledata/system-test/CY_Unit102.xml" => "Unit/CY_SAMPLE_UNIT102.XML", |
31 | "sampledata/system-test/CY_Unit103.xml" => "Unit/CY_SAMPLE_UNIT103.XML", |
32 | "sampledata/system-test/CY_Unit104.xml" => "Unit/CY_SAMPLE_UNIT104.XML", |
33 | ] |
34 | ]; |
35 | |
36 | private function importSampleFile(int $workspaceId, string $source, string $target): void { |
37 | $importFileName = ROOT_DIR . '/' . $source; |
38 | |
39 | if (!file_exists($importFileName)) { |
40 | throw new Exception("File not found: `$importFileName`"); |
41 | } |
42 | |
43 | $dir = pathinfo($target, PATHINFO_DIRNAME); |
44 | $fileName = basename($target); |
45 | $fileName = Folder::createPath(DATA_DIR . "/ws_$workspaceId/$dir") . $fileName; |
46 | |
47 | if (!@copy($importFileName, $fileName)) { |
48 | throw new Exception("Could not write file: $fileName"); |
49 | } |
50 | } |
51 | |
52 | public function importSampleFiles(int $workspaceId, string $sampleFileSet = 'default'): void { |
53 | foreach (self::sampleDataPaths[$sampleFileSet] as $source => $target) { |
54 | $this->importSampleFile($workspaceId, $source, $target); |
55 | } |
56 | } |
57 | |
58 | public function cleanWorkspace(int $workspaceId): void { |
59 | Folder::deleteContentsRecursive(DATA_DIR . "/ws_$workspaceId/"); |
60 | rmdir(DATA_DIR . "/ws_$workspaceId/"); |
61 | } |
62 | |
63 | public function createSampleScanImage(string $fileName, int $workspaceId): void { |
64 | $png = '89504e470d0a1a0a0000000d49484452000000010000000108060000001f15c4890000000d4944415478da636460f85f0f0002870180eb47ba920000000049454e44ae426082'; |
65 | file_put_contents( |
66 | Folder::createPath(DATA_DIR . "/ws_$workspaceId") . $fileName, |
67 | hex2bin($png) |
68 | ); |
69 | } |
70 | } |