Skip to content

Commit

Permalink
Add test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmitchell committed Jul 31, 2024
1 parent 23e8429 commit 16545e5
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions tests/Forms/FormTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace Tests\Forms;

use PHPUnit\Framework\Attributes\Test;
use Statamic\Facades;
use Tests\TestCase;

class FormTest extends TestCase
{
#[Test]
public function finding_a_form_sets_the_blink_cache()
{
Facades\Form::make('test')->title('Test form')->save();

$form = Facades\Form::find('test');

$this->assertSame(Facades\Blink::get('eloquent-forms-test'), $form);
}

#[Test]
public function getting_all_forms_sets_the_blink_cache()
{
$form = tap(Facades\Form::make('test')->title('Test form'))->save();

Facades\Form::all();

$this->assertCount(1, Facades\Blink::get('eloquent-forms'));
$this->assertSame($form->handle(), Facades\Blink::get('eloquent-forms')->first()->handle());
}

#[Test]
public function saving_a_form_removes_the_blink_cache()
{
Facades\Form::make('test')->title('Test form')->save();

$form = Facades\Form::find('test');
Facades\Form::all(); // to set up eloquent-forms blink

$this->assertSame(Facades\Blink::get('eloquent-forms-test'), $form);
$this->assertCount(1, Facades\Blink::get('eloquent-forms'));

$form->save();

$this->assertNull(Facades\Blink::get('eloquent-forms-test'));
$this->assertNull(Facades\Blink::get('eloquent-forms'));
}

#[Test]
public function deleting_a_form_removes_the_blink_cache()
{
Facades\Form::make('test')->title('Test form')->save();

$form = Facades\Form::find('test');
Facades\Form::all(); // to set up eloquent-forms blink

$this->assertSame(Facades\Blink::get('eloquent-forms-test'), $form);
$this->assertCount(1, Facades\Blink::get('eloquent-forms'));

$form->delete();

$this->assertNull(Facades\Blink::get('eloquent-forms-test'));
$this->assertNull(Facades\Blink::get('eloquent-forms'));
}
}

0 comments on commit 16545e5

Please sign in to comment.