2020-12-26 10:26:19 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2021-01-03 22:54:54 +01:00
|
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-12-26 10:26:19 +01:00
|
|
|
*
|
|
|
|
* @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()
|
|
|
|
{
|
2021-01-04 13:38:00 +01:00
|
|
|
$data = $this->getData();
|
2020-12-26 10:26:19 +01:00
|
|
|
|
2021-01-04 13:38:00 +01:00
|
|
|
$response = $this->withHeaders([
|
2020-12-26 10:26:19 +01:00
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->post('/api/v1/preview/', $data);
|
|
|
|
|
2021-01-04 13:38:00 +01:00
|
|
|
$response->assertStatus(200);
|
2020-12-26 10:26:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testPreviewHtmlResponse()
|
|
|
|
{
|
2021-01-04 13:38:00 +01:00
|
|
|
$data = $this->getData();
|
2020-12-26 10:26:19 +01:00
|
|
|
|
2021-01-04 13:38:00 +01:00
|
|
|
$response = $this->withHeaders([
|
2020-12-26 10:26:19 +01:00
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->post('/api/v1/preview?html=true', $data);
|
|
|
|
|
2021-01-04 13:38:00 +01:00
|
|
|
$response->assertStatus(200);
|
2020-12-26 10:26:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private function getData()
|
|
|
|
{
|
2021-01-04 13:38:00 +01:00
|
|
|
$data =
|
|
|
|
[
|
|
|
|
'entity_type' => 'invoice',
|
|
|
|
'entity_id' => '',
|
|
|
|
'design' => [
|
|
|
|
'name' => '',
|
|
|
|
'design' => [
|
2020-12-26 10:26:19 +01:00
|
|
|
'includes' => '</style>',
|
|
|
|
'header' => '<div id="header"></div>',
|
|
|
|
'body' => '<div id="body">',
|
|
|
|
'product' => '',
|
|
|
|
'task' => '',
|
|
|
|
'footer' => '<div id="footer">$entity_footer</div>'
|
2021-01-04 13:38:00 +01:00
|
|
|
],
|
|
|
|
],
|
2020-12-26 10:26:19 +01:00
|
|
|
'is_custom' => 1,
|
|
|
|
];
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
2021-01-04 13:38:00 +01:00
|
|
|
}
|