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
113 lines
3.7 KiB
PHP
113 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace System\Tests\Plugins\Database;
|
|
|
|
use System\Tests\Bootstrap\PluginTestCase;
|
|
use Database\Tester\Models\Post;
|
|
use Database\Tester\Models\Author;
|
|
use Winter\Storm\Database\Models\DeferredBinding;
|
|
use Model;
|
|
|
|
class DeferredBindingTest extends PluginTestCase
|
|
{
|
|
public function setUp() : void
|
|
{
|
|
parent::setUp();
|
|
|
|
include_once base_path() . '/modules/system/tests/fixtures/plugins/database/tester/models/Post.php';
|
|
include_once base_path() . '/modules/system/tests/fixtures/plugins/database/tester/models/Author.php';
|
|
|
|
$this->runPluginRefreshCommand('Database.Tester');
|
|
}
|
|
|
|
public function testNegatedBinding()
|
|
{
|
|
$sessionKey = uniqid('session_key', true);
|
|
DeferredBinding::truncate();
|
|
|
|
Model::unguard();
|
|
$author = Author::make(['name' => 'Stevie']);
|
|
$post = Post::create(['title' => "First post"]);
|
|
$post2 = Post::create(['title' => "Second post"]);
|
|
Model::reguard();
|
|
|
|
$author->posts()->add($post, $sessionKey);
|
|
$this->assertEquals(1, DeferredBinding::count());
|
|
|
|
// Skip repeat bindings
|
|
$author->posts()->add($post, $sessionKey);
|
|
$this->assertEquals(1, DeferredBinding::count());
|
|
|
|
// Remove add-delete pairs
|
|
$author->posts()->remove($post, $sessionKey);
|
|
$this->assertEquals(0, DeferredBinding::count());
|
|
|
|
// Multi ball
|
|
$sessionKey = uniqid('session_key', true);
|
|
$author->posts()->add($post, $sessionKey);
|
|
$author->posts()->add($post, $sessionKey);
|
|
$author->posts()->add($post, $sessionKey);
|
|
$author->posts()->add($post, $sessionKey);
|
|
$author->posts()->add($post2, $sessionKey);
|
|
$author->posts()->add($post2, $sessionKey);
|
|
$author->posts()->add($post2, $sessionKey);
|
|
$author->posts()->add($post2, $sessionKey);
|
|
$author->posts()->add($post2, $sessionKey);
|
|
$this->assertEquals(2, DeferredBinding::count());
|
|
|
|
// Clean up add-delete pairs
|
|
$author->posts()->remove($post, $sessionKey);
|
|
$author->posts()->remove($post2, $sessionKey);
|
|
$this->assertEquals(0, DeferredBinding::count());
|
|
|
|
// Double negative
|
|
$author->posts()->remove($post, $sessionKey);
|
|
$author->posts()->remove($post2, $sessionKey);
|
|
$this->assertEquals(2, DeferredBinding::count());
|
|
|
|
// Skip repeat bindings
|
|
$author->posts()->remove($post, $sessionKey);
|
|
$author->posts()->remove($post2, $sessionKey);
|
|
$this->assertEquals(2, DeferredBinding::count());
|
|
|
|
// Clean up add-delete pairs again
|
|
$author->posts()->add($post, $sessionKey);
|
|
$author->posts()->add($post2, $sessionKey);
|
|
$this->assertEquals(0, DeferredBinding::count());
|
|
}
|
|
|
|
public function testCancelBinding()
|
|
{
|
|
$sessionKey = uniqid('session_key', true);
|
|
DeferredBinding::truncate();
|
|
|
|
Model::unguard();
|
|
$author = Author::make(['name' => 'Stevie']);
|
|
$post = Post::create(['title' => "First post"]);
|
|
Model::reguard();
|
|
|
|
$author->posts()->add($post, $sessionKey);
|
|
$this->assertEquals(1, DeferredBinding::count());
|
|
|
|
$author->cancelDeferred($sessionKey);
|
|
$this->assertEquals(0, DeferredBinding::count());
|
|
}
|
|
|
|
public function testCommitBinding()
|
|
{
|
|
$sessionKey = uniqid('session_key', true);
|
|
DeferredBinding::truncate();
|
|
|
|
Model::unguard();
|
|
$author = Author::make(['name' => 'Stevie']);
|
|
$post = Post::create(['title' => "First post"]);
|
|
Model::reguard();
|
|
|
|
$author->posts()->add($post, $sessionKey);
|
|
$this->assertEquals(1, DeferredBinding::count());
|
|
|
|
$author->commitDeferred($sessionKey);
|
|
$this->assertEquals(0, DeferredBinding::count());
|
|
}
|
|
}
|