1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 20:22:42 +01:00
invoiceninja/tests/MockUnitData.php

134 lines
3.4 KiB
PHP
Raw Normal View History

2021-07-02 02:06:26 +02:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
2021-07-02 02:06:26 +02:00
*/
namespace Tests;
use App\DataMapper\CompanySettings;
use App\DataMapper\DefaultSettings;
use App\Factory\InvoiceItemFactory;
2023-11-26 08:41:42 +01:00
use App\Models\Account;
use App\Models\Client;
use App\Models\ClientContact;
use App\Models\Company;
use App\Models\CompanyToken;
use App\Models\User;
use App\Models\Vendor;
2021-07-02 02:06:26 +02:00
/**
* Class MockUnitData.
*/
trait MockUnitData
{
public $account;
public $company;
public $user;
public $client;
public $vendor;
2021-07-02 02:06:26 +02:00
public $faker;
public $primary_contact;
2021-10-11 12:13:11 +02:00
public $token;
2021-07-02 02:06:26 +02:00
public function makeTestData()
{
2024-10-17 23:54:38 +02:00
if (\App\Models\Country::count() == 0) {
\Illuminate\Support\Facades\Artisan::call('db:seed', ['--force' => true]);
}
2021-07-02 02:06:26 +02:00
$this->faker = \Faker\Factory::create();
$this->account = Account::factory()->create();
$this->user = User::factory()->create([
'account_id' => $this->account->id,
2024-10-17 21:58:43 +02:00
'email' => $this->faker->unique()->safeEmail(),
2021-07-02 02:06:26 +02:00
]);
$this->company = Company::factory()->create([
'account_id' => $this->account->id,
2021-07-02 02:06:26 +02:00
]);
2021-10-11 12:13:11 +02:00
$userPermissions = collect([
'view_invoice',
'view_client',
'edit_client',
'edit_invoice',
'create_invoice',
'create_client',
]);
$userSettings = DefaultSettings::userSettings();
$this->user->companies()->attach($this->company->id, [
'account_id' => $this->account->id,
'is_owner' => 1,
'is_admin' => 1,
'notifications' => CompanySettings::notificationDefaults(),
'permissions' => $userPermissions->toJson(),
'settings' => json_encode($userSettings),
'is_locked' => 0,
]);
$this->token = \Illuminate\Support\Str::random(64);
2024-08-22 08:57:52 +02:00
$company_token = new CompanyToken();
2021-10-11 12:13:11 +02:00
$company_token->user_id = $this->user->id;
$company_token->company_id = $this->company->id;
$company_token->account_id = $this->account->id;
$company_token->name = 'test token';
$company_token->token = $this->token;
$company_token->is_system = true;
$company_token->save();
2021-07-02 02:06:26 +02:00
$this->client = Client::factory()->create([
'user_id' => $this->user->id,
'company_id' => $this->company->id,
2021-07-02 02:06:26 +02:00
]);
$this->vendor = Vendor::factory()->create([
'user_id' => $this->user->id,
'company_id' => $this->company->id,
]);
2021-07-02 02:06:26 +02:00
$this->primary_contact = ClientContact::factory()->create([
'user_id' => $this->user->id,
'client_id' => $this->client->id,
'company_id' => $this->company->id,
'is_primary' => 1,
]);
ClientContact::factory()->count(2)->create([
'user_id' => $this->user->id,
'client_id' => $this->client->id,
'company_id' => $this->company->id,
]);
}
2021-10-11 12:13:11 +02:00
public function buildLineItems()
{
$line_items = [];
$item = InvoiceItemFactory::create();
$item->quantity = 1;
$item->cost = 10;
$line_items[] = $item;
return $line_items;
}
}