Skip to content

Commit cf16ce6

Browse files
committed
Add demo blade for testing purpose
1 parent e6f49ed commit cf16ce6

File tree

4 files changed

+72
-16
lines changed

4 files changed

+72
-16
lines changed

src/DocumentViewerServiceProvider.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace AMBERSIVE\DocumentViewer;
44

5+
use App;
6+
57
use Illuminate\Support\ServiceProvider;
68

79
class DocumentViewerServiceProvider extends ServiceProvider
@@ -58,6 +60,10 @@ public function boot()
5860
// Views
5961
$this->loadViewsFrom(__DIR__.'/Views', 'ambersive.documentviewer');
6062

63+
if (App::environment() === 'testing') {
64+
$this->loadViewsFrom(__DIR__.'/../tests/Testfiles', 'ambersive.testing');
65+
}
66+
6167
}
6268

6369
}

tests/Feature/RouteTest.php

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,13 @@ class RouteTest extends TestCase {
1616
protected function setUp(): void
1717
{
1818
parent::setUp();
19-
shell_exec('rm -rf '.resource_path("views/printables"));
20-
shell_exec('rm -rf '.app_path("Printables"));
21-
22-
$this->artisan('make:printable test --force')->assertExitCode(0);
23-
24-
Route::document("test/{id}", "test", \App\Printables\test::class, [], false, \App\Printables\test::class, []);
19+
Route::document("test/{id}", "test", \AMBERSIVE\Tests\Testfiles\Demo::class, [], false, \AMBERSIVE\Tests\Testfiles\Demo::class, []);
2520

2621
}
2722

2823
protected function tearDown(): void
2924
{
3025
parent::tearDown();
31-
shell_exec('rm -rf '.resource_path("views/printables"));
32-
shell_exec('rm -rf '.app_path("Printables"));
3326
}
3427

3528
/**
@@ -40,10 +33,6 @@ public function testIfRouteWillBeRegisteredAndWillReturnTheDocument():void {
4033
$response = $this->get("test/1");
4134
$content = $response->getContent();
4235

43-
if ($response->getStatusCode() !== 200){
44-
dd($content);
45-
}
46-
4736
$response->assertStatus(200);
4837
$this->assertNotFalse(strpos($content, "Create your printable document here."));
4938

@@ -54,12 +43,13 @@ public function testIfRouteWillBeRegisteredAndWillReturnTheDocument():void {
5443
*/
5544
public function testIfRouteWillFailWithServerError():void {
5645

57-
Route::document("test/{id}", "test", \App\Printables\test::class, ["auth"], false, \App\Printables\test::class, []);
46+
Route::document("test/{id}", "test", \AMBERSIVE\Tests\Testfiles\Demo::class, ["auth"], false, \AMBERSIVE\Tests\Testfiles\Demo::class, []);
5847

5948
$response = $this->get("/test/1");
6049
$content = $response->getContent();
6150

6251
$response->assertStatus(500);
52+
6353
$this->assertNotFalse(strpos($content, "Route [login] not defined"));
6454

6555
}
@@ -70,7 +60,7 @@ public function testIfRouteWillFailWithServerError():void {
7060
public function testIfRouteWillFailWillFailWithAnRedirect():void {
7161

7262
Route::get("login", function(){})->name("login");
73-
Route::document("test/{id}", "test", \App\Printables\test::class, ["auth"], false, \App\Printables\test::class, []);
63+
Route::document("test/{id}", "test", \AMBERSIVE\Tests\Testfiles\Demo::class, ["auth"], false, \AMBERSIVE\Tests\Testfiles\Demo::class, []);
7464

7565
$response = $this->get("/test/1");
7666
$response->assertStatus(302);
@@ -82,7 +72,7 @@ public function testIfRouteWillFailWillFailWithAnRedirect():void {
8272
*/
8373
public function testIfRouteSignedWillWorkAndRequestWillFailWithForbidden(): void {
8474

85-
Route::document("test/{id}", "test", \App\Printables\test::class, [], true, \App\Printables\test::class, []);
75+
Route::document("test/{id}", "test", \AMBERSIVE\Tests\Testfiles\Demo::class, [], true, \AMBERSIVE\Tests\Testfiles\Demo::class, []);
8676

8777
$response = $this->get("/test/1");
8878
$response->assertStatus(403);
@@ -94,13 +84,17 @@ public function testIfRouteSignedWillWorkAndRequestWillFailWithForbidden(): void
9484
*/
9585
public function testIfRouteSignedWillWorkAndRequestWillSucceedIfTokenIsPresent(): void {
9686

97-
Route::document("test/{id}", "test", \App\Printables\test::class, [], true, \App\Printables\test::class, []);
87+
Route::document("test/{id}", "test", \AMBERSIVE\Tests\Testfiles\Demo::class, [], true, \AMBERSIVE\Tests\Testfiles\Demo::class, []);
9888

9989
$url = URL::signedRoute('test', ['id' => 1]);
10090

10191
$response = $this->get($url);
10292
$content = $response->getContent();
10393

94+
if ($response->getStatusCode() !== 200){
95+
dd($content);
96+
}
97+
10498
$response->assertStatus(200);
10599
$this->assertNotFalse(strpos($content, "Create your printable document here."));
106100

tests/Testfiles/Demo.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace AMBERSIVE\Tests\Testfiles;
4+
5+
use Illuminate\Http\Request;
6+
7+
use AMBERSIVE\DocumentViewer\Abstracts\DocumentAbstract;
8+
9+
class Demo extends DocumentAbstract
10+
{
11+
12+
public array $data = [];
13+
public String $blade = "ambersive.testing::demo";
14+
public bool $useValidationEndpoint = false;
15+
16+
/**
17+
* Set the data of this printable
18+
*/
19+
public function setData(){
20+
// Request is available in $this->request
21+
// Save stuff in $this->data
22+
return $this;
23+
}
24+
25+
public function uploadDocumentHandler(Request $request) {
26+
27+
// Handle the file upload
28+
// Requires a response (preferable json)
29+
30+
}
31+
32+
public function validateDocumentHandler(Request $request) {
33+
34+
// Handle the validation
35+
return ['status' => 200];
36+
37+
}
38+
39+
}

tests/Testfiles/demo.blade.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@extends('ambersive.documentviewer::printable')
2+
3+
@section('styles')
4+
5+
<style>
6+
body {
7+
background:#efefef;
8+
}
9+
</style>
10+
11+
@endsection
12+
13+
@section('document')
14+
15+
<div>Create your printable document here.</div>
16+
17+
@endsection

0 commit comments

Comments
 (0)