mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 22:04:35 -04:00
Test for HTML output for preview controller
This commit is contained in:
parent
b3962986fb
commit
4129dba08b
@ -125,7 +125,7 @@ class PreviewController extends BaseController
|
|||||||
->design($design)
|
->design($design)
|
||||||
->build();
|
->build();
|
||||||
|
|
||||||
if (request()->query('html') == true) {
|
if (request()->query('html') == 'true') {
|
||||||
return $maker->getCompiledHTML;
|
return $maker->getCompiledHTML;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,6 +209,10 @@ class PreviewController extends BaseController
|
|||||||
->design($design)
|
->design($design)
|
||||||
->build();
|
->build();
|
||||||
|
|
||||||
|
if (request()->query('html') == 'true') {
|
||||||
|
return $maker->getCompiledHTML();
|
||||||
|
}
|
||||||
|
|
||||||
if (config('ninja.phantomjs_pdf_generation')) {
|
if (config('ninja.phantomjs_pdf_generation')) {
|
||||||
return (new Phantom)->convertHtmlToPdf($maker->getCompiledHTML(true));
|
return (new Phantom)->convertHtmlToPdf($maker->getCompiledHTML(true));
|
||||||
}
|
}
|
||||||
|
@ -351,4 +351,4 @@ class CompanyTransformer extends EntityTransformer
|
|||||||
|
|
||||||
return $this->includeCollection($company->system_logs, $transformer, SystemLog::class);
|
return $this->includeCollection($company->system_logs, $transformer, SystemLog::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
86
tests/Feature/PreviewTest.php
Normal file
86
tests/Feature/PreviewTest.php
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
<?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 Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
|
use Illuminate\Routing\Middleware\ThrottleRequests;
|
||||||
|
use Tests\MockAccountData;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @covers App\Http\Controllers\PreviewController
|
||||||
|
*/
|
||||||
|
class PreviewTest extends TestCase
|
||||||
|
{
|
||||||
|
use DatabaseTransactions;
|
||||||
|
use MockAccountData;
|
||||||
|
|
||||||
|
public function setUp() :void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->makeTestData();
|
||||||
|
|
||||||
|
$this->withoutMiddleware(
|
||||||
|
ThrottleRequests::class
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPreviewRoute()
|
||||||
|
{
|
||||||
|
$data = $this->getData();
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->post('/api/v1/preview/', $data);
|
||||||
|
|
||||||
|
$response->assertStatus(200);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPreviewHtmlResponse()
|
||||||
|
{
|
||||||
|
$data = $this->getData();
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->post('/api/v1/preview?html=true', $data);
|
||||||
|
|
||||||
|
$response->assertStatus(200);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private function getData()
|
||||||
|
{
|
||||||
|
$data =
|
||||||
|
[
|
||||||
|
'entity_type' => 'invoice',
|
||||||
|
'entity_id' => '',
|
||||||
|
'design' => [
|
||||||
|
'name' => '',
|
||||||
|
'design' => [
|
||||||
|
'includes' => '</style>',
|
||||||
|
'header' => '<div id="header"></div>',
|
||||||
|
'body' => '<div id="body">',
|
||||||
|
'product' => '',
|
||||||
|
'task' => '',
|
||||||
|
'footer' => '<div id="footer">$entity_footer</div>'
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'is_custom' => 1,
|
||||||
|
];
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user