|  | 
| 2 | 2 | 
 | 
| 3 | 3 | namespace Rappasoft\LaravelLivewireTables\Tests\Unit\Views\Columns; | 
| 4 | 4 | 
 | 
|  | 5 | +use Illuminate\Database\Eloquent\Model; | 
| 5 | 6 | use PHPUnit\Framework\Attributes\Group; | 
| 6 | 7 | use Rappasoft\LaravelLivewireTables\Exceptions\DataTableConfigurationException; | 
| 7 | 8 | use Rappasoft\LaravelLivewireTables\Tests\Models\Pet; | 
| @@ -89,4 +90,83 @@ public function test_can_set_attribute_callback(): void | 
| 89 | 90 | 
 | 
| 90 | 91 |         $this->assertTrue(self::$columnInstance->hasAttributesCallback()); | 
| 91 | 92 |     } | 
|  | 93 | + | 
|  | 94 | +    public static function setup_with_public_methods() | 
|  | 95 | +    { | 
|  | 96 | +        \Livewire\Livewire::component('test-livewire-column-component', \Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\TestLivewireColumnComponent::class); | 
|  | 97 | + | 
|  | 98 | +        $row = Pet::find(1); | 
|  | 99 | + | 
|  | 100 | +        $temp = (new class('name', 'name') extends LivewireComponentColumn | 
|  | 101 | +        { | 
|  | 102 | +            public function pubRetrieveAttributes(Model $row) | 
|  | 103 | +            { | 
|  | 104 | +                return $this->retrieveAttributes($row); | 
|  | 105 | +            } | 
|  | 106 | + | 
|  | 107 | +            public function pubImplodeAttributes(array $attributes) | 
|  | 108 | +            { | 
|  | 109 | +                return $this->implodeAttributes($attributes); | 
|  | 110 | +            } | 
|  | 111 | + | 
|  | 112 | +            public function pubGetBlade(array $attributes, string $key) | 
|  | 113 | +            { | 
|  | 114 | +                return $this->getBlade($attributes, $key); | 
|  | 115 | +            } | 
|  | 116 | + | 
|  | 117 | +            public function pubGetHtmlString(array $attributes, string $key) | 
|  | 118 | +            { | 
|  | 119 | +                return $this->getHtmlString($attributes, $key); | 
|  | 120 | +            } | 
|  | 121 | +        })->component('test-livewire-column-component')->attributes(function ($columnValue, $row) { | 
|  | 122 | +            return [ | 
|  | 123 | +                'type' => 'test', | 
|  | 124 | +                'name' => $row->name, | 
|  | 125 | +            ]; | 
|  | 126 | +        }); | 
|  | 127 | + | 
|  | 128 | +        $temp->setTable('test-table'); | 
|  | 129 | + | 
|  | 130 | +        return $temp; | 
|  | 131 | +    } | 
|  | 132 | + | 
|  | 133 | +    public function test_can_get_attributes_correctly(): void | 
|  | 134 | +    { | 
|  | 135 | +        $row = Pet::find(1); | 
|  | 136 | +        $temp = self::setup_with_public_methods(); | 
|  | 137 | +        $key = 'test-table-'.$row->{$row->getKeyName()}; | 
|  | 138 | + | 
|  | 139 | +        $this->assertSame(['type' => 'test', 'name' => 'Cartman'], $temp->pubRetrieveAttributes($row)); | 
|  | 140 | + | 
|  | 141 | +        $this->assertSame(':type="$type" :name="$name"', $temp->pubImplodeAttributes($temp->pubRetrieveAttributes($row))); | 
|  | 142 | +    } | 
|  | 143 | + | 
|  | 144 | +    public function test_can_get_blade_correctly(): void | 
|  | 145 | +    { | 
|  | 146 | +        $row = Pet::find(1); | 
|  | 147 | +        $temp = self::setup_with_public_methods(); | 
|  | 148 | +        $key = 'test-table-'.$row->{$row->getKeyName()}; | 
|  | 149 | + | 
|  | 150 | +        $this->assertStringContainsString('wire:snapshot="{"data":{"id":null,"name":"Cartman","value":null,"type":"test"}', $temp->pubGetBlade($temp->pubRetrieveAttributes($row), $key)); | 
|  | 151 | + | 
|  | 152 | +        $this->assertStringContainsString('<div>Name:Cartman</div><div>Type:test</div>', $temp->pubGetBlade($temp->pubRetrieveAttributes($row), $key)); | 
|  | 153 | +    } | 
|  | 154 | + | 
|  | 155 | +    public function test_can_get_html_string_correctly(): void | 
|  | 156 | +    { | 
|  | 157 | +        $row = Pet::find(1); | 
|  | 158 | +        $temp = self::setup_with_public_methods(); | 
|  | 159 | +        $key = 'test-table-'.$row->{$row->getKeyName()}; | 
|  | 160 | + | 
|  | 161 | +        $this->assertStringContainsString('<div>Name:Cartman</div><div>Type:test</div>', $temp->pubGetHtmlString($temp->pubRetrieveAttributes($row), $key)); | 
|  | 162 | +    } | 
|  | 163 | + | 
|  | 164 | +    public function test_can_get_contents_correctly(): void | 
|  | 165 | +    { | 
|  | 166 | +        $row = Pet::find(1); | 
|  | 167 | +        $temp = self::setup_with_public_methods(); | 
|  | 168 | +        $key = 'test-table-'.$row->{$row->getKeyName()}; | 
|  | 169 | + | 
|  | 170 | +        $this->assertStringContainsString('<div>Name:Cartman</div><div>Type:test</div>', $temp->getContents($row)); | 
|  | 171 | +    } | 
| 92 | 172 | } | 
0 commit comments