mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Allow custom designs to be passed into the live designer
This commit is contained in:
parent
19e2e98665
commit
da92505de1
@ -47,6 +47,7 @@ class DesignPreviewRequest extends Request
|
||||
'settings' => 'sometimes',
|
||||
'group_id' => 'sometimes',
|
||||
'client_id' => 'sometimes',
|
||||
'design' => 'bail|sometimes|array'
|
||||
];
|
||||
|
||||
return $rules;
|
||||
|
@ -47,6 +47,15 @@ class PdfDesigner
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function buildFromPartials(array $partials): self
|
||||
{
|
||||
|
||||
$this->template = $this->composeFromPartials($partials);
|
||||
|
||||
return $this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* If the user has implemented a custom design, then we need to rebuild the design at this point
|
||||
*/
|
||||
@ -54,10 +63,8 @@ class PdfDesigner
|
||||
/**
|
||||
* Returns the custom HTML design as
|
||||
* a string
|
||||
*
|
||||
* @param array
|
||||
* @param array $partials
|
||||
* @return string
|
||||
*
|
||||
*/
|
||||
private function composeFromPartials(array $partials) :string
|
||||
{
|
||||
|
@ -69,7 +69,11 @@ class PdfMock
|
||||
|
||||
$pdf_service->config = $pdf_config;
|
||||
|
||||
$pdf_designer = (new PdfDesigner($pdf_service))->build();
|
||||
if(isset($this->request['design']))
|
||||
$pdf_designer = (new PdfDesigner($pdf_service))->buildFromPartials($this->request['design']);
|
||||
else
|
||||
$pdf_designer = (new PdfDesigner($pdf_service))->build();
|
||||
|
||||
$pdf_service->designer = $pdf_designer;
|
||||
|
||||
$pdf_service->html_variables = $document_type == 'purchase_order' ? $this->getVendorStubVariables() : $this->getStubVariables();
|
||||
|
@ -11,10 +11,11 @@
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Routing\Middleware\ThrottleRequests;
|
||||
use Tests\MockAccountData;
|
||||
use Tests\TestCase;
|
||||
use App\Models\Design;
|
||||
use Tests\MockAccountData;
|
||||
use Illuminate\Routing\Middleware\ThrottleRequests;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
/**
|
||||
* @test
|
||||
@ -55,4 +56,26 @@ class LiveDesignTest extends TestCase
|
||||
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
public function testDesignWithCustomDesign()
|
||||
{
|
||||
|
||||
$d = Design::find(1);
|
||||
|
||||
|
||||
$data = [
|
||||
'entity_type' => 'invoice',
|
||||
'settings_type' => 'company',
|
||||
'settings' => (array)$this->company->settings,
|
||||
'design' => (array)$d->design,
|
||||
];
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/live_design/', $data);
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user