55 lines
2.8 KiB
PHP
55 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\Bootstrap;
|
|
|
|
use App\Domains\Core\Menu\Models\Menu;
|
|
use App\Domains\Core\Menu\Models\TenantMenu;
|
|
use App\Domains\Core\Tenant\Models\SocialMedia;
|
|
use App\Domains\Core\Tenant\Models\Tenant;
|
|
use App\Domains\Core\Tenant\Resources\TenantResource;
|
|
use App\Domains\Ticketing\Event\Models\Event;
|
|
use Illuminate\Database\Eloquent\Relations\Pivot;
|
|
use Tests\TestCase;
|
|
|
|
class TenantContactResourceTest extends TestCase
|
|
{
|
|
public function test_dynamic_contact_omits_legacy_content_and_prioritizes_active_event_social_media(): void
|
|
{
|
|
$tenant = new Tenant(['codigo' => 'test']);
|
|
foreach (['favicon', 'headerLogo', 'footerLogo', 'headerBackgroundImage', 'footerBackgroundImage', 'storefrontWebsiteType'] as $relation) {
|
|
$tenant->setRelation($relation, null);
|
|
}
|
|
$contact = new Menu([
|
|
'code' => 'help.contact', 'label' => 'Contacto', 'content_type' => 'dynamic', 'route' => '/ayuda/contacto',
|
|
]);
|
|
$contact->setRelation('pivot', new TenantMenu(['static_content' => ['whatsapp' => 'legacy']]));
|
|
$faq = new Menu(['code' => 'help.faq', 'label' => 'FAQ', 'content_type' => 'static']);
|
|
$faq->setRelation('pivot', new TenantMenu(['static_content' => ['question' => 'Example']]));
|
|
$tenant->setRelation('menues', collect([$contact, $faq]));
|
|
$tenantSocial = new SocialMedia(['code' => 'whatsapp', 'name' => 'WhatsApp', 'icon' => 'fa-brands fa-whatsapp']);
|
|
$tenantSocial->setRelation('pivot', new Pivot(['url' => 'https://wa.me/111']));
|
|
$eventSocial = new SocialMedia(['code' => 'whatsapp', 'name' => 'WhatsApp', 'icon' => 'fa-brands fa-whatsapp']);
|
|
$eventSocial->setRelation('pivot', new Pivot(['url' => 'https://wa.me/222']));
|
|
$tenant->setRelation('socialMedia', collect([$tenantSocial]));
|
|
$event = new Event;
|
|
$event->setRelation('socialMedia', collect([$eventSocial]));
|
|
$event->setRelation('address', null);
|
|
$event->setRelation('dates', collect());
|
|
$tenant->setRelation('activeEvent', $event);
|
|
|
|
$data = TenantResource::make($tenant)->resolve(request());
|
|
$this->assertSame('dynamic', $data['menues'][0]['content_type']);
|
|
$this->assertArrayNotHasKey('static_content', $data['menues'][0]);
|
|
$this->assertSame(['question' => 'Example'], $data['menues'][1]['static_content']);
|
|
$this->assertSame('https://wa.me/222', $data['social_media'][0]['url']);
|
|
|
|
$event->setRelation('socialMedia', collect());
|
|
$data = TenantResource::make($tenant)->resolve(request());
|
|
$this->assertCount(0, $data['social_media']);
|
|
|
|
$tenant->setRelation('activeEvent', null);
|
|
$data = TenantResource::make($tenant)->resolve(request());
|
|
$this->assertSame('https://wa.me/111', $data['social_media'][0]['url']);
|
|
}
|
|
}
|