1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-13 22:54:25 +01:00
invoiceninja/tests/MockUnitData.php

129 lines
3.3 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()
{
$this->faker = \Faker\Factory::create();
$this->account = Account::factory()->create();
$this->user = User::factory()->create([
'account_id' => $this->account->id,
'email' => $this->faker->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);
$company_token = new CompanyToken;
$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;
}
}