mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
PDF Entity generation tests
This commit is contained in:
parent
8d508bb1f9
commit
0453c989eb
@ -103,18 +103,24 @@ class CreateEntityPdf implements ShouldQueue
|
||||
|
||||
App::setLocale($this->contact->preferredLocale());
|
||||
|
||||
if($this->entity instanceof Invoice)
|
||||
$entity_design_id = '';
|
||||
|
||||
if($this->entity instanceof Invoice){
|
||||
$path = $this->entity->client->invoice_filepath();
|
||||
elseif($this->entity instanceof Quote)
|
||||
$entity_design_id = 'invoice_design_id';
|
||||
}
|
||||
elseif($this->entity instanceof Quote){
|
||||
$path = $this->entity->client->quote_filepath();
|
||||
elseif($this->entity instanceof Credit)
|
||||
$entity_design_id = 'quote_design_id';
|
||||
}
|
||||
elseif($this->entity instanceof Credit){
|
||||
$path = $this->entity->client->credit_filepath();
|
||||
$entity_design_id = 'credit_design_id';
|
||||
}
|
||||
|
||||
$file_path = $path.$this->entity->number.'.pdf';
|
||||
|
||||
info($file_path);
|
||||
|
||||
$entity_design_id = $this->entity->design_id ? $this->entity->design_id : $this->decodePrimaryKey($this->entity->client->getSetting('invoice_design_id'));
|
||||
$entity_design_id = $this->entity->design_id ? $this->entity->design_id : $this->decodePrimaryKey($this->entity->client->getSetting($entity_design_id));
|
||||
|
||||
$design = Design::find($entity_design_id);
|
||||
$html = new HtmlEngine(null, $this->invitation, $this->entity_string);
|
||||
|
@ -109,7 +109,7 @@ trait GeneratesCounter
|
||||
|
||||
$credit_number = $this->checkEntityNumber(Credit::class, $client, $counter, $padding, $pattern);
|
||||
|
||||
$this->incrementCounter($client->company, 'credit_number_counter');
|
||||
$this->incrementCounter($counter_entity, 'credit_number_counter');
|
||||
|
||||
return $credit_number;
|
||||
}
|
||||
|
37
database/factories/CreditInvitationFactory.php
Normal file
37
database/factories/CreditInvitationFactory.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\CreditInvitation;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class CreditInvitationFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = CreditInvitation::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'key' => Str::random(40),
|
||||
];
|
||||
}
|
||||
}
|
63
tests/Feature/PdfCreatorTest.php
Normal file
63
tests/Feature/PdfCreatorTest.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Jobs\Entity\CreateEntityPdf;
|
||||
use Faker\Factory;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Routing\Middleware\ThrottleRequests;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Tests\MockAccountData;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
class PdfCreatorTest extends TestCase
|
||||
{
|
||||
|
||||
use DatabaseTransactions;
|
||||
use MockAccountData;
|
||||
|
||||
public function setUp() :void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->makeTestData();
|
||||
|
||||
$this->withoutMiddleware(
|
||||
ThrottleRequests::class
|
||||
);
|
||||
}
|
||||
|
||||
public function testCreditPdfCreated()
|
||||
{
|
||||
$credit_path = CreateEntityPdf::dispatchNow($this->credit->invitations->first());
|
||||
|
||||
$this->assertTrue(Storage::exists($this->client->credit_filepath().$this->credit->number.'.pdf'));
|
||||
}
|
||||
|
||||
public function testInvoicePdfCreated()
|
||||
{
|
||||
$invoice_path = CreateEntityPdf::dispatchNow($this->invoice->invitations->first());
|
||||
|
||||
$this->assertTrue(Storage::exists($this->client->invoice_filepath().$this->invoice->number.'.pdf'));
|
||||
}
|
||||
|
||||
public function testQuotePdfCreated()
|
||||
{
|
||||
$quote_path = CreateEntityPdf::dispatchNow($this->quote->invitations->first());
|
||||
|
||||
$this->assertTrue(Storage::exists($this->client->quote_filepath().$this->quote->number.'.pdf'));
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -31,6 +31,7 @@ use App\Models\Company;
|
||||
use App\Models\CompanyGateway;
|
||||
use App\Models\CompanyToken;
|
||||
use App\Models\Credit;
|
||||
use App\Models\CreditInvitation;
|
||||
use App\Models\Expense;
|
||||
use App\Models\ExpenseCategory;
|
||||
use App\Models\GroupSetting;
|
||||
@ -350,19 +351,45 @@ trait MockAccountData
|
||||
$this->credit->tax_rate3 = 0;
|
||||
|
||||
$this->credit->uses_inclusive_taxes = false;
|
||||
|
||||
$this->credit->save();
|
||||
$this->credit->service()->createInvitations()->markSent();
|
||||
|
||||
|
||||
$this->credit_calc = new InvoiceSum($this->credit);
|
||||
$this->credit_calc->build();
|
||||
|
||||
$this->credit = $this->credit_calc->getCredit();
|
||||
$this->credit->service()->markSent();
|
||||
|
||||
$this->client->service()->adjustCreditBalance($this->credit->balance)->save();
|
||||
$this->credit->ledger()->updateCreditBalance($this->credit->balance)->save();
|
||||
|
||||
$this->credit->number = $this->getNextCreditNumber($this->client);
|
||||
|
||||
|
||||
CreditInvitation::factory()->create([
|
||||
'user_id' => $this->user->id,
|
||||
'company_id' => $this->company->id,
|
||||
'client_contact_id' => $contact->id,
|
||||
'credit_id' => $this->credit->id,
|
||||
]);
|
||||
|
||||
CreditInvitation::factory()->create([
|
||||
'user_id' => $this->user->id,
|
||||
'company_id' => $this->company->id,
|
||||
'client_contact_id' => $contact2->id,
|
||||
'credit_id' => $this->credit->id,
|
||||
]);
|
||||
|
||||
$invitations = CreditInvitation::whereCompanyId($this->credit->company_id)
|
||||
->whereCreditId($this->credit->id);
|
||||
|
||||
$this->credit->setRelation('invitations', $invitations);
|
||||
|
||||
$this->credit->service()->markSent();
|
||||
|
||||
$this->credit->setRelation('client', $this->client);
|
||||
$this->credit->setRelation('company', $this->company);
|
||||
|
||||
$this->credit->save();
|
||||
|
||||
$contacts = $this->invoice->client->contacts;
|
||||
|
||||
$contacts->each(function ($contact) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user