<?php

use AdamWathan\Form\Elements\FormOpen;

class FormOpenTest extends PHPUnit_Framework_TestCase
{
    public function testFormCanBeCreated()
    {
        $form = new FormOpen;
    }

    public function testRenderBasicFormOpen()
    {
        $form = new FormOpen;
        $expected = '<form method="POST" action="">';
        $result = $form->render();

        $this->assertEquals($expected, $result);
    }

    public function testRenderPostFormOpen()
    {
        $form = new FormOpen;
        $expected = '<form method="POST" action="">';
        $result = $form->post()->render();

        $this->assertEquals($expected, $result);
    }

    public function testRenderGetFormOpen()
    {
        $form = new FormOpen;
        $expected = '<form method="GET" action="">';
        $result = $form->get()->render();

        $this->assertEquals($expected, $result);
    }

    public function testRenderPutFormOpen()
    {
        $form = new FormOpen;
        $expected = '<form method="POST" action=""><input type="hidden" name="_method" value="PUT">';
        $result = $form->put()->render();

        $this->assertEquals($expected, $result);
    }

    public function testRenderPatchFormOpen()
    {
        $form = new FormOpen;
        $expected = '<form method="POST" action=""><input type="hidden" name="_method" value="PATCH">';
        $result = $form->patch()->render();

        $this->assertEquals($expected, $result);
    }

    public function testRenderDeleteFormOpen()
    {
        $form = new FormOpen;
        $expected = '<form method="POST" action=""><input type="hidden" name="_method" value="DELETE">';
        $result = $form->delete()->render();

        $this->assertEquals($expected, $result);
    }

    public function testSetAction()
    {
        $form = new FormOpen;
        $expected = '<form method="POST" action="/test">';
        $result = $form->action('/test')->render();

        $this->assertEquals($expected, $result);
    }

    public function testSetCustomAttribute()
    {
        $form = new FormOpen;
        $expected = '<form method="POST" action="" data-test="sample">';
        $result = $form->attribute('data-test', 'sample')->render();

        $this->assertEquals($expected, $result);
    }

    public function testClearCustomAttribute()
    {
        $form = new FormOpen;
        $expected = '<form method="POST" action="">';
        $result = $form->attribute('data-test', 'sample')->clear('data-test')->render();

        $this->assertEquals($expected, $result);
    }

    public function testMultipart()
    {
        $form = new FormOpen;
        $expected = '<form method="POST" action="" enctype="multipart/form-data">';
        $result = $form->multipart()->render();

        $this->assertEquals($expected, $result);
    }

    public function testEncodingType()
    {
        $form = new FormOpen;
        $expected = '<form method="POST" action="" enctype="custom">';
        $result = $form->encodingType('custom')->render();

        $this->assertEquals($expected, $result);
    }

    public function testCanRenderCsrfToken()
    {
        $open = new FormOpen;
        $expected = '<form method="POST" action=""><input type="hidden" name="_token" value="abc123">';
        $result = (string) $open->token('abc123');

        $this->assertEquals($expected, $result);
    }

    public function testRenderCustomMethodWithToken()
    {
        $open = new FormOpen;
        $expected = '<form method="POST" action=""><input type="hidden" name="_token" value="abc123"><input type="hidden" name="_method" value="DELETE">';
        $result = $open->token('abc123')->delete()->render();

        $this->assertEquals($expected, $result);
    }
}
