Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function export() : void
public function import() : bool
{
$authenticatedUser = Auth::user();
$userId = $authenticatedUser ? $authenticatedUser->id : User::where('username', 'admin')->pluck('id');
$userId = $authenticatedUser ? $authenticatedUser->id : User::where('is_administrator', true)->first()->id;
switch ($this->mode) {
case 'copy':
case 'new':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export default {
helperProcessId: null,
startEvents: null,
shouldImportProcessTemplate: true,

};
},
computed: {
Expand Down
3 changes: 1 addition & 2 deletions tests/Feature/ImportExport/Exporters/ScriptExporterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ public function testHiddenUsesParentMode()

public function testNoMatchingRunAsUser()
{
$admin_user = User::factory()->create(['is_administrator' => true]);
DB::beginTransaction();
$user = User::factory()->create(['username' => 'test']);
$admin_user = User::where('is_administrator', true)->first();
$script = Script::factory()->create(['title' => 'test', 'run_as_user_id' => $user->id]);

$payload = $this->export($script, ScriptExporter::class, null, false);
Expand All @@ -126,7 +126,6 @@ public function testNoMatchingRunAsUser()

$script = Script::where('title', 'test')->firstOrFail();
$this->assertEquals($script->run_as_user_id, $admin_user->id);
$admin_user->delete();
}

public function testRunAsUserIdNull()
Expand Down
1 change: 1 addition & 0 deletions tests/Feature/ImportExport/HelperTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tests\Feature\ImportExport;

use Database\Seeders\AdminTestUserSeeder;
use Database\Seeders\SignalSeeder;
use Illuminate\Http\UploadedFile;
use ProcessMaker\ImportExport\Exporter;
Expand Down
20 changes: 20 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use ProcessMaker\Models\ProcessRequestLock;
use ProcessMaker\Models\SecurityLog;
use ProcessMaker\Models\Setting;
use ProcessMaker\Models\User;

abstract class TestCase extends BaseTestCase
{
Expand All @@ -36,6 +37,8 @@ protected function setUp(): void

$this->disableSetContentMiddleware();

$this->createAdministrator();

foreach (get_class_methods($this) as $method) {
$imethod = strtolower($method);
if (strpos($imethod, 'setup') === 0 && $imethod !== 'setup') {
Expand All @@ -44,6 +47,23 @@ protected function setUp(): void
}
}

/**
* Creates an admin user for each test if one does not already exist
*
* @return void
*/
protected function createAdministrator(): void
{
if (User::where('is_administrator', true)->exists()) {
return;
}

User::factory()->create([
'password' => Hash::make('password'),
'is_administrator' => true,
]);
}

/**
* Disable middleware that calls setContent() otherwise we can't use assertViewIs()
*/
Expand Down