Skip to content
Snippets Groups Projects
Select Git revision
  • 87f91d1766ca55d814b3f479a9d697f1f0953ad1
  • master default protected
  • devel
  • feature/add-escaping-to-templates
  • feature/add-priority-sorting
  • 3.3.0
  • 3.2.1
  • 3.2.0
  • 3.1.0
  • 3.0.0
  • 2.4.12
  • 2.4.11
  • 2.4.10
  • 2.4.9
  • 2.4.8
  • 2.4.7
  • 2.4.6
  • 2.4.5
  • 2.4.4
  • 2.4.2
  • 2.4.1
  • 2.4.0
  • 2.3.2
  • 2.3.1
  • 2.3
25 results

Form.php

Blame
  • TestForm.php 1.41 KiB
    <?php
    
    namespace Tests;
    
    use WPDesk\Forms\AbstractForm;
    
    class TestForm extends \PHPUnit\Framework\TestCase
    {
    
    	const FORM1_ID                = 'test_form';
    	const FORM1_FORM_DATA         = [ 'test' => true ];
    	const FORM1_UPDATED_FORM_DATA = [ 'test666' => true ];
    
    	private $form;
    
    	protected function setUp(){
    		// Create a new instance from the Abstract Class
    		$this->form = $this->getMockBuilder( AbstractForm::class )
    		                   ->enableOriginalConstructor()
    		                   ->setMethods(['get_form_id'])
    		                   ->getMockForAbstractClass();
    		$this->form->method( 'get_form_id' )->willReturn( self::FORM1_ID );
    		$this->form->method( 'create_form_data' )->willReturn( self::FORM1_FORM_DATA );
    	}
    
    	protected function getForm(){
    		return clone $this->form;
    	}
    
        /**
         * Test getting form id.
         */
        public function testFormId()
        {
        	$form = $this->getForm();
    	    $this->assertEquals(self::FORM1_ID, $form->get_form_id());
        }
    
    	/**
    	 * Test getting form data.
    	 */
    	public function testFormData()
    	{
    		$form = $this->getForm();
    		$this->assertSame( self::FORM1_FORM_DATA, $form->get_form_data());
    	}
    
    	/**
    	 * Test updated form data.
    	 */
    	public function testUpdatedFormData()
    	{
    		$form = $this->getForm();
    
    		$form->update_form_data( self::FORM1_UPDATED_FORM_DATA );
    		$this->assertSame( array_merge( self::FORM1_FORM_DATA, self::FORM1_UPDATED_FORM_DATA ), $form->get_form_data());
    	}
    }