mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-09 20:52:56 +01:00
Add files
This commit is contained in:
parent
cfb20182fb
commit
78fe4c0b80
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('designs', function (Blueprint $table) {
|
||||
$table->boolean('is_template')->default(false);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
}
|
||||
};
|
112
tests/Feature/Template/TemplateTest.php
Normal file
112
tests/Feature/Template/TemplateTest.php
Normal file
@ -0,0 +1,112 @@
|
||||
<?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\Feature\Template;
|
||||
|
||||
use App\Models\Design;
|
||||
use Tests\TestCase;
|
||||
use App\Utils\Ninja;
|
||||
use App\Utils\HtmlEngine;
|
||||
use Tests\MockAccountData;
|
||||
use App\Services\PdfMaker\PdfMaker;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Routing\Middleware\ThrottleRequests;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use App\Services\PdfMaker\Design as PdfDesignModel;
|
||||
use App\Services\PdfMaker\Design as PdfMakerDesign;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @covers
|
||||
*/
|
||||
class TemplateTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
use MockAccountData;
|
||||
|
||||
protected function setUp() :void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->makeTestData();
|
||||
|
||||
$this->withoutMiddleware(
|
||||
ThrottleRequests::class
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public function testTemplateGeneration()
|
||||
{
|
||||
$entity_obj = $this->invoice;
|
||||
|
||||
$design = new Design();
|
||||
$design->design = json_decode(json_encode($this->invoice->company->settings->pdf_variables), true);
|
||||
$design->name = 'test';
|
||||
$design->is_active = true;
|
||||
$design->is_template = true;
|
||||
$design->is_custom = true;
|
||||
$design->user_id = $this->invoice->user_id;
|
||||
$design->company_id = $this->invoice->company_id;
|
||||
|
||||
$design_object = new \stdClass;
|
||||
$design_object->includes = '';
|
||||
$design_object->header = '';
|
||||
$design_object->body = '';
|
||||
$design_object->product = '';
|
||||
$design_object->task = '';
|
||||
$design_object->footer = '';
|
||||
|
||||
$design->design = $design_object;
|
||||
|
||||
$design->save();
|
||||
|
||||
App::forgetInstance('translator');
|
||||
$t = app('translator');
|
||||
App::setLocale($entity_obj->client->locale());
|
||||
$t->replace(Ninja::transformTranslations($entity_obj->client->getMergedSettings()));
|
||||
|
||||
$html = new HtmlEngine($entity_obj->invitations()->first());
|
||||
|
||||
/** @var \App\Models\Design $design */
|
||||
$design = \App\Models\Design::withTrashed()->find($entity_obj->design_id);
|
||||
|
||||
$options = [
|
||||
'custom_partials' => json_decode(json_encode($design->design), true),
|
||||
];
|
||||
$template = new PdfMakerDesign(PdfDesignModel::CUSTOM, $options);
|
||||
|
||||
$variables = $html->generateLabelsAndValues();
|
||||
|
||||
$state = [
|
||||
'template' => $template->elements([
|
||||
'client' => $entity_obj->client,
|
||||
'entity' => $entity_obj,
|
||||
'pdf_variables' => (array) $entity_obj->company->settings->pdf_variables,
|
||||
'$product' => $design->design->product,
|
||||
'variables' => $variables,
|
||||
]),
|
||||
'variables' => $variables,
|
||||
'options' => [
|
||||
'all_pages_header' => $entity_obj->client->getSetting('all_pages_header'),
|
||||
'all_pages_footer' => $entity_obj->client->getSetting('all_pages_footer'),
|
||||
'client' => $entity_obj->client,
|
||||
'entity' => $entity_obj,
|
||||
'variables' => $variables,
|
||||
],
|
||||
'process_markdown' => $entity_obj->client->company->markdown_enabled,
|
||||
];
|
||||
|
||||
$maker = new PdfMaker($state);
|
||||
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user