Fix testing as a result of changes in 34139bc

This commit is contained in:
Deon George 2021-07-02 10:03:36 +10:00
parent 6656fc3d3d
commit 9e1723a7af
No known key found for this signature in database
GPG Key ID: 7670E8DC27415254
5 changed files with 19 additions and 31 deletions

View File

@ -23,7 +23,7 @@ trait NextKey
$model->id = self::NextId(); $model->id = self::NextId();
if (! $model->site_id) if (! $model->site_id)
$model->site_id = config('SITE')->id; $model->site_id = config('SITE')->site_id;
}); });
static::saved(function($model) static::saved(function($model)
@ -33,21 +33,22 @@ trait NextKey
throw new \Exception('Missing record_id const for '.get_class($model)); throw new \Exception('Missing record_id const for '.get_class($model));
try { try {
$mo = Module::where('name',$model::RECORD_ID)->firstOrFail(); $mo = Module::where('name',$model::RECORD_ID)
->where('site_id',$model->site_id)->firstOrFail();
} catch (ModelNotFoundException $e) { } catch (ModelNotFoundException $e) {
Log::critical(sprintf('Module [%s] not recorded, we\'ll create it.',$model::RECORD_ID),['model'=>$model->getAttributes()]); Log::critical(sprintf('Module [%s] not recorded, we\'ll create it.',$model::RECORD_ID),['model'=>$model->getAttributes()]);
$mo = new Module; $mo = new Module;
$mo->name = $model::RECORD_ID; $mo->name = $model::RECORD_ID;
$mo->site_id = $model->site_id ?: config('SITE')->id; $mo->site_id = $model->site_id ?: config('SITE')->site_id;
$mo->save(); $mo->save();
} }
if (! $mo->record) { if (! $mo->record) {
$mo->record = new Record; $mo->record = new Record;
$mo->record->module_id = $mo->id; $mo->record->module_id = $mo->id;
$mo->record->site_id = $model->site_id ?: config('SITE')->id; $mo->record->site_id = $model->site_id ?: config('SITE')->site_id;
} }
$mo->record->id = $model->id; $mo->record->id = $model->id;

View File

@ -30,17 +30,12 @@ class SiteFactory extends Factory
'id' => $this->faker->numberBetween(255,65535), 'id' => $this->faker->numberBetween(255,65535),
// date_orig // date_orig
'active' => TRUE, 'active' => TRUE,
'site_id' => $this->faker->numberBetween(255,65535),
'country_id' => $co->id, 'country_id' => $co->id,
'language_id' => $lo->id, 'language_id' => $lo->id,
'currency_id' => $cyo->id, 'currency_id' => $cyo->id,
// 'url'', // Needs to be passed in // 'url'', // Needs to be passed in
// login_expire, // admin_id,
// time_format,
// date_format,
// decimal_place,
// module_config,
// site_details,
// admin_date,
]; ];
} }
} }

View File

@ -29,7 +29,7 @@ class RenameSetup extends Migration
DB::statement('ALTER TABLE ab_setup RENAME TO sites'); DB::statement('ALTER TABLE ab_setup RENAME TO sites');
DB::statement('ALTER TABLE sites MODIFY url VARCHAR(256) NOT NULL'); DB::statement('ALTER TABLE sites MODIFY url VARCHAR(256) NOT NULL');
DB::statement('ALTER TABLE sites CHANGE COLUMN id site_id INT NOT NULL'); DB::statement('ALTER TABLE sites CHANGE COLUMN id site_id INT NOT NULL');
DB::statement('ALTER TABLE sites MODIFY admin_id INT(10) UNSIGNED NOT NULL'); DB::statement('ALTER TABLE sites MODIFY admin_id INT(10) UNSIGNED DEFAULT NULL');
DB::statement('ALTER TABLE sites MODIFY active TINYINT(1) NOT NULL'); DB::statement('ALTER TABLE sites MODIFY active TINYINT(1) NOT NULL');
Schema::table('sites', function (Blueprint $table) { Schema::table('sites', function (Blueprint $table) {

View File

@ -20,35 +20,27 @@ class SiteTableSeeder extends Seeder
$o->id = 254; $o->id = 254;
// $o->date_orig // $o->date_orig
$o->active = TRUE; $o->active = TRUE;
$o->site_id = 254;
$o->country_id = 61; $o->country_id = 61;
$o->language_id = 1; $o->language_id = 1;
$o->currency_id = 6; $o->currency_id = 6;
$o->url = 'test1'; $o->url = 'test1';
// $o->login_expire; //$o->admin_id;
// $o->time_format;
// $o->date_format;
// $o->decimal_place;
// $o->module_config;
// $o->site_details;
// $o->admin_date;
$o->save(); $o->save();
// Test Sites 254 & 255 // Test Sites 254 & 255
$o = new Site; $o = new Site;
$o->id = 255; $o->id = 255;
// $o->date_orig // $o->date_orig
$o->site_id = 255;
$o->active = TRUE; $o->active = TRUE;
$o->country_id = 61; $o->country_id = 61;
$o->language_id = 1; $o->language_id = 1;
$o->currency_id = 6; $o->currency_id = 6;
$o->url = 'test2'; $o->url = 'test2';
// $o->login_expire; // $o->admin_id;
// $o->time_format;
// $o->date_format;
// $o->decimal_place;
// $o->module_config;
// $o->site_details;
// $o->admin_date;
$o->save(); $o->save();
} }
} }

View File

@ -16,8 +16,8 @@ class InvoiceTest extends TestCase
private function account_setup(): void private function account_setup(): void
{ {
$this->setup['account'] = [ $this->setup['account'] = [
'a'=>Account::factory()->create(['site_id'=>Arr::get($this->setup,'site.a')->id]), 'a'=>Account::factory()->create(['site_id'=>Arr::get($this->setup,'site.a')->site_id]),
'b'=>Account::factory()->create(['site_id'=>Arr::get($this->setup,'site.b')->id]) 'b'=>Account::factory()->create(['site_id'=>Arr::get($this->setup,'site.b')->site_id])
]; ];
} }
@ -28,8 +28,8 @@ class InvoiceTest extends TestCase
'b'=>Site::factory()->create(['url'=>'Test B']) 'b'=>Site::factory()->create(['url'=>'Test B'])
]; ];
Group::factory()->create(['site_id'=>Arr::get($this->setup,'site.a')->id]); Group::factory()->create(['site_id'=>Arr::get($this->setup,'site.a')->site_id]);
Group::factory()->create(['site_id'=>Arr::get($this->setup,'site.b')->id]); Group::factory()->create(['site_id'=>Arr::get($this->setup,'site.b')->site_id]);
} }
/** /**
@ -45,7 +45,7 @@ class InvoiceTest extends TestCase
// Create two services for the same account // Create two services for the same account
// First service was billed a month ago, so this invoice will have 1 service charge // First service was billed a month ago, so this invoice will have 1 service charge
$o = Service::factory()->create([ $o = Service::factory()->create([
'site_id'=>Arr::get($this->setup,'site.a')->id, 'site_id'=>Arr::get($this->setup,'site.a')->site_id,
'account_id'=>Arr::get($this->setup,'account.a')->id, 'account_id'=>Arr::get($this->setup,'account.a')->id,
]); ]);
$po = Product::factory()->notStrict()->make(); $po = Product::factory()->notStrict()->make();