Skip to content

Commit 5339b77

Browse files
committed
added tests
1 parent 21d204a commit 5339b77

File tree

13 files changed

+346
-22
lines changed

13 files changed

+346
-22
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"license": "MIT",
55
"autoload": {
66
"psr-4": {
7-
"AmirHossein5\\LaravelComponents\\": "src/"
7+
"AmirHossein5\\LaravelComponents\\": "src/",
8+
"AmirHossein5\\LaravelComponents\\Tests\\": "tests/"
89
}
910
},
1011
"authors": [

phpunit.xml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
bootstrap="vendor/autoload.php"
5+
backupGlobals="false"
6+
backupStaticAttributes="false"
7+
colors="true"
8+
verbose="true"
9+
convertErrorsToExceptions="true"
10+
convertNoticesToExceptions="true"
11+
convertWarningsToExceptions="true"
12+
processIsolation="false"
13+
stopOnFailure="false"
14+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
15+
>
16+
<coverage>
17+
<include>
18+
<directory suffix=".php">src/</directory>
19+
</include>
20+
</coverage>
21+
<testsuites>
22+
<testsuite name="Unit">
23+
<directory suffix="Test.php">./tests/Unit</directory>
24+
</testsuite>
25+
<testsuite name="Feature">
26+
<directory suffix="Test.php">./tests/Feature</directory>
27+
</testsuite>
28+
</testsuites>
29+
<php>
30+
<env name="DB_CONNECTION" value="testing"/>
31+
<env name="APP_KEY" value="base64:2fl+Ktvkfl+Fuz4Qp/A75G2RTiWVA/ZoKZvp6fiiM10="/>
32+
</php>
33+
</phpunit>

resources/views/pagination/gray-circled/tailwind.blade.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
@if ($paginator->onFirstPage())
4444
@if ($showDisabledButtons)
4545
<span aria-disabled="true" aria-label="{{ __('pagination.previous') }}">
46-
<span class="relative inline-flex items-center px-2 py-2 text-sm font-medium leading-5 text-gray-500 bg-white border border-gray-300 cursor-default rounded-l-md" aria-hidden="true">
46+
<span class="relative inline-flex items-center px-2 py-2 text-sm font-medium leading-5 text-gray-500 bg-white border border-gray-300 cursor-default first-button rounded-l-md" aria-hidden="true">
4747
@if($prev)
4848
{!! $prev !!}
4949
@else
@@ -55,7 +55,7 @@
5555
</span>
5656
@endif
5757
@else
58-
<a href="{{ $paginator->previousPageUrl() }}" rel="prev" class="relative inline-flex items-center px-2 py-2 text-sm font-medium leading-5 text-gray-500 transition duration-150 ease-in-out bg-white border border-gray-300 rounded-l-md hover:text-gray-400 focus:z-10 focus:outline-none focus:ring ring-gray-300 focus:border-blue-300 active:bg-gray-100 active:text-gray-500" aria-label="{{ __('pagination.previous') }}">
58+
<a href="{{ $paginator->previousPageUrl() }}" rel="prev" class="relative inline-flex items-center px-2 py-2 text-sm font-medium leading-5 text-gray-500 transition duration-150 ease-in-out bg-white border border-gray-300 first-button rounded-l-md hover:text-gray-400 focus:z-10 focus:outline-none focus:ring ring-gray-300 focus:border-blue-300 active:bg-gray-100 active:text-gray-500" aria-label="{{ __('pagination.previous') }}">
5959
@if($prev)
6060
{!! $prev !!}
6161
@else
@@ -96,7 +96,7 @@
9696

9797
{{-- Next Page Link --}}
9898
@if ($paginator->hasMorePages())
99-
<a href="{{ $paginator->nextPageUrl() }}" rel="next" class="relative inline-flex items-center px-2 py-2 -ml-px text-sm font-medium leading-5 text-gray-500 transition duration-150 ease-in-out bg-white border border-gray-300 rounded-r-md hover:text-gray-400 focus:z-10 focus:outline-none focus:ring ring-gray-300 focus:border-blue-300 active:bg-gray-100 active:text-gray-500" aria-label="{{ __('pagination.next') }}">
99+
<a href="{{ $paginator->nextPageUrl() }}" rel="next" class="relative inline-flex items-center px-2 py-2 -ml-px text-sm font-medium leading-5 text-gray-500 transition duration-150 ease-in-out bg-white border border-gray-300 rounded-r-md hover:text-gray-400 focus:z-10 focus:outline-none focus:ring ring-gray-300 focus:border-blue-300 last-button active:bg-gray-100 active:text-gray-500" aria-label="{{ __('pagination.next') }}">
100100
@if($next)
101101
{!! $next !!}
102102
@else
@@ -108,7 +108,7 @@
108108
@else
109109
@if ($showDisabledButtons)
110110
<span aria-disabled="true" aria-label="{{ __('pagination.next') }}">
111-
<span class="relative inline-flex items-center px-2 py-2 -ml-px text-sm font-medium leading-5 text-gray-500 bg-white border border-gray-300 cursor-default rounded-r-md" aria-hidden="true">
111+
<span class="relative inline-flex items-center px-2 py-2 -ml-px text-sm font-medium leading-5 text-gray-500 bg-white border border-gray-300 cursor-default last-button rounded-r-md" aria-hidden="true">
112112
@if($next)
113113
{!! $next !!}
114114
@else

resources/views/pagination/gray/tailwind.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
@if ($paginator->onFirstPage())
4444
@if ($showDisabledButtons)
4545
<span aria-disabled="true" aria-label="{{ __('pagination.previous') }}">
46-
<span class="relative inline-flex items-center px-2 py-2 text-sm font-medium leading-5 text-gray-500 bg-white border border-gray-300 cursor-default rounded-l-md" aria-hidden="true">
46+
<span class="relative inline-flex items-center px-2 py-2 text-sm font-medium leading-5 text-gray-500 bg-white border border-gray-300 cursor-default rounded-l-md first-button" aria-hidden="true">
4747
@if($prev)
4848
{!! $prev !!}
4949
@else
@@ -113,7 +113,7 @@ class="relative inline-flex items-center px-3 py-2 -ml-px text-sm bg-gray-500 bo
113113
@else
114114
@if ($showDisabledButtons)
115115
<span aria-disabled="true" aria-label="{{ __('pagination.next') }}">
116-
<span class="relative inline-flex items-center px-2 py-2 -ml-px text-sm font-medium leading-5 text-gray-500 bg-white border border-gray-300 cursor-default rounded-r-md" aria-hidden="true">
116+
<span class="relative inline-flex items-center px-2 py-2 -ml-px text-sm font-medium leading-5 text-gray-500 bg-white border border-gray-300 cursor-default last-button rounded-r-md" aria-hidden="true">
117117
@if($next)
118118
{!! $next !!}
119119
@else

src/ComponentServiceProvider.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ private function mergesConfig()
3333
{
3434
$this->mergeConfigFrom(
3535
__DIR__ . '/../config/components.php',
36-
'lComponents-components'
36+
'components-components'
3737
);
3838

3939
$this->mergeConfigFrom(
4040
__DIR__ . '/../config/app.php',
41-
'lComponents-app'
41+
'components-app'
4242
);
4343
}
4444

@@ -71,7 +71,7 @@ private function registerRoutes()
7171
private function publishesViews(): void
7272
{
7373
$allComponents = $this->getAllComponents();
74-
$publish_vendor_folder = config('lComponents-app.publish_vendor_folder');
74+
$publish_vendor_folder = config('components-app.publish_vendor_folder');
7575

7676
foreach ($allComponents as $component) {
7777
$this->publishes([
@@ -84,10 +84,10 @@ private function publishesViews(): void
8484
private function getAllComponents(): array
8585
{
8686
$allComponents = [];
87-
$components = array_keys(config('lComponents-components')); // like pagination,...
87+
$components = array_keys(config('components-components')); // like pagination,...
8888

8989
foreach ($components as $component) {
90-
$themes = config("lComponents-components.{$component}"); // theme names.
90+
$themes = config("components-components.{$component}"); // theme names.
9191
foreach ($themes as $theme) {
9292
$allComponents[] = ['component' => $component, 'theme' => $theme];
9393
}

src/Components/Pathable.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22

33
namespace AmirHossein5\LaravelComponents\Components;
44

5+
use Illuminate\Support\Facades\App;
6+
57
trait Pathable
68
{
79
protected function assets_path($path): string
810
{
9-
$package_name = config('lComponents-app.package_name');
10-
$author_name = config('lComponents-app.author_name');
11-
$assets_path = config('lComponents-app.assets_path');
11+
$package_name = config('components-app.package_name');
12+
$author_name = config('components-app.author_name');
13+
$assets_path = config('components-app.assets_path');
1214

13-
return base_path("vendor/{$author_name}/{$package_name}/{$assets_path}/{$path}");
15+
return !App::environment('testing')
16+
? base_path("vendor/{$author_name}/{$package_name}/{$assets_path}/{$path}")
17+
: "{$assets_path}/{$path}";
1418
}
1519
}

src/Components/Renderable.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ protected function view(string $path): View
1616
private function getViewPath(string $path): string
1717
{
1818
$path = str_replace('.', '/', $path);
19-
$publish_vendor_folder = config('lComponents-app.publish_vendor_folder');
19+
$publish_vendor_folder = config('components-app.publish_vendor_folder');
2020

2121
return $this->isViewPublished($path)
2222
? "vendor/{$publish_vendor_folder}/{$path}"
@@ -25,7 +25,7 @@ private function getViewPath(string $path): string
2525

2626
private function isViewPublished($path): bool
2727
{
28-
$publish_vendor_folder = config('lComponents-app.publish_vendor_folder');
28+
$publish_vendor_folder = config('components-app.publish_vendor_folder');
2929
return file_exists(resource_path("views/vendor/{$publish_vendor_folder}/{$path}.blade.php"));
3030
}
3131
}

src/LaravelComponentsAssets.php

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

33
namespace AmirHossein5\LaravelComponents;
44

5-
use Prophecy\Exception\Doubler\ClassNotFoundException;
6-
use Prophecy\Exception\Doubler\MethodNotFoundException;
7-
85
class LaravelComponentsAssets
96
{
107
use PretendsToBeAFile;
@@ -17,7 +14,7 @@ public function css($componentName)
1714
} catch (\Error $e) {
1815
abort('404', "{$componentName} doesn't have any stylesheet");
1916
}
20-
17+
2118
return $this->pretendsResponseIsFile($file, 'text/css');
2219
}
2320

tests/Feature/AssetTest.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace AmirHossein5\LaravelComponents\Tests;
4+
5+
class AssetTest extends TestCase
6+
{
7+
public function test_components_assets_loads_correctly()
8+
{
9+
foreach ($this->hasStyleAsset as $comopnent) {
10+
$blade = $this->blade("@lComponentStyles('$comopnent')");
11+
$blade->assertSee("<link rel=stylesheet href=laravelComponents/css/$comopnent.css >", false);
12+
$this->get("laravelComponents/css/$comopnent.css")->assertStatus(200);
13+
};
14+
foreach ($this->hasScriptAsset as $comopnent) {
15+
$blade = $this->blade("@lComponentScripts('$comopnent')");
16+
$blade->assertSee("<script src=laravelComponents/js/$comopnent.js></script>");
17+
$this->get("laravelComponents/js/$comopnent.js")->assertStatus(200);
18+
};
19+
}
20+
21+
public function test_if_passes_wrong_component_name_for_asset_returns_404()
22+
{
23+
$blade = $this->blade("@lComponentStyles('wrong')");
24+
$blade->assertSee("<link rel=stylesheet href=laravelComponents/css/wrong.css >", false);
25+
$this->get('laravelComponents/css/wrong.css')->assertStatus(404);
26+
}
27+
28+
public function test_if_component_dont_have_requested_asset_returns_404()
29+
{
30+
foreach ($this->hasStyleAsset as $comopnent) {
31+
$blade = $this->blade("@lComponentScripts('$comopnent')");
32+
$blade->assertSee("<script src=laravelComponents/js/$comopnent.js></script>", false);
33+
$this->get("laravelComponents/js/$comopnent.js")->assertStatus(404);
34+
};
35+
foreach ($this->hasScriptAsset as $comopnent) {
36+
$blade = $this->blade("@lComponentStyles('$comopnent')");
37+
$blade->assertSee("link rel=stylesheet href=laravelComponents/css/$comopnent.css >", false);
38+
$this->get("laravelComponents/css/$comopnent.css")->assertStatus(404);
39+
};
40+
}
41+
}

tests/Feature/PaginationTest.php

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
<?php
2+
3+
namespace AmirHossein5\LaravelComponents\Tests\Feature;
4+
5+
use AmirHossein5\LaravelComponents\Tests\TestCase;
6+
7+
class PaginationTest extends TestCase
8+
{
9+
public function test_pagination_component_renders_correctly()
10+
{
11+
$blade = $this->blade(
12+
'<x-pagination::gray-circled :elems="$users"/>',
13+
['users' => $this->makePagination()]
14+
);
15+
16+
$blade->assertSee('Showing');
17+
$blade->assertSee('results');
18+
$blade->assertSee('?page=4');
19+
}
20+
21+
public function test_prev_and_next_will_change()
22+
{
23+
$blade = $this->blade(
24+
'<x-pagination::gray-circled :elems="$users" prev="prev" next="next"/>',
25+
['users' => $this->makePagination()]
26+
);
27+
28+
$blade->assertSee('prev');
29+
$blade->assertSee('next');
30+
$blade->assertDontSee('d="M12.707 5.293a1 1 0 010 1.414L9.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z"');
31+
}
32+
33+
public function test_prev_in_responsive_and_next_in_responsive_will_change()
34+
{
35+
$blade = $this->blade(
36+
'<x-pagination::gray-circled
37+
:elems="$users"
38+
prevInResponsive="prevInResponsive"
39+
nextInResponsive="nextInResponsive"
40+
/>',
41+
['users' => $this->makePagination()]
42+
);
43+
44+
$blade->assertSee('prevInResponsive');
45+
$blade->assertSee('nextInResponsive');
46+
$blade->assertDontSee('&amp;laquo; Previous');
47+
$blade->assertDontSee('Next &amp;raquo;');
48+
}
49+
50+
public function test_showDisabledButtons_works()
51+
{
52+
$blade = $this->blade(
53+
'<x-pagination::gray-circled :elems="$users" :showDisabledButtons="false"/>',
54+
['users' => $this->makePagination()]
55+
);
56+
57+
$blade->assertDontSee('first-button');
58+
59+
$blade = $this->blade(
60+
'<x-pagination::gray-circled :elems="$users" :showDisabledButtons="false"/>',
61+
['users' => $this->makePagination(false, 3)]
62+
);
63+
64+
$blade->assertSee('first-button');
65+
$blade->assertSee('last-button');
66+
67+
$blade = $this->blade(
68+
'<x-pagination::gray-circled :elems="$users" :showDisabledButtons="false"/>',
69+
['users' => $this->makePagination(false, 5)]
70+
);
71+
72+
$blade->assertDontSee('last-button');
73+
}
74+
75+
public function test_show_paginator_details_can_disable_showing_pagination_details()
76+
{
77+
$blade = $this->blade(
78+
'<x-pagination::gray-circled :elems="$users" :showPaginatorDetails="false"/>',
79+
['users' => $this->makePagination()]
80+
);
81+
82+
$blade->assertDontSee('Showing');
83+
$blade->assertDontSee('results');
84+
}
85+
86+
public function test_class_can_be_added_to_component()
87+
{
88+
$blade = $this->blade(
89+
'<x-pagination::gray-circled :elems="$users" class="test"/>',
90+
['users' => $this->makePagination()]
91+
);
92+
93+
$blade->assertSee('test"', false);
94+
}
95+
96+
public function test_default_setted_variables_are_changeable()
97+
{
98+
$blade = $this->blade(
99+
'<x-pagination::gray :elems="$users"/>',
100+
['users' => $this->makePagination()]
101+
);
102+
103+
$blade->assertDontSee('first-button', false);
104+
105+
$blade = $this->blade(
106+
'<x-pagination::gray :elems="$users" :showDisabledButtons="true"/>',
107+
['users' => $this->makePagination()]
108+
);
109+
110+
$blade->assertSee('first-button', false);
111+
112+
$blade = $this->blade(
113+
'<x-pagination::gray-circled :elems="$users"/>',
114+
['users' => $this->makePagination()]
115+
);
116+
117+
$blade->assertSee('first-button', false);
118+
119+
$blade = $this->blade(
120+
'<x-pagination::gray-circled :elems="$users" :showDisabledButtons="false"/>',
121+
['users' => $this->makePagination()]
122+
);
123+
124+
$blade->assertDontSee('first-button', false);
125+
}
126+
127+
public function test_simple_pagination_view_is_different()
128+
{
129+
foreach (config('components-components.pagination') as $theme) {
130+
$blade = $this->blade(
131+
'<x-pagination::' . $theme . ' :elems="$users"/>',
132+
['users' => $this->makePagination(true)]
133+
);
134+
135+
$blade->assertDontSee('hidden sm:flex-1 sm:flex sm:items-center sm:justify-between');
136+
};
137+
}
138+
139+
public function test_themes_load_correctly()
140+
{
141+
foreach ($this->uniqueContent['pagination'] as $theme => $contents) {
142+
$blade = $this->blade(
143+
'<x-pagination::' . $theme . ' :elems="$users"/>',
144+
['users' => $this->makePagination()]
145+
);
146+
foreach ($contents as $content) {
147+
$blade->assertSee($content, false);
148+
}
149+
}
150+
}
151+
}

0 commit comments

Comments
 (0)