-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the
url
option to the avatar widget
- Loading branch information
1 parent
9587737
commit b0f00bc
Showing
5 changed files
with
128 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
<img src="{{ avatar_image_url($data, $size*2) }}" class="img-avatar img-avatar-{{ $size }}" style="width: {{ $size }}px;" @if($tooltip)title="{{ $tooltip }}"@endif> | ||
|
||
@if($url)<a href="{{ $url }}">@endif<img src="{{ avatar_image_url($data, $size*2) }}" class="img-avatar img-avatar-{{ $size }}" style="width: {{ $size }}px;" @if($tooltip)title="{{ $tooltip }}"@endif>@if($url)</a>@endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Contains the AvatarWidgetTest class. | ||
* | ||
* @copyright Copyright (c) 2025 Attila Fulop | ||
* @author Attila Fulop | ||
* @license MIT | ||
* @since 2025-01-09 | ||
* | ||
*/ | ||
|
||
use Illuminate\Support\Facades\Route; | ||
use Konekt\AppShell\Tests\TestCase; | ||
use Konekt\AppShell\Theme\AppShellTheme; | ||
use Konekt\AppShell\Widgets\Avatar; | ||
|
||
class AvatarWidgetTest extends TestCase | ||
{ | ||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
Route::get('/avatar-route-prefix/{user}', ['as' => 'test.user.show']); | ||
} | ||
|
||
/** @test */ | ||
public function it_renders_a_default_when_the_model_is_null() | ||
{ | ||
$widget = Avatar::create(new AppShellTheme()); | ||
|
||
$html = trim($widget->render()); | ||
$this->assertStringContainsString('<img', $html); | ||
$this->assertStringContainsString('src="https://www.gravatar.com/avatar/00000000000000000000000000000000', $html); | ||
} | ||
|
||
/** @test */ | ||
public function it_renders_the_md5_of_the_models_email_when_given() | ||
{ | ||
$user = new \stdClass(); | ||
$user->email = 'test@example.com'; | ||
$md5 = md5($user->email); | ||
$widget = Avatar::create(new AppShellTheme()); | ||
|
||
$html = trim($widget->render($user)); | ||
$this->assertStringContainsString('<img', $html); | ||
$this->assertStringContainsString($md5, $html); | ||
} | ||
|
||
/** @test */ | ||
public function it_substitutes_placeholders_when_given() | ||
{ | ||
$user = new \stdClass(); | ||
$user->email = 'giovanni.gatto@catsville.com'; | ||
$md5 = md5($user->email); | ||
$order = new \stdClass(); | ||
$order->user = $user; | ||
$widget = Avatar::create(new AppShellTheme(), ['model' => '$model.user']); | ||
|
||
$html = trim($widget->render($order)); | ||
$this->assertStringContainsString('<img', $html); | ||
$this->assertStringContainsString($md5, $html); | ||
} | ||
|
||
/** @test */ | ||
public function it_does_not_render_a_link_if_such_parameter_was_not_passed() | ||
{ | ||
$user = new \stdClass(); | ||
$user->email = 'test@example.com'; | ||
$widget = Avatar::create(new AppShellTheme()); | ||
|
||
$html = trim($widget->render($user)); | ||
$this->assertStringNotContainsString('<a', $html); | ||
$this->assertStringNotContainsString('href="', $html); | ||
} | ||
|
||
/** @test */ | ||
public function a_link_can_be_rendered_optionally() | ||
{ | ||
$user = new \stdClass(); | ||
$user->email = 'giovanni.gatto@catsville.com'; | ||
$user->id = 35688; | ||
$md5 = md5($user->email); | ||
|
||
$widget = Avatar::create(new AppShellTheme(), ['url' => 'https://penny.cz']); | ||
|
||
$html = trim($widget->render($user)); | ||
$this->assertStringContainsString('<img ', $html); | ||
$this->assertStringContainsString($md5, $html); | ||
$this->assertStringContainsString('<a href="https://penny.cz">', $html); | ||
} | ||
|
||
/** @test */ | ||
public function a_route_based_link_can_be_rendered_optionally() | ||
{ | ||
$user = new \stdClass(); | ||
$user->email = 'giovanni.gatto@catsville.com'; | ||
$user->id = 35688; | ||
$md5 = md5($user->email); | ||
|
||
$widget = Avatar::create(new AppShellTheme(), ['url' => ['route' => 'test.user.show', 'parameters' => ['$model.id']]]); | ||
|
||
$html = trim($widget->render($user)); | ||
$this->assertStringContainsString('<img ', $html); | ||
$this->assertStringContainsString($md5, $html); | ||
$this->assertStringContainsString('<a href="http://localhost/avatar-route-prefix/35688">', $html); | ||
} | ||
} |