|
7 | 7 | +-------------------------------------------------------------------------+ |
8 | 8 | */ |
9 | 9 |
|
10 | | -/* |
11 | | - * Verify setup.php defines required plugin hooks and info function. |
12 | | - */ |
| 10 | +// Verify setup.php defines required plugin hooks and info function. |
13 | 11 |
|
14 | 12 | function thold_read_setup_source() { |
15 | 13 | $setupPath = realpath(__DIR__ . '/../../setup.php'); |
@@ -47,3 +45,40 @@ function thold_read_setup_source() { |
47 | 45 | expect($source)->toContain('parse_ini_file'); |
48 | 46 | expect($source)->toContain("return \$info['info'];"); |
49 | 47 | }); |
| 48 | + |
| 49 | +it('setup.php file exists and is readable at expected path', function () { |
| 50 | + $setupPath = __DIR__ . '/../../setup.php'; |
| 51 | + expect(file_exists($setupPath))->toBeTrue('setup.php does not exist at expected location'); |
| 52 | + expect(is_readable($setupPath))->toBeTrue('setup.php exists but is not readable'); |
| 53 | + expect(realpath($setupPath))->not->toBeFalse('realpath() failed to resolve setup.php'); |
| 54 | +}); |
| 55 | + |
| 56 | +it('registers required poller and device hooks via api_plugin_register_hook', function () { |
| 57 | + $source = thold_read_setup_source(); |
| 58 | + expect($source)->toContain("'poller_output'"); |
| 59 | + expect($source)->toContain("'poller_bottom'"); |
| 60 | + expect($source)->toContain("'device_action_array'"); |
| 61 | + expect($source)->toContain("'api_device_save'"); |
| 62 | +}); |
| 63 | + |
| 64 | +it('api_plugin_register_hook calls use at least four arguments', function () { |
| 65 | + $source = thold_read_setup_source(); |
| 66 | + $matches = []; |
| 67 | + preg_match_all('/api_plugin_register_hook\s*\([^;)]+\)/', $source, $matches); |
| 68 | + |
| 69 | + expect(count($matches[0]))->toBeGreaterThan(0, 'No api_plugin_register_hook calls found in setup.php'); |
| 70 | + |
| 71 | + foreach ($matches[0] as $call) { |
| 72 | + $argCount = substr_count($call, ',') + 1; |
| 73 | + expect($argCount)->toBeGreaterThanOrEqual( |
| 74 | + 4, |
| 75 | + "Hook call has fewer than 4 arguments: {$call}" |
| 76 | + ); |
| 77 | + } |
| 78 | +}); |
| 79 | + |
| 80 | +it('api_plugin_register_hook hook names are non-empty string literals', function () { |
| 81 | + $source = thold_read_setup_source(); |
| 82 | + expect($source)->not->toMatch("/api_plugin_register_hook\s*\(\s*[^,]+,\s*''\s*,/"); |
| 83 | + expect($source)->not->toMatch('/api_plugin_register_hook\s*\(\s*[^,]+,\s*""\s*,/'); |
| 84 | +}); |
0 commit comments