|
26 | 26 | use Illuminate\Database\Eloquent\Casts\AsEncryptedCollection;
|
27 | 27 | use Illuminate\Database\Eloquent\Casts\AsEnumArrayObject;
|
28 | 28 | use Illuminate\Database\Eloquent\Casts\AsEnumCollection;
|
| 29 | +use Illuminate\Database\Eloquent\Casts\AsHtmlString; |
29 | 30 | use Illuminate\Database\Eloquent\Casts\AsStringable;
|
30 | 31 | use Illuminate\Database\Eloquent\Casts\Attribute;
|
31 | 32 | use Illuminate\Database\Eloquent\Collection;
|
|
45 | 46 | use Illuminate\Support\Carbon;
|
46 | 47 | use Illuminate\Support\Collection as BaseCollection;
|
47 | 48 | use Illuminate\Support\Facades\Crypt;
|
| 49 | +use Illuminate\Support\HtmlString; |
48 | 50 | use Illuminate\Support\InteractsWithTime;
|
49 | 51 | use Illuminate\Support\Stringable;
|
50 | 52 | use InvalidArgumentException;
|
@@ -264,6 +266,24 @@ public function testDirtyOnCastedStringable()
|
264 | 266 | $this->assertTrue($model->isDirty('asStringableAttribute'));
|
265 | 267 | }
|
266 | 268 |
|
| 269 | + public function testDirtyOnCastedHtmlString() |
| 270 | + { |
| 271 | + $model = new EloquentModelCastingStub; |
| 272 | + $model->setRawAttributes([ |
| 273 | + 'asHtmlStringAttribute' => '<div>foo bar</div>', |
| 274 | + ]); |
| 275 | + $model->syncOriginal(); |
| 276 | + |
| 277 | + $this->assertInstanceOf(HtmlString::class, $model->asHtmlStringAttribute); |
| 278 | + $this->assertFalse($model->isDirty('asHtmlStringAttribute')); |
| 279 | + |
| 280 | + $model->asHtmlStringAttribute = new HtmlString('<div>foo bar</div>'); |
| 281 | + $this->assertFalse($model->isDirty('asHtmlStringAttribute')); |
| 282 | + |
| 283 | + $model->asHtmlStringAttribute = new Stringable('<div>foo baz</div>'); |
| 284 | + $this->assertTrue($model->isDirty('asHtmlStringAttribute')); |
| 285 | + } |
| 286 | + |
267 | 287 | // public function testDirtyOnCastedEncryptedCollection()
|
268 | 288 | // {
|
269 | 289 | // $this->encrypter = m::mock(Encrypter::class);
|
@@ -3670,6 +3690,7 @@ protected function casts(): array
|
3670 | 3690 | 'datetimeAttribute' => 'datetime',
|
3671 | 3691 | 'asarrayobjectAttribute' => AsArrayObject::class,
|
3672 | 3692 | 'asStringableAttribute' => AsStringable::class,
|
| 3693 | + 'asHtmlStringAttribute' => AsHtmlString::class, |
3673 | 3694 | 'asCustomCollectionAttribute' => AsCollection::using(CustomCollection::class),
|
3674 | 3695 | 'asEncryptedArrayObjectAttribute' => AsEncryptedArrayObject::class,
|
3675 | 3696 | 'asEncryptedCustomCollectionAttribute' => AsEncryptedCollection::using(CustomCollection::class),
|
|
0 commit comments