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
57 changes: 57 additions & 0 deletions database/seeders/AdminTestUserSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;
use Laravel\Passport\ClientRepository;
use ProcessMaker\Models\Group;
use ProcessMaker\Models\GroupMember;
use ProcessMaker\Models\User;

class AdminTestUserSeeder extends Seeder
{
public static $INSTALLER_ADMIN_TEST_USERNAME = 'admin_test';

public static $INSTALLER_ADMIN_TEST_PASSWORD = 'admin';

public static $INSTALLER_ADMIN_TEST_EMAIL = 'admin_test@processmaker.com';

public static $INSTALLER_ADMIN_TEST_FIRSTNAME = 'Admin';

public static $INSTALLER_ADMIN_TEST_LASTNAME = 'TestUser';

/**
* Run the database seeds.
*
* @return void
*/
public function run(ClientRepository $clients)
{
// Create admin user
User::updateOrCreate([
'username' => self::$INSTALLER_ADMIN_TEST_USERNAME,
'is_administrator' => true,
], [
'username' => self::$INSTALLER_ADMIN_TEST_USERNAME,
'password' => Hash::make(self::$INSTALLER_ADMIN_TEST_PASSWORD),
'email' => self::$INSTALLER_ADMIN_TEST_EMAIL,
'firstname' => self::$INSTALLER_ADMIN_TEST_FIRSTNAME,
'lastname' => self::$INSTALLER_ADMIN_TEST_LASTNAME,
'address' => null,
'city' => null,
'state' => null,
'postal' => null,
'country' => null,
'phone' => null,
'fax' => null,
'cell' => null,
'title' => null,
'birthdate' => null,
'timezone' => 'America/Los_Angeles',
'datetime_format' => 'm/d/Y H:i',
'language' => 'en',
'status' => 'ACTIVE',
]);
}
}
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
3 changes: 3 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@
Artisan::call('migrate:fresh', []);
Artisan::call('db:seed', ['--class' => 'AnonymousUserSeeder']);

// Seed the super administrator user data
Artisan::call('db:seed', ['--class' => 'AdminTestUserSeeder']);

\Illuminate\Foundation\Testing\RefreshDatabaseState::$migrated = true;

ScriptExecutor::firstOrCreate(
Expand Down