Add tests
This commit is contained in:
parent
44fe418eee
commit
c607990991
@ -34,7 +34,7 @@ class OptionForm
|
||||
|
||||
protected $renderWithOutTable = false;
|
||||
protected $renderInputTagsOnly = false;
|
||||
protected $renderWithOutSubmitButton = false;
|
||||
protected $renderWithoutSubmitButton = false;
|
||||
|
||||
/**
|
||||
* Create a new option form instance.
|
||||
@ -244,7 +244,7 @@ class OptionForm
|
||||
*/
|
||||
public function handle(callable $callback = null)
|
||||
{
|
||||
$request = app('request');
|
||||
$request = request();
|
||||
$allPostData = $request->all();
|
||||
|
||||
if ($request->isMethod('POST') && Arr::get($allPostData, 'option') == $this->id) {
|
||||
@ -368,9 +368,9 @@ class OptionForm
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function renderWithOutSubmitButton()
|
||||
public function renderWithoutSubmitButton()
|
||||
{
|
||||
$this->renderWithOutSubmitButton = true;
|
||||
$this->renderWithoutSubmitButton = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@ -387,7 +387,7 @@ class OptionForm
|
||||
}
|
||||
|
||||
// attach submit button to the form
|
||||
if (! $this->renderWithOutSubmitButton) {
|
||||
if (! $this->renderWithoutSubmitButton) {
|
||||
$this->addButton([
|
||||
'style' => 'primary',
|
||||
'text' => trans('general.submit'),
|
||||
|
94
tests/ServicesTest/OptionFormTest.php
Normal file
94
tests/ServicesTest/OptionFormTest.php
Normal file
@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use App\Services\OptionForm;
|
||||
|
||||
class OptionFormTest extends TestCase
|
||||
{
|
||||
public function testHookBefore()
|
||||
{
|
||||
$called = false;
|
||||
$form = new OptionForm('test', 'test');
|
||||
$form->before(function () use (&$called) {
|
||||
$called = true;
|
||||
});
|
||||
|
||||
$request = request();
|
||||
$request->setMethod('POST');
|
||||
$request->merge(['option' => 'test']);
|
||||
|
||||
$form->handle();
|
||||
$this->assertTrue($called);
|
||||
}
|
||||
|
||||
public function testHookAfter()
|
||||
{
|
||||
$called = false;
|
||||
$form = new OptionForm('test', 'test');
|
||||
$form->after(function () use (&$called) {
|
||||
$called = true;
|
||||
});
|
||||
|
||||
$request = request();
|
||||
$request->setMethod('POST');
|
||||
$request->merge(['option' => 'test']);
|
||||
|
||||
$form->handle();
|
||||
$this->assertTrue($called);
|
||||
}
|
||||
|
||||
public function testDirectHook()
|
||||
{
|
||||
$called = false;
|
||||
$form = new OptionForm('test', 'test');
|
||||
|
||||
$request = request();
|
||||
$request->setMethod('POST');
|
||||
$request->merge(['option' => 'test']);
|
||||
|
||||
$form->handle(function () use (&$called) {
|
||||
$called = true;
|
||||
});
|
||||
$this->assertTrue($called);
|
||||
}
|
||||
|
||||
public function testHookAlways()
|
||||
{
|
||||
$called = false;
|
||||
$form = new OptionForm('test', 'test');
|
||||
$form->always(function () use (&$called) {
|
||||
$called = true;
|
||||
});
|
||||
|
||||
$request = request();
|
||||
$request->setMethod('POST');
|
||||
$request->merge(['option' => 'test']);
|
||||
|
||||
$form->handle();
|
||||
$this->assertFalse($called);
|
||||
|
||||
$form->render();
|
||||
$this->assertTrue($called);
|
||||
}
|
||||
|
||||
public function testRenderInputTagsOnly()
|
||||
{
|
||||
$form = new OptionForm('test', 'test');
|
||||
$form->text('text');
|
||||
$form->renderInputTagsOnly();
|
||||
$html = $form->render();
|
||||
$this->assertFalse(Str::contains($html, '<td class="key">'));
|
||||
$this->assertTrue(Str::contains($html, '<td class="value">'));
|
||||
}
|
||||
|
||||
public function testRenderWithoutSubmitButton()
|
||||
{
|
||||
$form = new OptionForm('test', 'test');
|
||||
$form->text('text');
|
||||
$form->renderWithoutSubmitButton();
|
||||
$html = $form->render();
|
||||
$this->assertFalse(Str::contains($html, '<button'));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user