Skip to content

Commit

Permalink
The id is persisted when its generated the first time. Closes #2822. C…
Browse files Browse the repository at this point in the history
…loses #2823
  • Loading branch information
jasonvarga committed Nov 20, 2020
1 parent a7f3b5f commit dea77e8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Forms/Submission.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function id($id = null)
{
return $this->fluentlyGetOrSet('id')
->getter(function ($id) {
return $id ?: microtime(true);
return $this->id = $id ?: microtime(true);
})
->args(func_get_args());
}
Expand Down
23 changes: 23 additions & 0 deletions tests/Forms/SubmissionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Tests\Forms;

use Statamic\Facades\Form;
use Tests\TestCase;

class SubmissionTest extends TestCase
{
/** @test */
public function the_id_is_generated_the_first_time_but_can_be_overridden()
{
$submission = Form::make('test')->makeSubmission();

$this->assertNotNull($id = $submission->id());
$this->assertEquals($id, $submission->id());
$this->assertEquals($id, $submission->id());

$submission->id('123');

$this->assertEquals('123', $submission->id());
}
}

0 comments on commit dea77e8

Please sign in to comment.