mirror of
https://github.com/Kovah/LinkAce.git
synced 2025-03-14 19:59:38 +01:00
Add missing link deletion method for link repository
This commit is contained in:
parent
5d96a75341
commit
e2da1d38a6
@ -190,7 +190,12 @@ class LinkController extends Controller
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$link->delete();
|
||||
$deletion_successfull = LinkRepository::delete($link);
|
||||
|
||||
if ($deletion_successfull) {
|
||||
alert(trans('link.deletion_error'), 'error');
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
alert(trans('link.deleted_successfully'), 'warning');
|
||||
|
||||
|
@ -6,6 +6,7 @@ use App\Helper\LinkAce;
|
||||
use App\Helper\LinkIconMapper;
|
||||
use App\Models\Link;
|
||||
use App\Models\Tag;
|
||||
use Tests\Unit\Models\LinkDeleteTest;
|
||||
|
||||
class LinkRepository
|
||||
{
|
||||
@ -51,6 +52,21 @@ class LinkRepository
|
||||
return $link;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Link $link
|
||||
* @return bool
|
||||
*/
|
||||
public static function delete(Link $link): bool
|
||||
{
|
||||
try {
|
||||
$link->delete();
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Link $link
|
||||
* @param string $tags
|
||||
|
@ -33,6 +33,7 @@ return [
|
||||
'added_successfully' => 'Link added successfully.',
|
||||
'updated_successfully' => 'Link updated successfully.',
|
||||
'deleted_successfully' => 'Link deleted successfully.',
|
||||
'deletion_error' => 'Link could not be deleted.',
|
||||
|
||||
'notifications.linkcheck.errors' => 'LinkAce found errors while checking your Links',
|
||||
'notifications.linkcheck.errors.moved' => '⚠ ️The following Links were moved:',
|
||||
|
@ -18,7 +18,7 @@ class LinkCreateTest extends TestCase
|
||||
/** @var User */
|
||||
private $user;
|
||||
|
||||
public function setUp()
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
@ -30,7 +30,7 @@ class LinkCreateTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testValidLinkCreation()
|
||||
public function testValidLinkCreation(): void
|
||||
{
|
||||
$this->be($this->user);
|
||||
|
||||
|
42
tests/Unit/Models/LinkDeleteTest.php
Normal file
42
tests/Unit/Models/LinkDeleteTest.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Models;
|
||||
|
||||
use App\Models\Link;
|
||||
use App\Models\User;
|
||||
use App\Repositories\LinkRepository;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Tests\TestCase;
|
||||
|
||||
class LinkDeleteTest extends TestCase
|
||||
{
|
||||
use DatabaseMigrations;
|
||||
use DatabaseTransactions;
|
||||
|
||||
/** @var User */
|
||||
private $user;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->user = factory(User::class)->create();
|
||||
}
|
||||
|
||||
/**
|
||||
* A basic test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testValidCategoryCreation(): void
|
||||
{
|
||||
$this->be($this->user);
|
||||
|
||||
$link = factory(Link::class)->create();
|
||||
|
||||
$deletion_result = LinkRepository::delete($link);
|
||||
|
||||
$this->assertTrue($deletion_result);
|
||||
}
|
||||
}
|
@ -17,7 +17,7 @@ class LinkUpdateTest extends TestCase
|
||||
/** @var User */
|
||||
private $user;
|
||||
|
||||
public function setUp()
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
@ -29,7 +29,7 @@ class LinkUpdateTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testValidLinkUpdate()
|
||||
public function testValidLinkUpdate(): void
|
||||
{
|
||||
$this->be($this->user);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user