Skip to content
Snippets Groups Projects
Select Git revision
  • 1502ed6377514bf22e2999be2caa829db3d22f22
  • master default protected
  • fix/woo-stubs-dir
  • default-packages
  • use-internal-packages
  • update-setup
  • feature/wpdesk-cs
  • 2.5.3
  • 2.5.2
  • 2.5.1
  • 2.5.0
  • 2.4.2
  • 2.4.1
  • 2.4.0
  • 2.3
  • 2.2.1
  • 2.2
  • 2.1
  • 2.0
  • 1.10.15
  • 1.10.12
  • 1.10.8
  • 1.10.7
  • 1.10.6
  • 1.10.5
  • 1.10.3
  • 1.10.2
27 results

plugin-template.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());
    	}
    }