mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-08 20:22:42 +01:00
129 lines
3.3 KiB
PHP
129 lines
3.3 KiB
PHP
<?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
|
|
*/
|
|
|
|
namespace Tests;
|
|
|
|
use App\DataMapper\CompanySettings;
|
|
use App\DataMapper\DefaultSettings;
|
|
use App\Factory\InvoiceItemFactory;
|
|
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;
|
|
|
|
/**
|
|
* Class MockUnitData.
|
|
*/
|
|
trait MockUnitData
|
|
{
|
|
public $account;
|
|
|
|
public $company;
|
|
|
|
public $user;
|
|
|
|
public $client;
|
|
|
|
public $vendor;
|
|
|
|
public $faker;
|
|
|
|
public $primary_contact;
|
|
|
|
public $token;
|
|
|
|
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(),
|
|
]);
|
|
|
|
$this->company = Company::factory()->create([
|
|
'account_id' => $this->account->id,
|
|
]);
|
|
|
|
$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();
|
|
|
|
$this->client = Client::factory()->create([
|
|
'user_id' => $this->user->id,
|
|
'company_id' => $this->company->id,
|
|
]);
|
|
|
|
$this->vendor = Vendor::factory()->create([
|
|
'user_id' => $this->user->id,
|
|
'company_id' => $this->company->id,
|
|
]);
|
|
|
|
$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,
|
|
]);
|
|
}
|
|
|
|
public function buildLineItems()
|
|
{
|
|
$line_items = [];
|
|
|
|
$item = InvoiceItemFactory::create();
|
|
$item->quantity = 1;
|
|
$item->cost = 10;
|
|
$line_items[] = $item;
|
|
|
|
return $line_items;
|
|
}
|
|
}
|