2020-02-19 21:44:12 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Integration;
|
|
|
|
|
2020-03-11 21:30:49 +01:00
|
|
|
use App\Designs\Bold;
|
|
|
|
use App\Designs\Business;
|
|
|
|
use App\Designs\Clean;
|
2020-02-19 21:44:12 +01:00
|
|
|
use App\Designs\Designer;
|
|
|
|
use App\Designs\Modern;
|
2020-03-04 00:51:50 +01:00
|
|
|
use App\Jobs\Credit\CreateCreditPdf;
|
2020-02-19 21:44:12 +01:00
|
|
|
use App\Jobs\Invoice\CreateInvoicePdf;
|
|
|
|
use App\Jobs\Quote\CreateQuotePdf;
|
2020-03-11 21:30:49 +01:00
|
|
|
use App\Models\ClientContact;
|
2020-03-07 07:31:26 +01:00
|
|
|
use App\Models\Design;
|
2020-02-26 05:11:17 +01:00
|
|
|
use App\Utils\Traits\GeneratesCounter;
|
2020-03-06 23:48:03 +01:00
|
|
|
use App\Utils\Traits\MakesHash;
|
2020-03-11 21:30:49 +01:00
|
|
|
use App\Utils\Traits\MakesInvoiceHtml;
|
|
|
|
use App\Utils\Traits\Pdf\PdfMaker;
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
2020-02-19 21:44:12 +01:00
|
|
|
use Tests\MockAccountData;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @covers App\Designs\Designer
|
|
|
|
*/
|
|
|
|
class DesignTest extends TestCase
|
|
|
|
{
|
2020-03-11 21:30:49 +01:00
|
|
|
use MakesInvoiceHtml;
|
|
|
|
use PdfMaker;
|
2020-02-19 21:44:12 +01:00
|
|
|
use MockAccountData;
|
2020-02-26 05:11:17 +01:00
|
|
|
use GeneratesCounter;
|
2020-03-06 23:48:03 +01:00
|
|
|
use MakesHash;
|
2020-03-11 21:30:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var ClientContact
|
|
|
|
*/
|
|
|
|
private $contact;
|
|
|
|
|
2020-02-19 21:44:12 +01:00
|
|
|
public function setUp() :void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->makeTestData();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testInvoiceDesignExists()
|
|
|
|
{
|
2020-03-11 21:30:49 +01:00
|
|
|
$this->contact = $this->invoice->client->primary_contact()->first();
|
2020-02-19 21:44:12 +01:00
|
|
|
|
2020-03-07 07:31:26 +01:00
|
|
|
$design = Design::find(3);
|
2020-02-19 21:44:12 +01:00
|
|
|
|
2020-03-07 07:31:26 +01:00
|
|
|
$designer = new Designer($this->invoice, $design, $this->company->settings->pdf_variables, 'quote');
|
2020-02-19 21:44:12 +01:00
|
|
|
|
2020-03-05 08:14:57 +01:00
|
|
|
$html = $designer->build()->getHtml();
|
2020-02-19 21:44:12 +01:00
|
|
|
|
|
|
|
$this->assertNotNull($html);
|
|
|
|
|
2020-02-22 03:25:49 +01:00
|
|
|
|
|
|
|
$this->invoice = factory(\App\Models\Invoice::class)->create([
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
'client_id' => $this->client->id,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->invoice->uses_inclusive_taxes = false;
|
2020-02-19 21:44:12 +01:00
|
|
|
|
|
|
|
$settings = $this->invoice->client->settings;
|
2020-03-06 23:48:03 +01:00
|
|
|
$settings->invoice_design_id = "VolejRejNm";
|
2020-02-19 21:44:12 +01:00
|
|
|
|
|
|
|
$this->client->settings = $settings;
|
|
|
|
$this->client->save();
|
|
|
|
|
|
|
|
CreateInvoicePdf::dispatchNow($this->invoice, $this->invoice->company, $this->invoice->client->primary_contact()->first());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testQuoteDesignExists()
|
|
|
|
{
|
2020-03-11 21:30:49 +01:00
|
|
|
$invoice_design = new Clean();
|
|
|
|
$design_object = new \stdClass;
|
|
|
|
$design_object->includes = $invoice_design->includes() ?: '';
|
|
|
|
$design_object->header = $invoice_design->header() ?: '';
|
|
|
|
$design_object->body = $invoice_design->body() ?: '';
|
|
|
|
$design_object->product = $invoice_design->product() ?: '';
|
|
|
|
$design_object->task = $invoice_design->task() ?: '';
|
|
|
|
$design_object->footer = $invoice_design->footer() ?: '';
|
|
|
|
$design = new \stdClass;
|
|
|
|
$design->name = 'Dave Rocks';
|
|
|
|
$design->design = $design_object;
|
|
|
|
$designer = new Designer($this->invoice, $design, $this->company->settings->pdf_variables, 'quote');
|
2020-02-19 21:44:12 +01:00
|
|
|
|
2020-03-05 08:14:57 +01:00
|
|
|
$html = $designer->build()->getHtml();
|
2020-02-19 21:44:12 +01:00
|
|
|
|
|
|
|
$this->assertNotNull($html);
|
|
|
|
|
|
|
|
//\Log::error($html);
|
|
|
|
|
2020-03-11 21:30:49 +01:00
|
|
|
$html = $this->generateEntityHtml($designer, $this->invoice, $this->contact);
|
|
|
|
$pdf = $this->makePdf(null, null, $html);
|
2020-02-19 21:44:12 +01:00
|
|
|
|
2020-03-11 21:30:49 +01:00
|
|
|
$instance = Storage::disk('local')->put('invoice.pdf', $pdf);
|
2020-02-19 21:44:12 +01:00
|
|
|
|
2020-03-11 21:30:49 +01:00
|
|
|
exec('xdg-open ~/Code/invoiceninja/storage/app/invoice.pdf');
|
2020-02-19 21:44:12 +01:00
|
|
|
}
|
2020-02-26 05:11:17 +01:00
|
|
|
|
2020-03-05 08:14:57 +01:00
|
|
|
// public function testQuoteDesignWithRepeatingHeader()
|
|
|
|
// {
|
|
|
|
|
|
|
|
// $modern = new Modern();
|
|
|
|
|
|
|
|
// $designer = new Designer($this->quote, $modern, $this->company->settings->pdf_variables, 'quote');
|
|
|
|
|
|
|
|
// $html = $designer->build()->getHtml();
|
|
|
|
|
|
|
|
// $this->assertNotNull($html);
|
|
|
|
|
|
|
|
// //\Log::error($html);
|
|
|
|
|
|
|
|
// $settings = $this->invoice->client->settings;
|
|
|
|
// $settings->quote_design_id = "4";
|
|
|
|
// $settings->all_pages_header = true;
|
|
|
|
|
|
|
|
// $this->quote->client_id = $this->client->id;
|
|
|
|
// $this->quote->setRelation('client', $this->client);
|
|
|
|
// $this->quote->save();
|
|
|
|
|
|
|
|
// $this->client->settings = $settings;
|
|
|
|
// $this->client->save();
|
|
|
|
|
|
|
|
// CreateQuotePdf::dispatchNow($this->quote, $this->quote->company, $this->quote->client->primary_contact()->first());
|
|
|
|
// }
|
|
|
|
|
|
|
|
// public function testQuoteDesignWithRepeatingFooter()
|
|
|
|
// {
|
|
|
|
|
|
|
|
// $modern = new Modern();
|
|
|
|
|
|
|
|
// $designer = new Designer($this->quote, $modern, $this->company->settings->pdf_variables, 'quote');
|
|
|
|
|
|
|
|
// $html = $designer->build()->getHtml();
|
|
|
|
|
|
|
|
// $this->assertNotNull($html);
|
|
|
|
|
|
|
|
// //\Log::error($html);
|
|
|
|
|
|
|
|
// $settings = $this->invoice->client->settings;
|
|
|
|
// $settings->quote_design_id = "4";
|
|
|
|
// $settings->all_pages_footer = true;
|
|
|
|
|
|
|
|
// $this->quote->client_id = $this->client->id;
|
|
|
|
// $this->quote->setRelation('client', $this->client);
|
|
|
|
// $this->quote->save();
|
|
|
|
|
|
|
|
// $this->client->settings = $settings;
|
|
|
|
// $this->client->save();
|
|
|
|
|
|
|
|
// CreateQuotePdf::dispatchNow($this->quote, $this->quote->company, $this->quote->client->primary_contact()->first());
|
|
|
|
// }
|
|
|
|
|
|
|
|
// public function testQuoteDesignWithRepeatingHeaderAndFooter()
|
|
|
|
// {
|
|
|
|
|
|
|
|
// $modern = new Modern();
|
|
|
|
|
|
|
|
// $designer = new Designer($this->quote, $modern, $this->company->settings->pdf_variables, 'quote');
|
|
|
|
|
|
|
|
// $html = $designer->build()->getHtml();
|
|
|
|
|
|
|
|
// $this->assertNotNull($html);
|
|
|
|
|
|
|
|
// //\Log::error($html);
|
|
|
|
|
|
|
|
// $settings = $this->invoice->client->settings;
|
|
|
|
// $settings->quote_design_id = "4";
|
|
|
|
// $settings->all_pages_header = true;
|
|
|
|
// $settings->all_pages_footer = true;
|
|
|
|
|
|
|
|
// $this->quote->client_id = $this->client->id;
|
|
|
|
// $this->quote->setRelation('client', $this->client);
|
|
|
|
// $this->quote->save();
|
|
|
|
|
|
|
|
// $this->client->settings = $settings;
|
|
|
|
// $this->client->save();
|
|
|
|
|
|
|
|
// CreateQuotePdf::dispatchNow($this->quote, $this->quote->company, $this->quote->client->primary_contact()->first());
|
|
|
|
// }
|
|
|
|
|
2020-03-04 00:51:50 +01:00
|
|
|
public function testCreditDesignExists()
|
|
|
|
{
|
|
|
|
|
2020-03-07 07:31:26 +01:00
|
|
|
$design = Design::find(3);
|
2020-03-04 00:51:50 +01:00
|
|
|
|
2020-03-07 07:31:26 +01:00
|
|
|
$designer = new Designer($this->credit, $design, $this->company->settings->pdf_variables, 'credit');
|
2020-03-04 00:51:50 +01:00
|
|
|
|
2020-03-05 08:14:57 +01:00
|
|
|
$html = $designer->build()->getHtml();
|
2020-03-04 00:51:50 +01:00
|
|
|
|
|
|
|
$this->assertNotNull($html);
|
|
|
|
|
|
|
|
$settings = $this->invoice->client->settings;
|
2020-03-05 08:14:57 +01:00
|
|
|
$settings->quote_design_id = "4";
|
2020-03-04 00:51:50 +01:00
|
|
|
|
|
|
|
$this->credit->client_id = $this->client->id;
|
|
|
|
$this->credit->setRelation('client', $this->client);
|
|
|
|
$this->credit->save();
|
2020-03-11 21:30:49 +01:00
|
|
|
|
2020-03-04 00:51:50 +01:00
|
|
|
$this->client->settings = $settings;
|
|
|
|
$this->client->save();
|
|
|
|
|
|
|
|
CreateCreditPdf::dispatchNow($this->credit, $this->credit->company, $this->credit->client->primary_contact()->first());
|
|
|
|
}
|
|
|
|
|
2020-03-06 23:48:03 +01:00
|
|
|
public function testAllDesigns()
|
|
|
|
{
|
2020-02-26 05:11:17 +01:00
|
|
|
|
2020-03-06 23:48:03 +01:00
|
|
|
for($x=1; $x<=10; $x++)
|
|
|
|
{
|
2020-02-26 05:11:17 +01:00
|
|
|
|
2020-03-06 23:48:03 +01:00
|
|
|
$settings = $this->invoice->client->settings;
|
|
|
|
$settings->quote_design_id = (string)$this->encodePrimaryKey($x);
|
2020-03-11 21:30:49 +01:00
|
|
|
|
2020-03-06 23:48:03 +01:00
|
|
|
$this->quote->client_id = $this->client->id;
|
|
|
|
$this->quote->setRelation('client', $this->client);
|
|
|
|
$this->quote->save();
|
2020-02-26 05:11:17 +01:00
|
|
|
|
2020-03-06 23:48:03 +01:00
|
|
|
$this->client->settings = $settings;
|
|
|
|
$this->client->save();
|
2020-02-26 05:11:17 +01:00
|
|
|
|
2020-03-06 23:48:03 +01:00
|
|
|
CreateQuotePdf::dispatchNow($this->quote, $this->quote->company, $this->quote->client->primary_contact()->first());
|
2020-02-26 05:11:17 +01:00
|
|
|
|
2020-03-06 23:48:03 +01:00
|
|
|
$this->quote->number = $this->getNextQuoteNumber($this->quote->client);
|
|
|
|
$this->quote->save();
|
2020-02-26 05:11:17 +01:00
|
|
|
|
2020-03-06 23:48:03 +01:00
|
|
|
}
|
2020-02-26 05:11:17 +01:00
|
|
|
|
2020-03-06 23:48:03 +01:00
|
|
|
$this->assertTrue(true);
|
2020-02-26 05:11:17 +01:00
|
|
|
|
2020-03-06 23:48:03 +01:00
|
|
|
}
|
2020-03-11 21:30:49 +01:00
|
|
|
|
2020-02-19 21:44:12 +01:00
|
|
|
}
|
|
|
|
|