Files
vivespos-landing/modules/system/tests/plugins/database/MorphToModelTest.php
avives 1f72193a64
Some checks are pending
Module sub-split / Sub-split (push) Waiting to run
feat: VivesPOS landing on Winter CMS 1.2 — theme + plugin + Dockerfile
- 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
2026-08-21 19:29:00 -06:00

67 lines
2.3 KiB
PHP

<?php
namespace System\Tests\Plugins\Database;
use System\Tests\Bootstrap\PluginTestCase;
use Database\Tester\Models\Post;
use Database\Tester\Models\Author;
use Database\Tester\Models\EventLog;
use Model;
class MorphToModelTest extends PluginTestCase
{
public function setUp() : void
{
parent::setUp();
include_once base_path() . '/modules/system/tests/fixtures/plugins/database/tester/models/Author.php';
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/EventLog.php';
$this->runPluginRefreshCommand('Database.Tester');
}
public function testSetRelationValue()
{
Model::unguard();
$author = Author::create(['name' => 'Stevie', 'email' => 'stevie@example.com']);
$post1 = Post::create(['title' => "First post", 'description' => "Yay!!"]);
$post2 = Post::make(['title' => "Second post", 'description' => "Woohoo!!"]);
$event = EventLog::create(['action' => "user-created"]);
Model::reguard();
// Set by Model object
$event->related = $author;
$event->save();
$this->assertEquals($author->id, $event->related_id);
$this->assertEquals('Stevie', $event->related->name);
// Set by primary key
$event->related = [$post1->id, get_class($post1)];
$this->assertEquals($post1->id, $event->related_id);
$this->assertEquals('First post', $event->related->title);
// Nullify
$event->related = null;
$this->assertNull($event->related_id);
$this->assertNull($event->related);
// Deferred in memory
$event->related = $post2;
$this->assertEquals('Second post', $event->related->title);
$this->assertNull($event->related_id);
$event->save();
$this->assertEquals($post2->id, $event->related_id);
}
public function testGetRelationValue()
{
Model::unguard();
$author = Author::create(['name' => 'Stevie']);
$event = EventLog::make(['action' => "user-created", 'related_id' => $author->id, 'related_type' => get_class($author)]);
Model::reguard();
$this->assertEquals([$author->id, get_class($author)], $event->getRelationValue('related'));
}
}