Some checks are pending
Module sub-split / Sub-split (push) Waiting to run
- Base: wintercms/winter branch 1.2 (full framework) - Theme vivespos: Canvas 7 + Bootstrap 5 CDN, custom CSS - Layout: deferred GTM/GA4 tracking, JSON-LD SoftwareApplication - Partials: hero (offline-first), features, modes (offline/nube toggle), screenshots, pricing (3 planes), comparison, FAQ, CTA - Plugin VivesPOS.Site with ContactForm - Dockerfile: PHP 8.2 Apache, port 80, healthcheck - Added winter/wn-pages, blog, sitemap, seo plugins - Active theme set to vivespos
102 lines
3.7 KiB
PHP
102 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace System\Tests\Plugins\Database;
|
|
|
|
use System\Tests\Bootstrap\PluginTestCase;
|
|
use Database\Tester\Models\User;
|
|
use Database\Tester\Models\Author;
|
|
use Database\Tester\Models\UserWithAuthor;
|
|
use Database\Tester\Models\SoftDeleteAuthor;
|
|
use Database\Tester\Models\UserWithSoftAuthor;
|
|
use Database\Tester\Models\UserWithAuthorAndSoftDelete;
|
|
use Database\Tester\Models\UserWithSoftAuthorAndSoftDelete;
|
|
use Model;
|
|
|
|
class SoftDeleteModelTest extends PluginTestCase
|
|
{
|
|
public function setUp() : void
|
|
{
|
|
parent::setUp();
|
|
|
|
include_once base_path() . '/modules/system/tests/fixtures/plugins/database/tester/models/User.php';
|
|
include_once base_path() . '/modules/system/tests/fixtures/plugins/database/tester/models/Author.php';
|
|
|
|
$this->runPluginRefreshCommand('Database.Tester');
|
|
}
|
|
|
|
public function testDeleteOptionOnHardModel()
|
|
{
|
|
Model::unguard();
|
|
$user = UserWithAuthor::create(['name' => 'Stevie', 'email' => 'stevie@example.com']);
|
|
$author = Author::create(['name' => 'Louie', 'email' => 'louie@example.com', 'user_id' => $user->id]);
|
|
Model::reguard();
|
|
|
|
$authorId = $author->id;
|
|
$user->delete(); // Hard
|
|
$this->assertNull(Author::find($authorId));
|
|
}
|
|
|
|
public function testSoftDeleteOptionOnHardModel()
|
|
{
|
|
Model::unguard();
|
|
$user = UserWithSoftAuthor::create(['name' => 'Stevie', 'email' => 'stevie@example.com']);
|
|
$author = Author::create(['name' => 'Louie', 'email' => 'louie@example.com', 'user_id' => $user->id]);
|
|
Model::reguard();
|
|
|
|
$authorId = $author->id;
|
|
$user->delete(); // Hard
|
|
$this->assertNotNull(Author::find($authorId)); // Do nothing
|
|
}
|
|
|
|
public function testSoftDeleteOptionOnSoftModel()
|
|
{
|
|
Model::unguard();
|
|
$user = UserWithSoftAuthorAndSoftDelete::create(['name' => 'Stevie', 'email' => 'stevie@example.com']);
|
|
$author = SoftDeleteAuthor::create(['name' => 'Louie', 'email' => 'louie@example.com', 'user_id' => $user->id]);
|
|
Model::reguard();
|
|
|
|
$authorId = $author->id;
|
|
$user->delete(); // Soft
|
|
$this->assertNull(SoftDeleteAuthor::find($authorId));
|
|
$this->assertNotNull(SoftDeleteAuthor::withTrashed()->find($authorId));
|
|
}
|
|
|
|
public function testDeleteOptionOnSoftModel()
|
|
{
|
|
Model::unguard();
|
|
$user = UserWithAuthorAndSoftDelete::create(['name' => 'Stevie', 'email' => 'stevie@example.com']);
|
|
$author = Author::create(['name' => 'Louie', 'email' => 'louie@example.com', 'user_id' => $user->id]);
|
|
Model::reguard();
|
|
|
|
$authorId = $author->id;
|
|
$user->delete(); // Soft
|
|
$this->assertNotNull(Author::find($authorId)); // Do nothing
|
|
|
|
$userId = $user->id;
|
|
$user = UserWithAuthorAndSoftDelete::withTrashed()->find($userId);
|
|
$user->restore();
|
|
|
|
$user->forceDelete(); // Hard
|
|
$this->assertNull(Author::find($authorId));
|
|
}
|
|
|
|
public function testRestoreSoftDeleteRelation()
|
|
{
|
|
Model::unguard();
|
|
$user = UserWithSoftAuthorAndSoftDelete::create(['name' => 'Stevie', 'email' => 'stevie@example.com']);
|
|
$author = SoftDeleteAuthor::create(['name' => 'Louie', 'email' => 'louie@example.com', 'user_id' => $user->id]);
|
|
Model::reguard();
|
|
|
|
$authorId = $author->id;
|
|
$user->delete(); // Soft
|
|
$this->assertNull(SoftDeleteAuthor::find($authorId));
|
|
$this->assertNotNull(SoftDeleteAuthor::withTrashed()->find($authorId));
|
|
|
|
$userId = $user->id;
|
|
$user = UserWithSoftAuthorAndSoftDelete::withTrashed()->find($userId);
|
|
$user->restore();
|
|
|
|
$this->assertNotNull(SoftDeleteAuthor::find($authorId));
|
|
}
|
|
}
|