Skip to content

Commit 1c59dae

Browse files
incluindo testes
1 parent e0ef3ba commit 1c59dae

15 files changed

+103
-458
lines changed

app/Http/Controllers/ContentController.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Http\Controllers;
44

55
use App\Services\Color;
6+
use App\Services\CssVariablesParser;
67
use Illuminate\Http\Request;
78
use Illuminate\Support\Facades\Storage;
89
use ParsedownExtra;
@@ -51,19 +52,12 @@ public function generatePdf(Request $request){
5152

5253
$rawCss = Storage::disk('public')->get('pdf.css');
5354

54-
$parsedCss = $this->parseCssVariables($rawCss, $cssVariables);
55+
$parsedCss = CssVariablesParser::parseAllFromArray($rawCss, $cssVariables);
5556

5657
$css = '<style>'. $parsedCss .'</style>';
5758

5859
$mpdf = new \Mpdf\Mpdf();
5960
$mpdf->WriteHTML($css.$htmlText);
6061
$mpdf->Output($filename, \Mpdf\Output\Destination::DOWNLOAD);
6162
}
62-
63-
private function parseCssVariables($cssCode, $cssColors){
64-
foreach($cssColors as $key => $value){
65-
$cssCode = str_replace("var($key)", $value, $cssCode);
66-
}
67-
return $cssCode;
68-
}
6963
}

app/Services/Color.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function generateDarkerColors($colors_array, $amount){
2727
}
2828

2929
}
30+
ksort($colors_array);
3031
return $colors_array;
3132
}
3233

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace App\Services;
4+
5+
class CssVariablesParser {
6+
7+
public static function parseAllFromArray(String $css, array $variables_array){
8+
foreach($variables_array as $key => $value){
9+
$css = str_replace("var($key)", $value, $css);
10+
}
11+
return $css;
12+
}
13+
}

phpunit.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
colors="true"
66
>
77
<testsuites>
8-
<testsuite name="Unit">
9-
<directory>tests/Unit</directory>
10-
</testsuite>
11-
<testsuite name="Feature">
12-
<directory>tests/Feature</directory>
8+
<testsuite name="Tests">
9+
<directory>tests</directory>
1310
</testsuite>
11+
<!-- <testsuite name="Color">
12+
<directory>tests/Color</directory>
13+
</testsuite> -->
1414
</testsuites>
1515
<source>
1616
<include>

tests/Color/ColorTest.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace Tests\Color;
4+
5+
use App\Services\Color;
6+
use Tests\TestCase;
7+
8+
class ColorTest extends TestCase {
9+
private $color_service;
10+
11+
public function setup():void {
12+
$this->color_service = new Color();
13+
}
14+
15+
public function test_if_generates_darker_colors(){
16+
$cssColors = [
17+
'--hexColor' => '#e5e5e5',
18+
'--rgbColor' => 'rgb(16, 185, 129)',
19+
'--hslColor' => 'hsl(0, 0%, 100%)',
20+
'--darkColor' => 'hsl(0, 0%, 0%)',
21+
];
22+
$expectedColors = [
23+
'--darkColor' => 'hsl(0,0%,0%)',
24+
'--darkColor0' => 'hsl(0,0%,0%)',
25+
'--darkColor1' => 'hsl(0,0%,0%)',
26+
'--hexColor' => 'hsl(0,0%,90%)',
27+
'--hexColor0' => 'hsl(0,0%,80%)',
28+
'--hexColor1' => 'hsl(0,0%,70%)',
29+
'--hslColor' => 'hsl(0,0%,100%)',
30+
'--hslColor0' => 'hsl(0,0%,90%)',
31+
'--hslColor1' => 'hsl(0,0%,80%)',
32+
'--rgbColor' => 'hsl(160,84%,39%)',
33+
'--rgbColor0' => 'hsl(160,84%,29%)',
34+
'--rgbColor1' => 'hsl(160,84%,19%)',
35+
];
36+
37+
$return = $this->color_service->generateDarkerColors($cssColors, 2);
38+
39+
$this->assertEquals($expectedColors, $return);
40+
}
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace Tests\CssVariablesParser;
4+
5+
use App\Services\CssVariablesParser;
6+
use Tests\TestCase;
7+
8+
class CssVariablesParserTest extends TestCase {
9+
public function test_css_variables_parser(){
10+
$css =
11+
'#id-test {
12+
background-color: var(--backgroundColor);
13+
}
14+
15+
.class-test {
16+
color: var(--textColor);
17+
text-wrap: wrap;
18+
overflow-wrap: break-word;
19+
}
20+
';
21+
$variables = [
22+
'--backgroundColor' => '#FFFFFF',
23+
'--textColor' => '#000000',
24+
];
25+
$expected =
26+
'#id-test {
27+
background-color: #FFFFFF;
28+
}
29+
30+
.class-test {
31+
color: #000000;
32+
text-wrap: wrap;
33+
overflow-wrap: break-word;
34+
}
35+
';
36+
37+
$return = CssVariablesParser::parseAllFromArray($css, $variables);
38+
39+
$this->assertEquals($expected, $return);
40+
}
41+
}

tests/Feature/Auth/AuthenticationTest.php

Lines changed: 0 additions & 54 deletions
This file was deleted.

tests/Feature/Auth/EmailVerificationTest.php

Lines changed: 0 additions & 58 deletions
This file was deleted.

tests/Feature/Auth/PasswordConfirmationTest.php

Lines changed: 0 additions & 44 deletions
This file was deleted.

tests/Feature/Auth/PasswordResetTest.php

Lines changed: 0 additions & 73 deletions
This file was deleted.

0 commit comments

Comments
 (0)