makeTestData(); $this->fake_email = $this->faker->email(); } public function testMaxInvoiceFields() { $settings = CompanySettings::defaults(); $settings->pdf_variables = json_decode($this->max_pdf_variables); $settings->company_logo = 'https://pdf.invoicing.co/favicon-v2.png'; $settings->website = 'www.invoiceninja.com'; $settings->name = 'Invoice Ninja'; $settings->address1 = 'Address 1'; $settings->address2 = 'Address 2'; $settings->city = 'City'; $settings->state = 'State'; $settings->postal_code = 'Postal Code'; $settings->phone = '555-343-2323'; $settings->email = $this->fake_email; $settings->country_id = '840'; $settings->vat_number = 'vat number'; $settings->id_number = 'id number'; $settings->use_credits_payment = 'always'; $settings->timezone_id = '1'; $settings->entity_send_time = 0; $company = Company::factory()->create([ 'account_id' => $this->account->id, 'settings' => $settings ]); $client = Client::factory()->create([ 'user_id' => $this->user->id, 'company_id' => $company->id ]); $contact = ClientContact::factory()->create([ 'user_id' => $this->user->id, 'company_id' => $company->id, 'client_id' => $client->id, 'is_primary' => true, 'first_name' => 'John', 'last_name' => 'Doe', 'email' => 'john@doe.com', 'phone' => '1234567890', 'send_email' => true, ]); $invoice = Invoice::factory()->create([ 'user_id' => $this->user->id, 'company_id' => $company->id, 'client_id' => $client->id, 'status_id' => Invoice::STATUS_DRAFT, ]); $invoice = $invoice->calc()->getInvoice(); $invoice = $invoice->service()->createInvitations()->markSent()->save(); $invoice = $invoice->fresh(); $this->assertGreaterThan(0, $invoice->invitations()->count()); \App\Models\Design::where('is_custom', false)->cursor()->each(function ($design) use($invoice) { $invoice->design_id = $design->id; $invoice->save(); $invoice = $invoice->fresh(); $service = (new PdfService($invoice->invitations()->first()))->boot(); $pdf = $service->getPdf(); $this->assertNotNull($pdf); \Illuminate\Support\Facades\Storage::put('/pdf/max_fields_' . $design->name.'.pdf', $pdf); }); } public function testMinInvoiceFields() { $settings = CompanySettings::defaults(); $settings->pdf_variables = json_decode($this->min_pdf_variables); $settings->company_logo = 'https://pdf.invoicing.co/favicon-v2.png'; $settings->website = 'www.invoiceninja.com'; $settings->name = 'Invoice Ninja'; $settings->address1 = 'Address 1'; $settings->address2 = 'Address 2'; $settings->city = 'City'; $settings->state = 'State'; $settings->postal_code = 'Postal Code'; $settings->phone = '555-343-2323'; $settings->email = $this->fake_email; $settings->country_id = '840'; $settings->vat_number = 'vat number'; $settings->id_number = 'id number'; $settings->use_credits_payment = 'always'; $settings->timezone_id = '1'; $settings->entity_send_time = 0; $company = Company::factory()->create([ 'account_id' => $this->account->id, 'settings' => $settings ]); $client = Client::factory()->create([ 'user_id' => $this->user->id, 'company_id' => $company->id ]); $contact = ClientContact::factory()->create([ 'user_id' => $this->user->id, 'company_id' => $company->id, 'client_id' => $client->id, 'is_primary' => true, 'first_name' => 'John', 'last_name' => 'Doe', 'email' => 'john@doe.com', 'phone' => '1234567890', 'send_email' => true, ]); $invoice = Invoice::factory()->create([ 'user_id' => $this->user->id, 'company_id' => $company->id, 'client_id' => $client->id, 'status_id' => Invoice::STATUS_DRAFT, ]); $invoice = $invoice->calc()->getInvoice(); $invoice = $invoice->service()->createInvitations()->markSent()->save(); \App\Models\Design::where('is_custom', false)->cursor()->each(function ($design) use ($invoice) { $invoice->design_id = $design->id; $invoice->save(); $invoice = $invoice->fresh(); $service = (new PdfService($invoice->invitations->first()))->boot(); $pdf = $service->getPdf(); $this->assertNotNull($pdf); \Illuminate\Support\Facades\Storage::put('/pdf/min_fields_' . $design->name.'.pdf', $pdf); }); } public function testStatementPdfGeneration() { $pdf = $this->client->service()->statement([ 'client_id' => $this->client->hashed_id, 'start_date' => '2000-01-01', 'end_date' => '2023-01-01', 'show_aging_table' => true, 'show_payments_table' => true, 'status' => 'all' ]); $this->assertNotNull($pdf); \Illuminate\Support\Facades\Storage::put('/pdf/statement.pdf', $pdf); } public function testMultiDesignGeneration() { if (config('ninja.testvars.travis')) { $this->markTestSkipped(); } \App\Models\Design::where('is_custom',false)->cursor()->each(function ($design){ $this->invoice->design_id = $design->id; $this->invoice->save(); $this->invoice = $this->invoice->fresh(); $invitation = $this->invoice->invitations->first(); $service = (new PdfService($invitation))->boot(); $pdf = $service->getPdf(); $this->assertNotNull($pdf); \Illuminate\Support\Facades\Storage::put('/pdf/' . $design->name.'.pdf', $pdf); }); \App\Models\Design::where('is_custom', false)->cursor()->each(function ($design) { $this->invoice->design_id = $design->id; $this->invoice->save(); $this->invoice = $this->invoice->fresh(); $invitation = $this->invoice->invitations->first(); $service = (new PdfService($invitation, 'delivery_note'))->boot(); $pdf = $service->getPdf(); $this->assertNotNull($pdf); \Illuminate\Support\Facades\Storage::put('/pdf/dn_' . $design->name.'.pdf', $pdf); }); } public function testPdfGeneration() { if(config('ninja.testvars.travis')) { $this->markTestSkipped(); } $invitation = $this->invoice->invitations->first(); $service = (new PdfService($invitation))->boot(); $this->assertNotNull($service->getPdf()); } public function testHtmlGeneration() { $invitation = $this->invoice->invitations->first(); $service = (new PdfService($invitation))->boot(); $this->assertIsString($service->getHtml()); } public function testInitOfClass() { $invitation = $this->invoice->invitations->first(); $service = (new PdfService($invitation))->boot(); $this->assertInstanceOf(PdfService::class, $service); } public function testEntityResolution() { $invitation = $this->invoice->invitations->first(); $service = (new PdfService($invitation))->boot(); $this->assertInstanceOf(PdfConfiguration::class, $service->config); } public function testDefaultDesign() { $invitation = $this->invoice->invitations->first(); $service = (new PdfService($invitation))->boot(); $this->assertEquals(2, $service->config->design->id); } public function testHtmlIsArray() { $invitation = $this->invoice->invitations->first(); $service = (new PdfService($invitation))->boot(); $this->assertIsArray($service->html_variables); } public function testTemplateResolution() { $invitation = $this->invoice->invitations->first(); $service = (new PdfService($invitation))->boot(); $this->assertIsString($service->designer->template); } }