Skip to content
This repository was archived by the owner on Feb 18, 2023. It is now read-only.

Commit 3eb5975

Browse files
author
joselfonseca
committed
final tests
1 parent 0756fa4 commit 3eb5975

File tree

4 files changed

+64
-17
lines changed

4 files changed

+64
-17
lines changed

app/Http/Controllers/Controller.php

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,5 @@
1212
class Controller extends BaseController
1313
{
1414
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
15-
16-
/**
17-
* Create the response for when a request fails validation.
18-
*
19-
* @param \Illuminate\Http\Request $request
20-
* @param array $errors
21-
* @return \Symfony\Component\HttpFoundation\Response
22-
*/
23-
protected function buildFailedValidationResponse(Request $request, array $errors)
24-
{
25-
if ($request->expectsJson()) {
26-
throw new ResourceException('Validation Error', $errors);
27-
}
28-
29-
return redirect()->to($this->getRedirectUrl())->withInput($request->input())->withErrors($errors, $this->errorBag());
30-
}
15+
3116
}

routes/web.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
use Illuminate\Support\Facades\Route;
44

5-
Route::get('/', 'ApiDocsController@index');
5+
Route::get('/', [\App\Http\Controllers\ApiDocsController::class, 'index']);

tests/Feature/ApiDocsTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Tests\Feature;
4+
5+
use Illuminate\Foundation\Testing\RefreshDatabase;
6+
use Illuminate\Foundation\Testing\WithFaker;
7+
use Tests\TestCase;
8+
9+
class ApiDocsTest extends TestCase
10+
{
11+
function test_it_renders_api_docs_page()
12+
{
13+
$this->get('/')
14+
->assertSeeText('The API uses conventional HTTP response codes to indicate the success or failure of an API request. The table below contains a summary of the typical response codes');
15+
}
16+
}

tests/Feature/Assets/RenderFileTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Entities\User;
66
use Illuminate\Foundation\Testing\RefreshDatabase;
7+
use Illuminate\Support\Facades\Storage;
78
use Illuminate\Support\Str;
89
use Laravel\Passport\Passport;
910
use Tests\TestCase;
@@ -38,4 +39,49 @@ function test_it_renders_placeholder_image()
3839
$this->assertTrue($headers->has('Content-Type'));
3940
$this->assertEquals('image/jpeg', $headers->get('Content-Type'));
4041
}
42+
43+
function test_it_renders_placeholder_image_resized_to_width_100()
44+
{
45+
Passport::actingAs(factory(User::class)->create());
46+
$response = $this->get('api/assets/'.Str::uuid().'/render?width=100');
47+
$response->assertStatus(200);
48+
$headers = $response->headers;
49+
$this->assertTrue($headers->has('Content-Type'));
50+
$this->assertEquals('image/jpeg', $headers->get('Content-Type'));
51+
Storage::put('created.jpeg', $response->getContent());
52+
$size = getimagesize(storage_path('app/created.jpeg'));
53+
$this->assertEquals(100, $size[0]);
54+
$this->assertEquals(100, $size[1]);
55+
Storage::delete('created.jpeg');
56+
}
57+
58+
function test_it_renders_placeholder_image_resized_to_height_100()
59+
{
60+
Passport::actingAs(factory(User::class)->create());
61+
$response = $this->get('api/assets/'.Str::uuid().'/render?height=100');
62+
$response->assertStatus(200);
63+
$headers = $response->headers;
64+
$this->assertTrue($headers->has('Content-Type'));
65+
$this->assertEquals('image/jpeg', $headers->get('Content-Type'));
66+
Storage::put('created.jpeg', $response->getContent());
67+
$size = getimagesize(storage_path('app/created.jpeg'));
68+
$this->assertEquals(100, $size[0]);
69+
$this->assertEquals(100, $size[1]);
70+
Storage::delete('created.jpeg');
71+
}
72+
73+
function test_it_renders_placeholder_image_resized_to_width_and_height()
74+
{
75+
Passport::actingAs(factory(User::class)->create());
76+
$response = $this->get('api/assets/'.Str::uuid().'/render?height=100&width=300');
77+
$response->assertStatus(200);
78+
$headers = $response->headers;
79+
$this->assertTrue($headers->has('Content-Type'));
80+
$this->assertEquals('image/jpeg', $headers->get('Content-Type'));
81+
Storage::put('created.jpeg', $response->getContent());
82+
$size = getimagesize(storage_path('app/created.jpeg'));
83+
$this->assertEquals(300, $size[0]);
84+
$this->assertEquals(100, $size[1]);
85+
Storage::delete('created.jpeg');
86+
}
4187
}

0 commit comments

Comments
 (0)