createAttachment('header.png'); $footerAttachment = $this->createAttachment('footer.png'); $tenant = Tenant::query()->create([ 'codigo' => 'group-test', 'nombre' => 'Group Test', 'dominio' => 'group.test', 'primary_color' => '#111111', 'secondary_color' => '#222222', 'danger_color' => '#333333', 'success_color' => '#28a745', 'header_bg_color' => '#444444', 'footer_bg_color' => '#555555', 'header_logo_id' => $headerAttachment->id, 'footer_logo_id' => $footerAttachment->id, ]); $category = Category::query()->create([ 'tenant_code' => $tenant->codigo, 'nombre' => 'Group items', ]); $product = Product::query()->create([ 'tenant_codigo' => $tenant->codigo, 'categoria_id' => $category->id, 'slug' => 'group-item-product', 'nombre' => 'Group Item Product', 'precio' => 100, ]); $this->variant = ProductVariant::query()->create([ 'producto_id' => $product->id, 'stock' => 10, ]); $this->bundle = Bundle::query()->create([ 'tenant_codigo' => $tenant->codigo, 'nombre' => 'Group Item Bundle', 'precio' => 150, ]); $this->featuredGroup = FeaturedGroup::query()->create([ 'tenant_codigo' => $tenant->codigo, 'group_name' => 'Featured', 'product_layout' => 'row', 'group_order' => 0, ]); } public function test_a_group_item_can_reference_a_product_variant(): void { $groupItem = $this->variant->groupItems()->create([ 'featured_group_id' => $this->featuredGroup->id, 'order' => 1, ]); $this->assertInstanceOf(ProductVariant::class, $groupItem->groupable); $this->assertTrue($groupItem->groupable->is($this->variant)); $this->assertTrue($this->variant->groupItems->first()->is($groupItem)); } public function test_a_group_item_can_reference_a_bundle(): void { $groupItem = $this->bundle->groupItems()->create([ 'featured_group_id' => $this->featuredGroup->id, 'order' => 2, ]); $this->assertInstanceOf(Bundle::class, $groupItem->groupable); $this->assertTrue($groupItem->groupable->is($this->bundle)); $this->assertTrue($this->bundle->groupItems->first()->is($groupItem)); } private function createAttachment(string $filename): Attachment { return Attachment::query()->create([ 'key' => (string) Str::uuid(), 'path' => 'tests/'.$filename, 'filename' => $filename, 'type' => AttachmentType::Image, 'mime_type' => 'image/png', ]); } }