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

Commit d1abbd0

Browse files
authored
Merge pull request #72 from joselfonseca/feature/testing-coverage-2
Feature - testing coverage 2
2 parents c41c464 + db18b0e commit d1abbd0

File tree

4 files changed

+104
-19
lines changed

4 files changed

+104
-19
lines changed

app/Http/Controllers/Controller.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,12 @@
22

33
namespace App\Http\Controllers;
44

5-
use Dingo\Api\Exception\ResourceException;
65
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
76
use Illuminate\Foundation\Bus\DispatchesJobs;
87
use Illuminate\Foundation\Validation\ValidatesRequests;
9-
use Illuminate\Http\Request;
108
use Illuminate\Routing\Controller as BaseController;
119

1210
class Controller extends BaseController
1311
{
1412
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-
}
3113
}

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+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
3+
namespace Tests\Feature\Assets;
4+
5+
use App\Entities\User;
6+
use Illuminate\Foundation\Testing\RefreshDatabase;
7+
use Illuminate\Support\Facades\Storage;
8+
use Illuminate\Support\Str;
9+
use Laravel\Passport\Passport;
10+
use Tests\TestCase;
11+
12+
class RenderFileTest extends TestCase
13+
{
14+
use RefreshDatabase;
15+
16+
function test_it_renders_image()
17+
{
18+
$file = base64_encode(file_get_contents(base_path('tests/Resources/pic.png')));
19+
Passport::actingAs(factory(User::class)->create());
20+
$server = $this->transformHeadersToServerVars([
21+
'Content-Type' => 'image/png',
22+
'Content-Length' => mb_strlen($file)
23+
]);
24+
$response = $this->call('POST', 'api/assets', [], [], [], $server, $file);
25+
$asset = json_decode($response->getContent());
26+
$response = $this->get('api/assets/'.$asset->data->id.'/render');
27+
$response->assertStatus(200);
28+
$headers = $response->headers;
29+
$this->assertTrue($headers->has('Content-Type'));
30+
$this->assertEquals('image/png', $headers->get('Content-Type'));
31+
}
32+
33+
function test_it_renders_placeholder_image()
34+
{
35+
Passport::actingAs(factory(User::class)->create());
36+
$response = $this->get('api/assets/'.Str::uuid().'/render');
37+
$response->assertStatus(200);
38+
$headers = $response->headers;
39+
$this->assertTrue($headers->has('Content-Type'));
40+
$this->assertEquals('image/jpeg', $headers->get('Content-Type'));
41+
}
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+
}
87+
}

0 commit comments

Comments
 (0)