1
0
mirror of https://github.com/Kovah/LinkAce.git synced 2025-01-17 21:28:30 +01:00

Add tests for password resets and sharing helper

This commit is contained in:
Kovah 2020-11-17 12:22:41 +01:00
parent b1dea309e3
commit 55bea84112
No known key found for this signature in database
GPG Key ID: AAAA031BA9830D7B
5 changed files with 128 additions and 7 deletions

View File

@ -15,8 +15,6 @@
aria-label="@lang('linkace.reset_password')">
@csrf
{{ implode('|',$errors->all()) }}
<input type="hidden" name="token" value="{{ request()->route('token') }}">
<div class="form-group">

View File

@ -1,3 +1,3 @@
<a href="{{ $href }}" class="{{ $class }}" title="{{ $title }}">
<a href="{!! $href !!}" class="{{ $class }}" title="{{ $title }}">
<x-dynamic-component :component="$icon" class="fw" />
</a>

View File

@ -0,0 +1,75 @@
<?php
namespace Tests\Controller\Auth;
use App\Models\User;
use Illuminate\Auth\Notifications\ResetPassword;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Notification;
use Tests\TestCase;
class PasswordResetTest extends TestCase
{
use RefreshDatabase;
public function testForgotPasswordView(): void
{
$confirmView = $this->get('forgot-password');
$confirmView->assertSee('forgot-password');
}
public function testForgotPasswordRequest(): void
{
Notification::fake();
$user = User::factory()->create([
'email' => 'reset@linkace.org',
]);
$response = $this->post('forgot-password', [
'email' => 'reset@linkace.org',
]);
$response->assertSessionHas('status');
Notification::assertSentTo($user, ResetPassword::class);
}
public function testPasswordResetView(): void
{
$user = User::factory()->create([
'email' => 'reset@linkace.org',
]);
$token = app('auth.password.broker')->createToken($user);
$confirmView = $this->get('reset-password/' . $token);
$confirmView->assertSee('reset-password');
}
public function testPasswordResetRequest(): void
{
$user = User::factory()->create([
'email' => 'reset@linkace.org',
]);
$token = app('auth.password.broker')->createToken($user);
$confirmView = $this->post('reset-password/', [
'token' => $token,
'email' => 'reset@linkace.org',
'password' => 'newPassword',
'password_confirmation' => 'newPassword',
]);
$confirmView->assertRedirect('login');
$loginAttempt = Auth::attempt([
'email' => 'reset@linkace.org',
'password' => 'newPassword',
]);
self::assertTrue($loginAttempt);
}
}

View File

@ -4,15 +4,13 @@ namespace Tests\Helper;
use App\Models\Link;
use App\Models\User;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
class HelperFunctionsTest extends TestCase
{
use DatabaseMigrations;
use DatabaseTransactions;
use RefreshDatabase;
/** @var User */
private $user;

View File

@ -0,0 +1,50 @@
<?php
namespace Tests\Helper;
use App\Helper\Sharing;
use App\Models\Link;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class SharingTest extends TestCase
{
use RefreshDatabase;
public static $shareData = [
'email' => 'mailto:?subject=Example%20Website&body=I%20found%20this%20awesome%20link%2C%20go%20check%20it%20out%3A%20https%3A%2F%2Fexample.com%2F"',
'facebook' => 'https://www.facebook.com/sharer/sharer.php?u=https://example.com/',
'twitter' => 'https://twitter.com/intent/tweet?text=I found this awesome link, go check it out: https://example.com/',
'reddit' => 'http://www.reddit.com/submit?url=https://example.com/&title=Example Website',
'pinterest' => 'http://pinterest.com/pin/create/button/?url=https://example.com/&description=Example Website',
'whatsapp' => 'whatsapp://send?text=I found this awesome link, go check it out: https://example.com/',
'telegram' => 'tg://msg?text==I found this awesome link, go check it out: https://example.com/',
'wechat' => 'https://www.addtoany.com/ext/wechat/share/#url=https://example.com/',
'sms' => 'sms:?&body=I found this awesome link, go check it out: https://example.com/',
'skype' => 'https://web.skype.com/share?url=https%3A%2F%2Fexample.com%2F',
'hackernews' => 'https://news.ycombinator.com/submitlink?u=https://example.com/&t=Example Website',
'mastodon' => 'web+mastodon://share?text=I%20found%20this%20awesome%20link%2C%20go%20check%20it%20out%3A%20https%3A%2F%2Fexample.com%2F',
'pocket' => 'https://getpocket.com/save?url=https://example.com/',
'flipboard' => 'https://share.flipboard.com/bookmarklet/popout?v=Example Website&url=https%3A%2F%2Fexample.com%2F',
'evernote' => 'https://www.evernote.com/clip.action?url=https%3A%2F%2Fexample.com%2F&title=Example Website',
'trello' => 'https://trello.com/add-card?mode=popup&url=https%3A%2F%2Fexample.com%2F&name=Example%20Website&desc=',
'buffer' => 'https://buffer.com/add?url=https%3A%2F%2Fexample.com%2F&text=Example%20Website',
'tumblr' => 'http://tumblr.com/share/link?url=https://example.com/&name=Example Website',
'xing' => 'https://www.xing.com/spi/shares/new?url=https://example.com/',
'linkedin' => 'https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fexample.com%2F&title=Example%20Website&summary=&source=AddToAny',
];
public function testCorrectShareLinkForServices(): void
{
$testLink = Link::factory()->create([
'url' => 'https://example.com/',
'title' => 'Example Website',
]);
foreach (self::$shareData as $service => $expectedLink) {
$shareLink = Sharing::getShareLink($service, $testLink);
self::assertStringContainsString($expectedLink, $shareLink);
}
}
}