Skip to content

Commit

Permalink
Test passing as a variable
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmitchell committed May 23, 2024
1 parent cb85c85 commit c83b554
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Forms/JsDrivers/AbstractJsDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ abstract class AbstractJsDriver implements JsDriver
*
* @param array $options
*/
public function __construct(Form $form, $options = [], ?Parameters $params)
public function __construct(Form $form, $options = [], ?Parameters $params = null)
{
$this->form = $form;
$this->options = $options;
Expand Down
21 changes: 21 additions & 0 deletions tests/Tags/Form/FormCreateAlpineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,27 @@ public function it_merges_any_x_data_passed_to_the_tag()
$expected = '<form method="POST" action="http://localhost/!/forms/contact" x-data="'.$expectedXData.'">';

$this->assertStringContainsString($expected, $output);

$params = ['xdata' => ['extra' => 'no']];

$output = $this->tag('{{ form:contact js="alpine:my_form" :x-data="xdata" }}{{ /form:contact }}', $params);

$expectedXData = $this->jsonEncode([
'my_form' => [
'name' => null,
'email' => null,
'message' => null,
'fav_animals' => [],
'fav_colour' => null,
'fav_subject' => null,
'winnie' => null,
'extra' => 'no',
],
]);

$expected = '<form method="POST" action="http://localhost/!/forms/contact" x-data="'.$expectedXData.'">';

$this->assertStringContainsString($expected, $output);
}

private function jsonEncode($data)
Expand Down
4 changes: 2 additions & 2 deletions tests/Tags/Form/FormTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ public function post($uri, array $data = [], array $headers = [])
], $headers));
}

protected function tag($tag)
protected function tag($tag, $params = [])
{
return Parse::template($tag, []);
return Parse::template($tag, $params);
}

protected function createForm($blueprintContents = null, $handle = null)
Expand Down

0 comments on commit c83b554

Please sign in to comment.