<file_sep><?php

namespace LaravelFlare\Fields;

use LaravelFlare\Flare\FlareModuleProvider as ServiceProvider;

class FieldServiceProvider extends ServiceProvider
{
    /**
     * Perform post-registration booting of services.
     */
    public function boot()
    {
        $this->publishConfig();
        $this->publishAssets();
        $this->publishViews();
    }

    /**
     * Register any package services.
     */
    public function register()
    {
        $this->registerFlareHelpers();
    }

    /**
     * Register Flare Helper for Pages.
     */
    private function registerFlareHelpers()
    {
        $this->flare->registerHelper('fields', \LaravelFlare\Fields\FieldManager::class);
    }

    /**
     * Publishes the Flare Assets to the appropriate directories.
     */
    private function publishAssets()
    {
        $assets = [
            'public' => 'public/vendor/flare',
        ];

        foreach ($assets as $location => $asset) {
            $assets[$this->basePath($location)] = base_path($asset);
        }

        $this->publishes($assets, 'public');
    }

    /**
     * Publishes the Flare Fields Config File.
     */
    private function publishConfig()
    {
        $this->publishes([
            $this->basePath('config/flare/fields.php') => config_path('flare/fields.php'),
        ]);
    }

    /**
     * Publishes the Flare Field Views and defines the location
     * they should be looked for in the application.
     */
    private function publishViews()
    {
        $this->loadViewsFrom($this->basePath('resources/views'), 'flare');
        $this->publishes([
            $this->basePath('resources/views') => base_path('resources/views/vendor/flare'),
        ]);
    }

    /**
     * Returns the path to a provided file within the Flare package.
     *
     * @param bool $fiepath
     *
     * @return string
     */
    private function basePath($filepath = false)
    {
        return __DIR__.'/../'.$filepath;
    }
}
<file_sep><?php

namespace LaravelFlare\Fields\Types;

class AutoCompleteField extends BaseField
{
    /**
     * View Path for this Field Type.
     *
     * @var string
     */
    protected $viewpath = 'flare::fields.autocomplete';
}
<file_sep><?php

use LaravelFlare\Fields\FieldManager;
use LaravelFlare\Fields\Types\PasswordField;
use Illuminate\Contracts\View\Factory as ViewFactory;

class PasswordFieldTest extends BaseTest
{
    protected $fieldManager;

    public function test_password_field_render_methods()
    {
        $this->setupField('password', PasswordField::class);

        $this->assertContains('type="password"', $this->fieldManager->render('add', 'password', 'new_attribute', null, [])->render());
        $this->assertContains('type="password"', $this->fieldManager->render('edit', 'password', 'new_attribute', null, [])->render());
        $this->assertContains('type="password"', $this->fieldManager->render('clone', 'password', 'new_attribute', null, [])->render());
        $this->assertContains('New Attribute', $this->fieldManager->render('view', 'password', 'new_attribute', null, [])->render());
    }

    public function test_password_field_attribute_title()
    {
        $this->setupField('password', PasswordField::class);

        $this->assertContains('Attribute Title', $this->fieldManager->render('add', 'password', 'attribute_title', null, [])->render());
        $this->assertContains('Attribute Title', $this->fieldManager->render('edit', 'password', 'attribute_title', null, [])->render());
        $this->assertContains('Attribute Title', $this->fieldManager->render('clone', 'password', 'attribute_title', null, [])->render());
        $this->assertContains('Attribute Title', $this->fieldManager->render('view', 'password', 'attribute_title', null, [])->render());
    }

    public function test_password_field_is_required()
    {
        $this->setupField('password', PasswordField::class);

        $options = ['required' => true];

        $this->assertContains('required="required"', $this->fieldManager->render('add', 'password', 'attribute_title', null, $options)->render());
        $this->assertContains('required="required"', $this->fieldManager->render('edit', 'password', 'attribute_title', null, $options)->render());
        $this->assertContains('required="required"', $this->fieldManager->render('clone', 'password', 'attribute_title', null, $options)->render());

        $this->assertContains('This field is required', $this->fieldManager->render('add', 'password', 'attribute_title', null, $options)->render());
        $this->assertContains('This field is required', $this->fieldManager->render('edit', 'password', 'attribute_title', null, $options)->render());
        $this->assertContains('This field is required', $this->fieldManager->render('clone', 'password', 'attribute_title', null, $options)->render());
    }

    public function test_password_field_has_tooltip()
    {
        $this->setupField('password', PasswordField::class);

        $options = ['tooltip' => null];

        $this->assertNotContains('data-toggle="tooltip"', $this->fieldManager->render('add', 'password', 'attribute_title', null, $options)->render());
        $this->assertNotContains('data-toggle="tooltip"', $this->fieldManager->render('edit', 'password', 'attribute_title', null, $options)->render());
        $this->assertNotContains('data-toggle="tooltip"', $this->fieldManager->render('clone', 'password', 'attribute_title', null, $options)->render());

        $options = ['tooltip' => 'This is the Attribute Title Field.'];

        $this->assertContains('data-original-title="This is the Attribute Title Field."', $this->fieldManager->render('add', 'password', 'attribute_title', null, $options)->render());
        $this->assertContains('data-original-title="This is the Attribute Title Field."', $this->fieldManager->render('edit', 'password', 'attribute_title', null, $options)->render());
        $this->assertContains('data-original-title="This is the Attribute Title Field."', $this->fieldManager->render('clone', 'password', 'attribute_title', null, $options)->render());
    }

    public function test_password_field_with_defined_classes()
    {
        $this->setupField('password', PasswordField::class);

        $options = ['class' => null];

        $this->assertContains('class="form-control "', $this->fieldManager->render('add', 'password', 'attribute_title', null, $options)->render());
        $this->assertContains('class="form-control "', $this->fieldManager->render('edit', 'password', 'attribute_title', null, $options)->render());
        $this->assertContains('class="form-control "', $this->fieldManager->render('clone', 'password', 'attribute_title', null, $options)->render());

        $options = ['class' => 'example-class another-class'];

        $this->assertContains('class="form-control example-class another-class"', $this->fieldManager->render('add', 'password', 'attribute_title', null, $options)->render());
        $this->assertContains('class="form-control example-class another-class"', $this->fieldManager->render('edit', 'password', 'attribute_title', null, $options)->render());
        $this->assertContains('class="form-control example-class another-class"', $this->fieldManager->render('clone', 'password', 'attribute_title', null, $options)->render());
    }

    public function test_password_field_has_maxlength()
    {      
        $this->setupField('password', PasswordField::class);

        $options = ['maxlength' => null];

        $this->assertNotContains('maxlength', $this->fieldManager->render('add', 'password', 'attribute_title', null, $options)->render());
        $this->assertNotContains('maxlength', $this->fieldManager->render('edit', 'password', 'attribute_title', null, $options)->render());
        $this->assertNotContains('maxlength', $this->fieldManager->render('clone', 'password', 'attribute_title', null, $options)->render());

        $options = ['maxlength' => 30];

        $this->assertContains('maxlength="30"', $this->fieldManager->render('add', 'password', 'attribute_title', null, $options)->render());
        $this->assertContains('maxlength="30"', $this->fieldManager->render('edit', 'password', 'attribute_title', null, $options)->render());
        $this->assertContains('maxlength="30"', $this->fieldManager->render('clone', 'password', 'attribute_title', null, $options)->render());
    }

    public function test_password_field_is_disabled()
    {
        $this->setupField('password', PasswordField::class);

        $options = ['disabled' => null];

        $this->assertNotContains('disabled', $this->fieldManager->render('add', 'password', 'attribute_title', null, $options)->render());
        $this->assertNotContains('disabled', $this->fieldManager->render('edit', 'password', 'attribute_title', null, $options)->render());
        $this->assertNotContains('disabled', $this->fieldManager->render('clone', 'password', 'attribute_title', null, $options)->render());

        $options = ['disabled' => true];

        $this->assertContains('disabled="disabled"', $this->fieldManager->render('add', 'password', 'attribute_title', null, $options)->render());
        $this->assertContains('disabled="disabled"', $this->fieldManager->render('edit', 'password', 'attribute_title', null, $options)->render());
        $this->assertContains('disabled="disabled"', $this->fieldManager->render('clone', 'password', 'attribute_title', null, $options)->render());
    }

    public function test_password_field_is_readonly()
    {
        $this->setupField('password', PasswordField::class);

        $options = ['readonly' => null];

        $this->assertNotContains('readonly', $this->fieldManager->render('add', 'password', 'attribute_title', null, $options)->render());
        $this->assertNotContains('readonly', $this->fieldManager->render('edit', 'password', 'attribute_title', null, $options)->render());
        $this->assertNotContains('readonly', $this->fieldManager->render('clone', 'password', 'attribute_title', null, $options)->render());

        $options = ['readonly' => true];

        $this->assertContains('readonly="readonly"', $this->fieldManager->render('add', 'password', 'attribute_title', null, $options)->render());
        $this->assertContains('readonly="readonly"', $this->fieldManager->render('edit', 'password', 'attribute_title', null, $options)->render());
        $this->assertContains('readonly="readonly"', $this->fieldManager->render('clone', 'password', 'attribute_title', null, $options)->render());
    }

    public function test_password_field_has_autofocus()
    {
        $this->setupField('password', PasswordField::class);

        $options = ['autofocus' => null];

        $this->assertNotContains('autofocus', $this->fieldManager->render('add', 'password', 'attribute_title', null, $options)->render());
        $this->assertNotContains('autofocus', $this->fieldManager->render('edit', 'password', 'attribute_title', null, $options)->render());
        $this->assertNotContains('autofocus', $this->fieldManager->render('clone', 'password', 'attribute_title', null, $options)->render());

        $options = ['autofocus' => true];

        $this->assertContains('autofocus="autofocus"', $this->fieldManager->render('add', 'password', 'attribute_title', null, $options)->render());
        $this->assertContains('autofocus="autofocus"', $this->fieldManager->render('edit', 'password', 'attribute_title', null, $options)->render());
        $this->assertContains('autofocus="autofocus"', $this->fieldManager->render('clone', 'password', 'attribute_title', null, $options)->render());
    }

    public function test_password_field_has_placeholder()
    {        
        $this->setupField('password', PasswordField::class);

        $options = ['placeholder' => null];

        $this->assertNotContains('placeholder', $this->fieldManager->render('add', 'password', 'attribute_title', null, $options)->render());
        $this->assertNotContains('placeholder', $this->fieldManager->render('edit', 'password', 'attribute_title', null, $options)->render());
        $this->assertNotContains('placeholder', $this->fieldManager->render('clone', 'password', 'attribute_title', null, $options)->render());

        $options = ['placeholder' => 'Input your Attribute Title'];

        $this->assertContains('placeholder="Input your Attribute Title"', $this->fieldManager->render('add', 'password', 'attribute_title', null, $options)->render());
        $this->assertContains('placeholder="Input your Attribute Title"', $this->fieldManager->render('edit', 'password', 'attribute_title', null, $options)->render());
        $this->assertContains('placeholder="Input your Attribute Title"', $this->fieldManager->render('clone', 'password', 'attribute_title', null, $options)->render());
    }

    public function test_password_field_has_help_text()
    {      
        $this->setupField('password', PasswordField::class);

        $options = ['help' => null];

        $this->assertNotContains('help-block', $this->fieldManager->render('add', 'password', 'attribute_title', null, $options)->render());
        $this->assertNotContains('help-block', $this->fieldManager->render('edit', 'password', 'attribute_title', null, $options)->render());
        $this->assertNotContains('help-block', $this->fieldManager->render('clone', 'password', 'attribute_title', null, $options)->render());

        $options = ['help' => 'Please enter your <strong>Attribute Title</strong>'];

        $this->assertContains('<p class="help-block">Please enter your <strong>Attribute Title</strong></p>', $this->fieldManager->render('add', 'password', 'attribute_title', null, $options)->render());
        $this->assertContains('<p class="help-block">Please enter your <strong>Attribute Title</strong></p>', $this->fieldManager->render('edit', 'password', 'attribute_title', null, $options)->render());
        $this->assertContains('<p class="help-block">Please enter your <strong>Attribute Title</strong></p>', $this->fieldManager->render('clone', 'password', 'attribute_title', null, $options)->render());
    }

    public function test_password_field_displays_first_error()
    {
        $this->setupField('password', PasswordField::class);

        $this->setErrors('attribute_title', ['Error 1', 'Error 2']);

        $this->assertContains('Error 1', $this->fieldManager->render('add', 'password', 'attribute_title', 'Aden Fraser', [])->render());
        $this->assertContains('Error 1', $this->fieldManager->render('edit', 'password', 'attribute_title', 'Aden Fraser', [])->render());
        $this->assertContains('Error 1', $this->fieldManager->render('clone', 'password', 'attribute_title', 'Aden Fraser', [])->render());

        $this->assertNotContains('Error 2', $this->fieldManager->render('add', 'password', 'attribute_title', 'Aden Fraser', [])->render());
        $this->assertNotContains('Error 2', $this->fieldManager->render('edit', 'password', 'attribute_title', 'Aden Fraser', [])->render());
        $this->assertNotContains('Error 2', $this->fieldManager->render('clone', 'password', 'attribute_title', 'Aden Fraser', [])->render());
    }

    public function test_password_field_has_error_class()
    {
        $this->setupField('password', PasswordField::class);

        $this->setErrors('attribute_title', ['Error 1', 'Error 2']);

        $this->assertContains('<div class="form-group  has-error', $this->fieldManager->render('add', 'password', 'attribute_title', 'Aden Fraser', [])->render());
        $this->assertContains('<div class="form-group  has-error', $this->fieldManager->render('edit', 'password', 'attribute_title', 'Aden Fraser', [])->render());
        $this->assertContains('<div class="form-group  has-error', $this->fieldManager->render('clone', 'password', 'attribute_title', 'Aden Fraser', [])->render());
    }

    public function test_password_field_has_error_icon()
    {
        $this->setupField('password', PasswordField::class);

        $this->setErrors('attribute_title', ['Error 1', 'Error 2']);

        $this->assertContains('<i class="fa fa-times-circle-o"></i>', $this->fieldManager->render('add', 'password', 'attribute_title', 'Aden Fraser', [])->render());
        $this->assertContains('<i class="fa fa-times-circle-o"></i>', $this->fieldManager->render('edit', 'password', 'attribute_title', 'Aden Fraser', [])->render());
        $this->assertContains('<i class="fa fa-times-circle-o"></i>', $this->fieldManager->render('clone', 'password', 'attribute_title', 'Aden Fraser', [])->render());
    }

    public function test_password_field_has_confirmed_input()
    {
        $this->setupField('password', PasswordField::class);

        $options = ['confirmed' => true];

        $this->assertContains('<label class="control-label" for="new_attribute_confirmation">', $this->fieldManager->render('add', 'password', 'new_attribute', null, $options)->render());
        $this->assertContains('<label class="control-label" for="new_attribute_confirmation">', $this->fieldManager->render('edit', 'password', 'new_attribute', null, $options)->render());
        $this->assertContains('<label class="control-label" for="new_attribute_confirmation">', $this->fieldManager->render('clone', 'password', 'new_attribute', null, $options)->render());
    }       
}
<file_sep><?php

namespace LaravelFlare\Fields\Types;

class CheckboxField extends BaseField
{
    /**
     * View Path for this Field Type
     *     Defaults to flare::fields which outputs
     *     a warning callout notifying the user that the field
     *     view does not yet exist.
     *
     * @var string
     */
    protected $viewpath = 'flare::fields.checkbox';
}
<file_sep><?php

class FileFieldTest extends BaseTest
{
	public function test_to_come()
	{
		$this->markTestIncomplete('test_to_come');
	}
}
<file_sep><?php

namespace LaravelFlare\Fields\Types;

class MapField extends BaseField
{
    /**
     * View Path for this Field Type
     *     Defaults to flare::fields which outputs
     *     a warning callout notifying the user that the field
     *     view does not yet exist.
     *
     * @var string
     */
    protected $viewpath = 'flare::fields.map';

    /**
     * Returns all of the accessible data for the Attirbute View.
     *
     * @return array
     */
    protected function viewData()
    {
        $fieldConfig = app('flare')->fields()->config();
        
        return [
            'google_api_key' => array_get($fieldConfig, 'options.map.google_api_key', null),
            'field' => $this->getField(),
            'fieldType' => $this->getFieldType(),
            'attribute' => $this->getAttribute(),
            'attributeTitle' => $this->getAttributeTitle(),
            'value' => $this->getValue(),
            'oldValue' => $this->getOldValue(),
            'options' => $this->getOptions(),
        ];
    }
}
<file_sep><?php

class CheckboxFieldTest extends BaseTest
{
	public function test_field_unavailable_without_options()
	{
		$this->markTestIncomplete('test_field_unavailable_without_options');
	}

	public function test_field_with_single_option()
	{
		$this->markTestIncomplete('test_field_with_single_option');
	}

	public function test_field_with_multiple_options()
	{
		$this->markTestIncomplete('test_field_with_multiple_options');
	}

	public function test_field_displays_errors()
	{
		$this->markTestIncomplete('test_field_displays_errors');
	}

	public function test_field_is_not_required()
	{
		$this->markTestIncomplete('test_field_is_not_required');
	}

	public function test_field_is_required()
	{
		$this->markTestIncomplete('test_field_is_required');
	}

	public function test_field_has_tooltip()
	{
		$this->markTestIncomplete('test_field_has_tooltip');
	}

	public function test_field_has_help_text()
	{
		$this->markTestIncomplete('test_field_has_help_text');
	}

	public function test_field_does_not_have_old_value()
	{
		$this->markTestIncomplete('test_field_does_not_have_old_value');
	}

	public function test_field_has_old_value_scalar()
	{
		$this->markTestIncomplete('test_field_has_old_value_scalar');
	}

	public function test_field_has_old_value_array_key()
	{
		$this->markTestIncomplete('test_field_has_old_value_array_key');
	}

	public function test_field_has_old_value_array_value()
	{
		$this->markTestIncomplete('test_field_has_old_value_array_value');
	}

	public function test_field_has_old_value_eloquent_model()
	{
		$this->markTestIncomplete('test_field_has_old_value_eloquent_model');
	}
}
<file_sep><?php

class EmailFieldTest extends BaseTest
{
	public function test_to_come()
	{
		$this->markTestIncomplete('test_to_come');
	}
}
<file_sep><?php

class ImageFieldTest extends BaseTest
{
	public function test_to_come()
	{
		$this->markTestIncomplete('test_to_come');
	}
}
<file_sep><?php

use LaravelFlare\Fields\FieldManager;
use LaravelFlare\Fields\Types\TextField;
use Illuminate\Contracts\View\Factory as ViewFactory;

class TextFieldTest extends BaseTest
{
    protected $fieldManager;

    public function test_text_field_render_methods()
    {
        $this->setupField('text', TextField::class);

        $this->assertContains('<label class="control-label" for="new_attribute">', $this->fieldManager->render('add', 'text', 'new_attribute', null, [])->render());
        $this->assertContains('<label class="control-label" for="new_attribute">', $this->fieldManager->render('edit', 'text', 'new_attribute', null, [])->render());
        $this->assertContains('<label class="control-label" for="new_attribute">', $this->fieldManager->render('clone', 'text', 'new_attribute', null, [])->render());
        $this->assertContains('New Attribute', $this->fieldManager->render('view', 'text', 'new_attribute', null, [])->render());
    }

    public function test_text_field_attribute_title()
    {
        $this->setupField('text', TextField::class);

        $this->assertContains('Attribute Title', $this->fieldManager->render('add', 'text', 'attribute_title', null, [])->render());
        $this->assertContains('Attribute Title', $this->fieldManager->render('edit', 'text', 'attribute_title', null, [])->render());
        $this->assertContains('Attribute Title', $this->fieldManager->render('clone', 'text', 'attribute_title', null, [])->render());
        $this->assertContains('Attribute Title', $this->fieldManager->render('view', 'text', 'attribute_title', null, [])->render());
    }

    public function test_text_field_is_required()
    {
        $this->setupField('text', TextField::class);

        $options = ['required' => true];

        $this->assertContains('required="required"', $this->fieldManager->render('add', 'text', 'attribute_title', null, $options)->render());
        $this->assertContains('required="required"', $this->fieldManager->render('edit', 'text', 'attribute_title', null, $options)->render());
        $this->assertContains('required="required"', $this->fieldManager->render('clone', 'text', 'attribute_title', null, $options)->render());

        $this->assertContains('This field is required', $this->fieldManager->render('add', 'text', 'attribute_title', null, $options)->render());
        $this->assertContains('This field is required', $this->fieldManager->render('edit', 'text', 'attribute_title', null, $options)->render());
        $this->assertContains('This field is required', $this->fieldManager->render('clone', 'text', 'attribute_title', null, $options)->render());
    }

    public function test_text_field_has_tooltip()
    {
        $this->setupField('text', TextField::class);

        $options = ['tooltip' => null];

        $this->assertNotContains('data-toggle="tooltip"', $this->fieldManager->render('add', 'text', 'attribute_title', null, $options)->render());
        $this->assertNotContains('data-toggle="tooltip"', $this->fieldManager->render('edit', 'text', 'attribute_title', null, $options)->render());
        $this->assertNotContains('data-toggle="tooltip"', $this->fieldManager->render('clone', 'text', 'attribute_title', null, $options)->render());

        $options = ['tooltip' => 'This is the Attribute Title Field.'];

        $this->assertContains('data-original-title="This is the Attribute Title Field."', $this->fieldManager->render('add', 'text', 'attribute_title', null, $options)->render());
        $this->assertContains('data-original-title="This is the Attribute Title Field."', $this->fieldManager->render('edit', 'text', 'attribute_title', null, $options)->render());
        $this->assertContains('data-original-title="This is the Attribute Title Field."', $this->fieldManager->render('clone', 'text', 'attribute_title', null, $options)->render());
    }

    public function test_text_field_with_defined_classes()
    {
        $this->setupField('text', TextField::class);

        $options = ['class' => null];

        $this->assertContains('class="form-control "', $this->fieldManager->render('add', 'text', 'attribute_title', null, $options)->render());
        $this->assertContains('class="form-control "', $this->fieldManager->render('edit', 'text', 'attribute_title', null, $options)->render());
        $this->assertContains('class="form-control "', $this->fieldManager->render('clone', 'text', 'attribute_title', null, $options)->render());

        $options = ['class' => 'example-class another-class'];

        $this->assertContains('class="form-control example-class another-class"', $this->fieldManager->render('add', 'text', 'attribute_title', null, $options)->render());
        $this->assertContains('class="form-control example-class another-class"', $this->fieldManager->render('edit', 'text', 'attribute_title', null, $options)->render());
        $this->assertContains('class="form-control example-class another-class"', $this->fieldManager->render('clone', 'text', 'attribute_title', null, $options)->render());
    }

    public function test_text_field_has_maxlength()
    {      
        $this->setupField('text', TextField::class);

        $options = ['maxlength' => null];

        $this->assertNotContains('maxlength', $this->fieldManager->render('add', 'text', 'attribute_title', null, $options)->render());
        $this->assertNotContains('maxlength', $this->fieldManager->render('edit', 'text', 'attribute_title', null, $options)->render());
        $this->assertNotContains('maxlength', $this->fieldManager->render('clone', 'text', 'attribute_title', null, $options)->render());

        $options = ['maxlength' => 30];

        $this->assertContains('maxlength="30"', $this->fieldManager->render('add', 'text', 'attribute_title', null, $options)->render());
        $this->assertContains('maxlength="30"', $this->fieldManager->render('edit', 'text', 'attribute_title', null, $options)->render());
        $this->assertContains('maxlength="30"', $this->fieldManager->render('clone', 'text', 'attribute_title', null, $options)->render());
    }

    public function test_text_field_is_disabled()
    {
        $this->setupField('text', TextField::class);

        $options = ['disabled' => null];

        $this->assertNotContains('disabled', $this->fieldManager->render('add', 'text', 'attribute_title', null, $options)->render());
        $this->assertNotContains('disabled', $this->fieldManager->render('edit', 'text', 'attribute_title', null, $options)->render());
        $this->assertNotContains('disabled', $this->fieldManager->render('clone', 'text', 'attribute_title', null, $options)->render());

        $options = ['disabled' => true];

        $this->assertContains('disabled="disabled"', $this->fieldManager->render('add', 'text', 'attribute_title', null, $options)->render());
        $this->assertContains('disabled="disabled"', $this->fieldManager->render('edit', 'text', 'attribute_title', null, $options)->render());
        $this->assertContains('disabled="disabled"', $this->fieldManager->render('clone', 'text', 'attribute_title', null, $options)->render());
    }

    public function test_text_field_is_readonly()
    {
        $this->setupField('text', TextField::class);

        $options = ['readonly' => null];

        $this->assertNotContains('readonly', $this->fieldManager->render('add', 'text', 'attribute_title', null, $options)->render());
        $this->assertNotContains('readonly', $this->fieldManager->render('edit', 'text', 'attribute_title', null, $options)->render());
        $this->assertNotContains('readonly', $this->fieldManager->render('clone', 'text', 'attribute_title', null, $options)->render());

        $options = ['readonly' => true];

        $this->assertContains('readonly="readonly"', $this->fieldManager->render('add', 'text', 'attribute_title', null, $options)->render());
        $this->assertContains('readonly="readonly"', $this->fieldManager->render('edit', 'text', 'attribute_title', null, $options)->render());
        $this->assertContains('readonly="readonly"', $this->fieldManager->render('clone', 'text', 'attribute_title', null, $options)->render());
    }

    public function test_text_field_has_autocomplete()
    {        
        $this->setupField('text', TextField::class);

        $options = ['autocomplete' => null];

        $this->assertNotContains('autocomplete', $this->fieldManager->render('add', 'text', 'attribute_title', null, $options)->render());
        $this->assertNotContains('autocomplete', $this->fieldManager->render('edit', 'text', 'attribute_title', null, $options)->render());
        $this->assertNotContains('autocomplete', $this->fieldManager->render('clone', 'text', 'attribute_title', null, $options)->render());

        $options = ['autocomplete' => false];

        $this->assertContains('autocomplete="off"', $this->fieldManager->render('add', 'text', 'attribute_title', null, $options)->render());
        $this->assertContains('autocomplete="off"', $this->fieldManager->render('edit', 'text', 'attribute_title', null, $options)->render());
        $this->assertContains('autocomplete="off"', $this->fieldManager->render('clone', 'text', 'attribute_title', null, $options)->render());

        $options = ['autocomplete' => true];

        $this->assertContains('autocomplete="on"', $this->fieldManager->render('add', 'text', 'attribute_title', null, $options)->render());
        $this->assertContains('autocomplete="on"', $this->fieldManager->render('edit', 'text', 'attribute_title', null, $options)->render());
        $this->assertContains('autocomplete="on"', $this->fieldManager->render('clone', 'text', 'attribute_title', null, $options)->render());
    }

    public function test_text_field_has_autofocus()
    {
        $this->setupField('text', TextField::class);

        $options = ['autofocus' => null];

        $this->assertNotContains('autofocus', $this->fieldManager->render('add', 'text', 'attribute_title', null, $options)->render());
        $this->assertNotContains('autofocus', $this->fieldManager->render('edit', 'text', 'attribute_title', null, $options)->render());
        $this->assertNotContains('autofocus', $this->fieldManager->render('clone', 'text', 'attribute_title', null, $options)->render());

        $options = ['autofocus' => true];

        $this->assertContains('autofocus="autofocus"', $this->fieldManager->render('add', 'text', 'attribute_title', null, $options)->render());
        $this->assertContains('autofocus="autofocus"', $this->fieldManager->render('edit', 'text', 'attribute_title', null, $options)->render());
        $this->assertContains('autofocus="autofocus"', $this->fieldManager->render('clone', 'text', 'attribute_title', null, $options)->render());
    }

    public function test_text_field_has_pattern()
    {
        $this->setupField('text', TextField::class);

        $options = ['pattern' => null];

        $this->assertNotContains('pattern', $this->fieldManager->render('add', 'text', 'attribute_title', null, $options)->render());
        $this->assertNotContains('pattern', $this->fieldManager->render('edit', 'text', 'attribute_title', null, $options)->render());
        $this->assertNotContains('pattern', $this->fieldManager->render('clone', 'text', 'attribute_title', null, $options)->render());

        $options = ['pattern' => '[A-Za-z]{3}'];

        $this->assertContains('pattern="[A-Za-z]{3}"', $this->fieldManager->render('add', 'text', 'attribute_title', null, $options)->render());
        $this->assertContains('pattern="[A-Za-z]{3}"', $this->fieldManager->render('edit', 'text', 'attribute_title', null, $options)->render());
        $this->assertContains('pattern="[A-Za-z]{3}"', $this->fieldManager->render('clone', 'text', 'attribute_title', null, $options)->render());
    }

    public function test_text_field_has_input_mask()
    {
        $this->setupField('text', TextField::class);

        $options = ['data-inputmask' => null];

        $this->assertNotContains('data-mask', $this->fieldManager->render('add', 'text', 'attribute_title', null, $options)->render());
        $this->assertNotContains('data-mask', $this->fieldManager->render('edit', 'text', 'attribute_title', null, $options)->render());
        $this->assertNotContains('data-mask', $this->fieldManager->render('clone', 'text', 'attribute_title', null, $options)->render());
        $this->assertNotContains('data-inputmask', $this->fieldManager->render('add', 'text', 'attribute_title', null, $options)->render());
        $this->assertNotContains('data-inputmask', $this->fieldManager->render('edit', 'text', 'attribute_title', null, $options)->render());
        $this->assertNotContains('data-inputmask', $this->fieldManager->render('clone', 'text', 'attribute_title', null, $options)->render());

        $options = ['data-inputmask' => "'alias': 'date'"];

        $this->assertContains('data-mask=""', $this->fieldManager->render('add', 'text', 'attribute_title', null, $options)->render());
        $this->assertContains('data-mask=""', $this->fieldManager->render('edit', 'text', 'attribute_title', null, $options)->render());
        $this->assertContains('data-mask=""', $this->fieldManager->render('clone', 'text', 'attribute_title', null, $options)->render());
        $this->assertContains('data-inputmask="\'alias\': \'date\'"', $this->fieldManager->render('add', 'text', 'attribute_title', null, $options)->render());
        $this->assertContains('data-inputmask="\'alias\': \'date\'"', $this->fieldManager->render('edit', 'text', 'attribute_title', null, $options)->render());
        $this->assertContains('data-inputmask="\'alias\': \'date\'"', $this->fieldManager->render('clone', 'text', 'attribute_title', null, $options)->render());
    }

    public function test_text_field_has_placeholder()
    {        
        $this->setupField('text', TextField::class);

        $options = ['placeholder' => null];

        $this->assertNotContains('placeholder', $this->fieldManager->render('add', 'text', 'attribute_title', null, $options)->render());
        $this->assertNotContains('placeholder', $this->fieldManager->render('edit', 'text', 'attribute_title', null, $options)->render());
        $this->assertNotContains('placeholder', $this->fieldManager->render('clone', 'text', 'attribute_title', null, $options)->render());

        $options = ['placeholder' => 'Input your Attribute Title'];

        $this->assertContains('placeholder="Input your Attribute Title"', $this->fieldManager->render('add', 'text', 'attribute_title', null, $options)->render());
        $this->assertContains('placeholder="Input your Attribute Title"', $this->fieldManager->render('edit', 'text', 'attribute_title', null, $options)->render());
        $this->assertContains('placeholder="Input your Attribute Title"', $this->fieldManager->render('clone', 'text', 'attribute_title', null, $options)->render());
    }

    public function test_text_field_has_value()
    {
        $this->setupField('text', TextField::class);

        $this->assertContains('value="Ad<NAME>aser"', $this->fieldManager->render('add', 'text', 'attribute_title', 'Aden Fraser', [])->render());
        $this->assertContains('value="Aden Fraser"', $this->fieldManager->render('edit', 'text', 'attribute_title', 'Aden Fraser', [])->render());
        $this->assertContains('value="Aden Fraser"', $this->fieldManager->render('clone', 'text', 'attribute_title', 'Aden Fraser', [])->render());
        $this->assertContains('Aden Fraser', $this->fieldManager->render('view', 'text', 'attribute_title', 'Aden Fraser', [])->render());
    }

    public function test_text_field_has_old_value()
    {
        $this->setupField('text', TextField::class);

        Request::session()->flash('_old_input', ['attribute_title' => 'Old Value']);

        $this->assertContains('value="Old Value"', $this->fieldManager->render('add', 'text', 'attribute_title', 'Aden Fraser', [])->render());
        $this->assertContains('value="Old Value"', $this->fieldManager->render('edit', 'text', 'attribute_title', 'Aden Fraser', [])->render());
        $this->assertContains('value="Old Value"', $this->fieldManager->render('clone', 'text', 'attribute_title', 'Aden Fraser', [])->render());
    }

    public function test_text_field_has_help_text()
    {      
        $this->setupField('text', TextField::class);

        $options = ['help' => null];

        $this->assertNotContains('help-block', $this->fieldManager->render('add', 'text', 'attribute_title', null, $options)->render());
        $this->assertNotContains('help-block', $this->fieldManager->render('edit', 'text', 'attribute_title', null, $options)->render());
        $this->assertNotContains('help-block', $this->fieldManager->render('clone', 'text', 'attribute_title', null, $options)->render());

        $options = ['help' => 'Please enter your <strong>Attribute Title</strong>'];

        $this->assertContains('<p class="help-block">Please enter your <strong>Attribute Title</strong></p>', $this->fieldManager->render('add', 'text', 'attribute_title', null, $options)->render());
        $this->assertContains('<p class="help-block">Please enter your <strong>Attribute Title</strong></p>', $this->fieldManager->render('edit', 'text', 'attribute_title', null, $options)->render());
        $this->assertContains('<p class="help-block">Please enter your <strong>Attribute Title</strong></p>', $this->fieldManager->render('clone', 'text', 'attribute_title', null, $options)->render());
    }

    public function test_text_field_displays_first_error()
    {
        $this->setupField('text', TextField::class);

        $this->setErrors('attribute_title', ['Error 1', 'Error 2']);

        $this->assertContains('Error 1', $this->fieldManager->render('add', 'text', 'attribute_title', 'Aden Fraser', [])->render());
        $this->assertContains('Error 1', $this->fieldManager->render('edit', 'text', 'attribute_title', 'Aden Fraser', [])->render());
        $this->assertContains('Error 1', $this->fieldManager->render('clone', 'text', 'attribute_title', 'Aden Fraser', [])->render());

        $this->assertNotContains('Error 2', $this->fieldManager->render('add', 'text', 'attribute_title', 'Aden Fraser', [])->render());
        $this->assertNotContains('Error 2', $this->fieldManager->render('edit', 'text', 'attribute_title', 'Aden Fraser', [])->render());
        $this->assertNotContains('Error 2', $this->fieldManager->render('clone', 'text', 'attribute_title', 'Aden Fraser', [])->render());
    }

    public function test_text_field_has_error_class()
    {
        $this->setupField('text', TextField::class);

        $this->setErrors('attribute_title', ['Error 1', 'Error 2']);

        $this->assertContains('<div class="form-group  has-error', $this->fieldManager->render('add', 'text', 'attribute_title', 'Aden Fraser', [])->render());
        $this->assertContains('<div class="form-group  has-error', $this->fieldManager->render('edit', 'text', 'attribute_title', 'Aden Fraser', [])->render());
        $this->assertContains('<div class="form-group  has-error', $this->fieldManager->render('clone', 'text', 'attribute_title', 'Aden Fraser', [])->render());
    }

    public function test_text_field_has_error_icon()
    {
        $this->setupField('text', TextField::class);

        $this->setErrors('attribute_title', ['Error 1', 'Error 2']);

        $this->assertContains('<i class="fa fa-times-circle-o"></i>', $this->fieldManager->render('add', 'text', 'attribute_title', 'Aden Fraser', [])->render());
        $this->assertContains('<i class="fa fa-times-circle-o"></i>', $this->fieldManager->render('edit', 'text', 'attribute_title', 'Aden Fraser', [])->render());
        $this->assertContains('<i class="fa fa-times-circle-o"></i>', $this->fieldManager->render('clone', 'text', 'attribute_title', 'Aden Fraser', [])->render());
    }

    public function test_text_field_has_confirmed_input()
    {
        $this->setupField('text', TextField::class);

        $options = ['confirmed' => true];

        $this->assertContains('<label class="control-label" for="new_attribute_confirmation">', $this->fieldManager->render('add', 'text', 'new_attribute', null, $options)->render());
        $this->assertContains('<label class="control-label" for="new_attribute_confirmation">', $this->fieldManager->render('edit', 'text', 'new_attribute', null, $options)->render());
        $this->assertContains('<label class="control-label" for="new_attribute_confirmation">', $this->fieldManager->render('clone', 'text', 'new_attribute', null, $options)->render());
    }       
}
<file_sep><?php

namespace LaravelFlare\Fields\Types;

use Exception;
use Illuminate\Support\HtmlString;

class BaseField
{
    /**
     * Field Type Constant.
     */
    const FIELD_TYPE = '';

    /**
     * View Path for this Field Type
     *     Defaults to flare::fields which outputs
     *     a warning callout notifying the user that the field
     *     view does not yet exist.
     *
     * @var string
     */
    protected $viewpath = 'flare::fields';

    /**
     * Field.
     *
     * @var string
     */
    protected $field;

    /**
     * Attribute.
     *
     * @var mixed
     */
    protected $attribute;

    /**
     * Value.
     *
     * @var mixed
     */
    protected $value;

    /**
     * Options.
     *
     * @var mixed
     */
    protected $options;

    /**
     * __construct.
     *
     * @param string $field
     * @param string $attribute
     * @param string $value
     * @param string $modelManager
     */
    public function __construct($field, $attribute, $value, $options = [])
    {
        $this->field = $field;
        $this->attribute = $attribute;
        $this->value = $value;
        $this->options = $options;
    }

    /**
     * Returns the Rendered View.
     *
     * @param bool $view
     *
     * @return \Illuminate\View\View
     */
    public function render($view = false)
    {
        if (method_exists($this, $method = 'render'.ucfirst($view))) {
            return new HtmlString(call_user_func_array([$this, $method], []));
        }

        throw new Exception("Render method `$view` for ".$this->getFieldType().' Field does not exist.');
    }

    /**
     * Renders the Add (Create) Field View.
     *
     * @return \Illuminate\View\View
     */
    public function renderAdd()
    {
        return view($this->viewpath.'.add', $this->viewData());
    }

    /**
     * Renders the Edit (Update) Field View.
     *
     * @return \Illuminate\View\View
     */
    public function renderEdit()
    {
        return view($this->viewpath.'.edit', $this->viewData());
    }

    /**
     * Renders the Clone (Update) Field View.
     *
     * @return \Illuminate\View\View
     */
    public function renderClone()
    {
        if (view()->exists($this->viewpath.'.clone')) {
            view($this->viewpath.'.clone', $this->viewData());
        }

        return view($this->viewpath.'.edit', $this->viewData());
    }

    /**
     * Renders the Viewable Field View.
     *
     * @return \Illuminate\View\View
     */
    public function renderView()
    {
        return view($this->viewpath.'.view', $this->viewData());
    }

    /**
     * Getter for Field.
     *
     * @return string
     */
    public function getField()
    {
        return $this->field;
    }

    /**
     * Getter for Attribute.
     *
     * @return string
     */
    public function getAttribute()
    {
        return $this->attribute;
    }

    /**
     * Returns the current value.
     *
     * @return mixed
     */
    public function getValue()
    {
        return $this->value;
    }

    /**
     * Returns the old or current value.
     *
     * @return mixed
     */
    public function getOldValue()
    {
        return old($this->attribute, $this->getValue());
    }

    /**
     * Gets Field Options if they are defined.
     */
    public function getOptions()
    {
        return $this->options;
    }

    /**
     * Accessor for Field Type converted to Title Case.
     *
     * @return string
     */
    public function getFieldType()
    {
        return title_case($this->getField() ? $this->getField() : self::FIELD_TYPE);
    }

    /*
     * Acessor for Field Title converted to Title Case with Spaces.
     *
     * @return string
     */
    public function getAttributeTitle()
    {
        return str_replace('_', ' ', isset($this->options['title']) ? $this->options['title'] : title_case($this->getAttribute()));
    }

    /**
     * Returns all of the accessible data for the Attirbute View.
     *
     * @return array
     */
    protected function viewData()
    {
        return [
                'field' => $this->getField(),
                'fieldType' => $this->getFieldType(),
                'attribute' => $this->getAttribute(),
                'attributeTitle' => $this->getAttributeTitle(),
                'value' => $this->getValue(),
                'oldValue' => $this->getOldValue(),
                'options' => $this->getOptions(),
            ];
    }
}
<file_sep># Form Field Component
<file_sep><?php

use LaravelFlare\Fields\FieldManager;
use LaravelFlare\Fields\Types\BaseField;
use LaravelFlare\Fields\Types\TextField;

/**
 * Tests the Field Manager Class and the generation
 * of Fields based on the BaseField class.
 */
class FieldManagerTest extends BaseTest
{
    protected $fieldManager;

    public function test_creating_a_field_that_does_not_exist()
    {
        $this->setupNoFieldTypes();
        $field = $this->fieldManager->create('text', 'attribute', null, []);

        $this->assertInstanceOf(BaseField::class, $field);
        $this->assertEquals('text', $field->getField());
        $this->assertEquals('attribute', $field->getAttribute());
        $this->assertNull($field->getValue());
        $this->assertEquals([], $field->getOptions());
        $this->assertEquals('Text', $field->getFieldType());
        $this->assertEquals('Attribute', $field->getAttributeTitle());
    }

    public function test_creating_a_new_field()
    {
        $this->setupTextAndPasswordFieldTypes();
        $field = $this->fieldManager->create('text', 'attribute', null, []);

        $this->assertInstanceOf(TextField::class, $field);
        $this->assertEquals('text', $field->getField());
        $this->assertEquals('attribute', $field->getAttribute());
        $this->assertNull($field->getValue());
        $this->assertEquals([], $field->getOptions());
        $this->assertEquals('Text', $field->getFieldType());
        $this->assertEquals('Attribute', $field->getAttributeTitle());
    }

    public function test_rendering_a_field_that_does_not_exist()
    {
        $this->setupNoFieldTypes();

        $this->assertContains('Text Field Type Missing!', $this->fieldManager->render('add', 'text', 'attribute', null, [])->render());
        $this->assertContains('Text Field Type Missing!', $this->fieldManager->render('edit', 'text', 'attribute', null, [])->render());
        $this->assertContains('Text Field Type Missing!', $this->fieldManager->render('clone', 'text', 'attribute', null, [])->render());
        $this->assertContains('Text Field Type Missing!', $this->fieldManager->render('view', 'text', 'attribute', null, [])->render());

        $this->setExpectedException(Exception::class, 'Field Type cannot be empty or undefined.');
        $this->fieldManager->render('add', null, 'attribute', null, [])->render();
    }

    public function test_rendering_a_field_that_does_exist()
    {
        $this->setupTextAndPasswordFieldTypes();

        $this->assertContains('<label class="control-label" for="attribute">', $this->fieldManager->create('text', 'attribute', null, [])->render('add')->toHtml()->render());
        $this->assertContains('<label class="control-label" for="attribute">', $this->fieldManager->create('text', 'attribute', null, [])->render('edit')->toHtml()->render());
        $this->assertContains('<label class="control-label" for="attribute">', $this->fieldManager->create('text', 'attribute', null, [])->render('clone')->toHtml()->render());
        $this->assertContains('Attribute', $this->fieldManager->create('text', 'attribute', null, [])->render('view')->toHtml()->render());
    }

    public function test_rendering_a_field_with_invalid_render_method()
    {
        $this->setupTextAndPasswordFieldTypes();

        $this->setExpectedException(Exception::class, 'Render method `foobar` for Text Field does not exist.');
        $this->fieldManager->create('text', 'attribute', null, [])->render('foobar');
    }

    public function test_field_type_does_not_exist()
    {
        $this->setupNoFieldTypes();

        $this->assertFalse($this->fieldManager->typeExists('text'));
        $this->assertFalse($this->fieldManager->typeExists('password'));
    }

    public function test_field_type_exists()
    {
        $this->setupTextAndPasswordFieldTypes();

        $this->assertTrue($this->fieldManager->typeExists(TextField::class));
        $this->assertTrue($this->fieldManager->typeExists('text'));
        $this->assertTrue($this->fieldManager->typeExists('password'));
    }

    public function test_retrieving_all_available_field_types_returns_none_when_empty()
    {
        // Empty field config should return empty array
        $this->setupNoFieldTypes();
        $types = $this->fieldManager->availableTypes();
        $this->assertTrue(is_array($types));
        $this->assertEmpty($types);
    }

    public function test_retrieving_all_available_field_types_returns_types_when_available()
    {
        // Defined field config should return array of field types
        $this->setupTextAndPasswordFieldTypes();
        $types = $this->fieldManager->availableTypes();
        $this->assertTrue(is_array($types));
        $this->assertCount(2, $types);
        $this->assertArrayHasKey('password', $types);
        $this->assertArrayHasKey('text', $types);
        $this->assertContains(\LaravelFlare\Fields\Types\PasswordField::class, $types);
        $this->assertContains(\LaravelFlare\Fields\Types\TextField::class, $types);
    }
}
<file_sep><?php

namespace LaravelFlare\Fields;

use LaravelFlare\Flare\Flare;
use LaravelFlare\Fields\Types\BaseField;

class FieldManager
{
    /**
     * Flare.
     *
     * @var Flare
     */
    protected $flare;

    /**
     * __construct.
     *
     * @param Flare $flare
     */
    public function __construct(Flare $flare)
    {
        $this->flare = $flare;
    }

    /**
     * Create a new Field Instance.
     *
     * @param string $type
     * @param string $action
     * @param string $attribute
     * @param string $field
     * @param array  $options
     */
    public function create($type, $attribute, $value = null, $options = [])
    {
        if ($this->typeExists($type)) {
            $fieldType = $this->resolveField($type);

            return new $fieldType($type, $attribute, $value, $options);
        }

        return new BaseField($type, $attribute, $value, $options);
    }

    /**
     * Render a Field.
     *
     * @param string $type
     * @param string $attribute
     * @param string $field
     * @param string $options
     *
     * @return \Illuminate\Http\Response
     */
    public function render($action, $type, $attribute, $value = null, $options = [])
    {
        if (!isset($type)) {
            throw new \Exception('Field Type cannot be empty or undefined.');
        }

        return call_user_func_array([$this->create($type, $attribute, $value, $options), camel_case('render_'.$action)], []);
    }

    /**
     * Determines if a Field type class exists or not.
     *
     * @param string $type
     *
     * @return bool
     */
    public function typeExists($type)
    {
        return $this->resolveField($type) ? true : false;
    }

    /**
     * Returns an array of all of the available Field Types.
     *
     * @return array
     */
    public function availableTypes()
    {
        $fields = [];

        foreach ($this->config()['types'] as $type => $classname) {
            $fields = array_add($fields, $type, $classname);
        }

        return $fields;
    }

    /**
     * Return the Fields Config.
     * 
     * @return array
     */
    public function config()
    {
        return $this->flare->config('fields');
    }

    /**
     * Resolves the Class of a Field and returns it as a string.
     *
     * @param string $type
     *
     * @return string
     */
    private function resolveField($type)
    {
        if (array_key_exists($type, $this->availableTypes())) {
            return $this->availableTypes()[$type];
        }

        if (class_exists($type)) {
            return $type;
        }

        return false;
    }
}
<file_sep><?php

class RadioFieldTest extends BaseTest
{
	public function test_to_come()
	{
		$this->markTestIncomplete('test_to_come');
	}
}
<file_sep><?php

class WysiwygFieldTest extends BaseTest
{
	public function test_to_come()
	{
		$this->markTestIncomplete('test_to_come');
	}
}
<file_sep><?php

use Mockery as m;
use Illuminate\Contracts\View\Factory as ViewFactory;
use Illuminate\Support\Facades\Request;
use Illuminate\Support\ViewErrorBag;
use Illuminate\Support\MessageBag;
use LaravelFlare\Fields\FieldManager;

abstract class BaseTest extends \Orchestra\Testbench\TestCase
{
    protected $flare;

    protected $fieldManager;

    protected function setupField($name, $class)
    {
        $this->fieldManager = new FieldManager($this->flare);

        $this->flare->shouldReceive('config')
                    ->with('fields.types')
                    ->andReturn([$name => $class]);
    }

    protected function setupNoFieldTypes()
    {
        $this->fieldManager = new FieldManager($this->flare);

        // Empty field config should return empty array
        $this->flare->shouldReceive('config')
                    ->with('fields.types')
                    ->andReturn([]);
    }

    protected function setupTextAndPasswordFieldTypes()
    {
        $this->fieldManager = new FieldManager($this->flare);

        $this->flare->shouldReceive('config')
                    ->with('fields.types')
                    ->andReturn([
                        'password' => \LaravelFlare\Fields\Types\PasswordField::class,
                        'text' => \LaravelFlare\Fields\Types\TextField::class,
                    ]);
    }

    protected function setErrors($key, $messages)
    {
        $messageBag = new MessageBag([$key => $messages]);

        app(ViewFactory::class)->share('errors', (new ViewErrorBag)->put('default', $messageBag));
    }

    public function setUp()
    {
        parent::setUp();

        $this->app
            ->make(\Illuminate\Contracts\Http\Kernel::class)
            ->pushMiddleware(\Illuminate\Session\Middleware\StartSession::class);

        Request::setSession($this->app['session.store']);

        app(ViewFactory::class)->share('errors', Request::session()->get('errors') ?: new ViewErrorBag);

        $this->app['view']->addNamespace('flare', __DIR__.'/../src/resources/views');

        $this->flare = m::mock(\LaravelFlare\Flare\Flare::class);
    }

    public function tearDown()
    {
        parent::tearDown();

        m::close();
    }
}
<file_sep><?php

use LaravelFlare\Fields\FieldManager;
use LaravelFlare\Fields\Types\TextareaField;
use Illuminate\Contracts\View\Factory as ViewFactory;

class TextareaFieldTest extends BaseTest
{
    protected $fieldManager;

    public function test_textarea_field_render_methods()
    {
        $this->setupField('textarea', TextareaField::class);

        $this->assertContains('<textarea', $this->fieldManager->render('add', 'textarea', 'new_attribute', null, [])->render());
        $this->assertContains('<textarea', $this->fieldManager->render('edit', 'textarea', 'new_attribute', null, [])->render());
        $this->assertContains('<textarea', $this->fieldManager->render('clone', 'textarea', 'new_attribute', null, [])->render());
        $this->assertContains('New Attribute', $this->fieldManager->render('view', 'textarea', 'new_attribute', null, [])->render());
    }

    public function test_textarea_field_attribute_title()
    {
        $this->setupField('textarea', TextareaField::class);

        $this->assertContains('Attribute Title', $this->fieldManager->render('add', 'textarea', 'attribute_title', null, [])->render());
        $this->assertContains('Attribute Title', $this->fieldManager->render('edit', 'textarea', 'attribute_title', null, [])->render());
        $this->assertContains('Attribute Title', $this->fieldManager->render('clone', 'textarea', 'attribute_title', null, [])->render());
        $this->assertContains('Attribute Title', $this->fieldManager->render('view', 'textarea', 'attribute_title', null, [])->render());
    }

    public function test_textarea_field_is_required()
    {
        $this->setupField('textarea', TextareaField::class);

        $options = ['required' => true];

        $this->assertContains('required="required"', $this->fieldManager->render('add', 'textarea', 'attribute_title', null, $options)->render());
        $this->assertContains('required="required"', $this->fieldManager->render('edit', 'textarea', 'attribute_title', null, $options)->render());
        $this->assertContains('required="required"', $this->fieldManager->render('clone', 'textarea', 'attribute_title', null, $options)->render());

        $this->assertContains('This field is required', $this->fieldManager->render('add', 'textarea', 'attribute_title', null, $options)->render());
        $this->assertContains('This field is required', $this->fieldManager->render('edit', 'textarea', 'attribute_title', null, $options)->render());
        $this->assertContains('This field is required', $this->fieldManager->render('clone', 'textarea', 'attribute_title', null, $options)->render());
    }

    public function test_textarea_field_has_tooltip()
    {
        $this->setupField('textarea', TextareaField::class);

        $options = ['tooltip' => null];

        $this->assertNotContains('data-toggle="tooltip"', $this->fieldManager->render('add', 'textarea', 'attribute_title', null, $options)->render());
        $this->assertNotContains('data-toggle="tooltip"', $this->fieldManager->render('edit', 'textarea', 'attribute_title', null, $options)->render());
        $this->assertNotContains('data-toggle="tooltip"', $this->fieldManager->render('clone', 'textarea', 'attribute_title', null, $options)->render());

        $options = ['tooltip' => 'This is the Attribute Title Field.'];

        $this->assertContains('data-original-title="This is the Attribute Title Field."', $this->fieldManager->render('add', 'textarea', 'attribute_title', null, $options)->render());
        $this->assertContains('data-original-title="This is the Attribute Title Field."', $this->fieldManager->render('edit', 'textarea', 'attribute_title', null, $options)->render());
        $this->assertContains('data-original-title="This is the Attribute Title Field."', $this->fieldManager->render('clone', 'textarea', 'attribute_title', null, $options)->render());
    }

    public function test_textarea_field_with_defined_classes()
    {
        $this->setupField('textarea', TextareaField::class);

        $options = ['class' => null];

        $this->assertContains('class="form-control "', $this->fieldManager->render('add', 'textarea', 'attribute_title', null, $options)->render());
        $this->assertContains('class="form-control "', $this->fieldManager->render('edit', 'textarea', 'attribute_title', null, $options)->render());
        $this->assertContains('class="form-control "', $this->fieldManager->render('clone', 'textarea', 'attribute_title', null, $options)->render());

        $options = ['class' => 'example-class another-class'];

        $this->assertContains('class="form-control example-class another-class"', $this->fieldManager->render('add', 'textarea', 'attribute_title', null, $options)->render());
        $this->assertContains('class="form-control example-class another-class"', $this->fieldManager->render('edit', 'textarea', 'attribute_title', null, $options)->render());
        $this->assertContains('class="form-control example-class another-class"', $this->fieldManager->render('clone', 'textarea', 'attribute_title', null, $options)->render());
    }

    public function test_textarea_field_has_maxlength()
    {      
        $this->setupField('textarea', TextareaField::class);

        $options = ['maxlength' => null];

        $this->assertNotContains('maxlength', $this->fieldManager->render('add', 'textarea', 'attribute_title', null, $options)->render());
        $this->assertNotContains('maxlength', $this->fieldManager->render('edit', 'textarea', 'attribute_title', null, $options)->render());
        $this->assertNotContains('maxlength', $this->fieldManager->render('clone', 'textarea', 'attribute_title', null, $options)->render());

        $options = ['maxlength' => 30];

        $this->assertContains('maxlength="30"', $this->fieldManager->render('add', 'textarea', 'attribute_title', null, $options)->render());
        $this->assertContains('maxlength="30"', $this->fieldManager->render('edit', 'textarea', 'attribute_title', null, $options)->render());
        $this->assertContains('maxlength="30"', $this->fieldManager->render('clone', 'textarea', 'attribute_title', null, $options)->render());
    }

    public function test_textarea_field_is_disabled()
    {
        $this->setupField('textarea', TextareaField::class);

        $options = ['disabled' => null];

        $this->assertNotContains('disabled', $this->fieldManager->render('add', 'textarea', 'attribute_title', null, $options)->render());
        $this->assertNotContains('disabled', $this->fieldManager->render('edit', 'textarea', 'attribute_title', null, $options)->render());
        $this->assertNotContains('disabled', $this->fieldManager->render('clone', 'textarea', 'attribute_title', null, $options)->render());

        $options = ['disabled' => true];

        $this->assertContains('disabled="disabled"', $this->fieldManager->render('add', 'textarea', 'attribute_title', null, $options)->render());
        $this->assertContains('disabled="disabled"', $this->fieldManager->render('edit', 'textarea', 'attribute_title', null, $options)->render());
        $this->assertContains('disabled="disabled"', $this->fieldManager->render('clone', 'textarea', 'attribute_title', null, $options)->render());
    }

    public function test_textarea_field_is_readonly()
    {
        $this->setupField('textarea', TextareaField::class);

        $options = ['readonly' => null];

        $this->assertNotContains('readonly', $this->fieldManager->render('add', 'textarea', 'attribute_title', null, $options)->render());
        $this->assertNotContains('readonly', $this->fieldManager->render('edit', 'textarea', 'attribute_title', null, $options)->render());
        $this->assertNotContains('readonly', $this->fieldManager->render('clone', 'textarea', 'attribute_title', null, $options)->render());

        $options = ['readonly' => true];

        $this->assertContains('readonly="readonly"', $this->fieldManager->render('add', 'textarea', 'attribute_title', null, $options)->render());
        $this->assertContains('readonly="readonly"', $this->fieldManager->render('edit', 'textarea', 'attribute_title', null, $options)->render());
        $this->assertContains('readonly="readonly"', $this->fieldManager->render('clone', 'textarea', 'attribute_title', null, $options)->render());
    }

    public function test_textarea_field_has_autofocus()
    {
        $this->setupField('textarea', TextareaField::class);

        $options = ['autofocus' => null];

        $this->assertNotContains('autofocus', $this->fieldManager->render('add', 'textarea', 'attribute_title', null, $options)->render());
        $this->assertNotContains('autofocus', $this->fieldManager->render('edit', 'textarea', 'attribute_title', null, $options)->render());
        $this->assertNotContains('autofocus', $this->fieldManager->render('clone', 'textarea', 'attribute_title', null, $options)->render());

        $options = ['autofocus' => true];

        $this->assertContains('autofocus="autofocus"', $this->fieldManager->render('add', 'textarea', 'attribute_title', null, $options)->render());
        $this->assertContains('autofocus="autofocus"', $this->fieldManager->render('edit', 'textarea', 'attribute_title', null, $options)->render());
        $this->assertContains('autofocus="autofocus"', $this->fieldManager->render('clone', 'textarea', 'attribute_title', null, $options)->render());
    }

    public function test_textarea_field_has_placeholder()
    {        
        $this->setupField('textarea', TextareaField::class);

        $options = ['placeholder' => null];

        $this->assertNotContains('placeholder', $this->fieldManager->render('add', 'textarea', 'attribute_title', null, $options)->render());
        $this->assertNotContains('placeholder', $this->fieldManager->render('edit', 'textarea', 'attribute_title', null, $options)->render());
        $this->assertNotContains('placeholder', $this->fieldManager->render('clone', 'textarea', 'attribute_title', null, $options)->render());

        $options = ['placeholder' => 'Input your Attribute Title'];

        $this->assertContains('placeholder="Input your Attribute Title"', $this->fieldManager->render('add', 'textarea', 'attribute_title', null, $options)->render());
        $this->assertContains('placeholder="Input your Attribute Title"', $this->fieldManager->render('edit', 'textarea', 'attribute_title', null, $options)->render());
        $this->assertContains('placeholder="Input your Attribute Title"', $this->fieldManager->render('clone', 'textarea', 'attribute_title', null, $options)->render());
    }

    public function test_textarea_field_has_help_text()
    {      
        $this->setupField('textarea', TextareaField::class);

        $options = ['help' => null];

        $this->assertNotContains('help-block', $this->fieldManager->render('add', 'textarea', 'attribute_title', null, $options)->render());
        $this->assertNotContains('help-block', $this->fieldManager->render('edit', 'textarea', 'attribute_title', null, $options)->render());
        $this->assertNotContains('help-block', $this->fieldManager->render('clone', 'textarea', 'attribute_title', null, $options)->render());

        $options = ['help' => 'Please enter your <strong>Attribute Title</strong>'];

        $this->assertContains('<p class="help-block">Please enter your <strong>Attribute Title</strong></p>', $this->fieldManager->render('add', 'textarea', 'attribute_title', null, $options)->render());
        $this->assertContains('<p class="help-block">Please enter your <strong>Attribute Title</strong></p>', $this->fieldManager->render('edit', 'textarea', 'attribute_title', null, $options)->render());
        $this->assertContains('<p class="help-block">Please enter your <strong>Attribute Title</strong></p>', $this->fieldManager->render('clone', 'textarea', 'attribute_title', null, $options)->render());
    }

    public function test_textarea_field_displays_first_error()
    {
        $this->setupField('textarea', TextareaField::class);

        $this->setErrors('attribute_title', ['Error 1', 'Error 2']);

        $this->assertContains('Error 1', $this->fieldManager->render('add', 'textarea', 'attribute_title', 'Aden Fraser', [])->render());
        $this->assertContains('Error 1', $this->fieldManager->render('edit', 'textarea', 'attribute_title', 'Aden Fraser', [])->render());
        $this->assertContains('Error 1', $this->fieldManager->render('clone', 'textarea', 'attribute_title', 'Aden Fraser', [])->render());

        $this->assertNotContains('Error 2', $this->fieldManager->render('add', 'textarea', 'attribute_title', 'Aden Fraser', [])->render());
        $this->assertNotContains('Error 2', $this->fieldManager->render('edit', 'textarea', 'attribute_title', 'Aden Fraser', [])->render());
        $this->assertNotContains('Error 2', $this->fieldManager->render('clone', 'textarea', 'attribute_title', 'Aden Fraser', [])->render());
    }

    public function test_textarea_field_has_error_class()
    {
        $this->setupField('textarea', TextareaField::class);

        $this->setErrors('attribute_title', ['Error 1', 'Error 2']);

        $this->assertContains('<div class="form-group  has-error', $this->fieldManager->render('add', 'textarea', 'attribute_title', 'Aden Fraser', [])->render());
        $this->assertContains('<div class="form-group  has-error', $this->fieldManager->render('edit', 'textarea', 'attribute_title', 'Aden Fraser', [])->render());
        $this->assertContains('<div class="form-group  has-error', $this->fieldManager->render('clone', 'textarea', 'attribute_title', 'Aden Fraser', [])->render());
    }

    public function test_textarea_field_has_error_icon()
    {
        $this->setupField('textarea', TextareaField::class);

        $this->setErrors('attribute_title', ['Error 1', 'Error 2']);

        $this->assertContains('<i class="fa fa-times-circle-o"></i>', $this->fieldManager->render('add', 'textarea', 'attribute_title', 'Aden Fraser', [])->render());
        $this->assertContains('<i class="fa fa-times-circle-o"></i>', $this->fieldManager->render('edit', 'textarea', 'attribute_title', 'Aden Fraser', [])->render());
        $this->assertContains('<i class="fa fa-times-circle-o"></i>', $this->fieldManager->render('clone', 'textarea', 'attribute_title', 'Aden Fraser', [])->render());
    }   
}
<file_sep><?php

return [
    /*
    |--------------------------------------------------------------------------
    | Flare Fields
    |--------------------------------------------------------------------------
    |
    | This array of Field classes allows you to define all of the
    | available field types that you have available.
    |
    | You can add your own custom field types here, replace or even remove
    | some of the defaults. Each type requires a unique key in order to
    | allow you to reference the class in a shorthand fashion.
    |
    */
    'types' => [
        'autocomplete' => \LaravelFlare\Fields\Types\AutoCompleteField::class,
        'checkbox' => \LaravelFlare\Fields\Types\CheckboxField::class,
        'date' => \LaravelFlare\Fields\Types\DateField::class,
        'datetime' => \LaravelFlare\Fields\Types\DateTimeField::class,
        'email' => \LaravelFlare\Fields\Types\EmailField::class,
        'file' => \LaravelFlare\Fields\Types\FileField::class,
        'hidden' => \LaravelFlare\Fields\Types\HiddenField::class,
        'image' => \LaravelFlare\Fields\Types\ImageField::class,
        'map' => \LaravelFlare\Fields\Types\MapField::class,
        'password' => \LaravelFlare\Fields\Types\PasswordField::class,
        'radio' => \LaravelFlare\Fields\Types\RadioField::class,
        'select' => \LaravelFlare\Fields\Types\SelectField::class,
        'textarea' => \LaravelFlare\Fields\Types\TextareaField::class,
        'text' => \LaravelFlare\Fields\Types\TextField::class,
        'textmask' => \LaravelFlare\Fields\Types\TextMaskField::class,
        'time' => \LaravelFlare\Fields\Types\TimeField::class,
        'wysiwyg' => \LaravelFlare\Fields\Types\WysiwygField::class,
    ],

    /*
    |--------------------------------------------------------------------------
    | Field Options
    |--------------------------------------------------------------------------
    |
    | Configuration for specific Field Types.
    |
    */
    'options' => [

        /**
         * Map Field Options.
         *
         * Google API Key is required for the map field.
         */
        'map' => [
            'google_api_key' => null,
        ],

    ],
];
