|
3 | 3 | namespace Tests; |
4 | 4 |
|
5 | 5 | use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts; |
6 | | -use Illuminate\Database\DatabaseManager; |
7 | 6 | use Illuminate\Foundation\Testing\DatabaseTransactions; |
8 | 7 | use Illuminate\Foundation\Testing\TestCase as BaseTestCase; |
9 | 8 | use Illuminate\Support\Facades\Artisan; |
10 | 9 | use Illuminate\Support\Facades\Bus; |
11 | 10 | use PDOException; |
| 11 | +use ProcessMaker\ImportExport\Importer; |
| 12 | +use ProcessMaker\ImportExport\Options; |
12 | 13 | use ProcessMaker\Jobs\RefreshArtisanCaches; |
13 | 14 | use ProcessMaker\Models\Process; |
14 | | -use ProcessMaker\Models\ProcessRequest; |
15 | | -use ProcessMaker\Models\ProcessRequestLock; |
16 | | -use ProcessMaker\Models\SecurityLog; |
17 | | -use ProcessMaker\Models\Setting; |
18 | 15 |
|
19 | 16 | abstract class TestCase extends BaseTestCase |
20 | 17 | { |
@@ -127,6 +124,30 @@ protected function createProcessFromBPMN(string $bpmnFile, array $attributes = [ |
127 | 124 | return Process::factory()->create(array_merge($data, $attributes)); |
128 | 125 | } |
129 | 126 |
|
| 127 | + /** |
| 128 | + * Creates a Process instance from a JSON file. |
| 129 | + * |
| 130 | + * This method reads the specified JSON file, merges the provided attributes, |
| 131 | + * and creates a new Process instance. |
| 132 | + * |
| 133 | + * @param string $jsonFile The path to the JSON file containing the process definition. |
| 134 | + * @param array $attributes Additional attributes to merge into the process definition. |
| 135 | + * @return Process The created Process instance. |
| 136 | + */ |
| 137 | + protected function createProcessFromJSON(string $jsonFile, array $attributes = []): Process |
| 138 | + { |
| 139 | + $payload = json_decode(file_get_contents($jsonFile), true); |
| 140 | + $options = new Options([]); |
| 141 | + $importer = new Importer($payload, $options); |
| 142 | + $importer->previewImport(); |
| 143 | + $manifest = $importer->doImport(); |
| 144 | + $processId = $manifest[$payload['root']]->log['newId']; |
| 145 | + $process = Process::find($processId); |
| 146 | + $process->update($attributes); |
| 147 | + |
| 148 | + return $process; |
| 149 | + } |
| 150 | + |
130 | 151 | /** |
131 | 152 | * Connections transacts |
132 | 153 | * |
|
0 commit comments