TestInputParser

Test input parser.

Contents

  • Methods

  • Source Source

    File: tests/test-class-automator-input-parser.php

    class TestInputParser extends WP_UnitTestCase {
    
        static $user_id;
    
    	public static function wpSetUpBeforeClass( $factory ) {
    
    		// This code will run once before all tests
            self::$user_id = $factory->user->create( array( 'role' => 'administrator' ) );
    	}
    
    	public function setUp() {
    		parent::setUp();
            
    		wp_set_current_user( self::$user_id );
    		// This code will run once before each test!
    		$this->importer = new Import_Recipe();
    	}
    
    	/**
    	 * Test if tokens are properly replaced when a WP post is viewed
    	 *
    	 */
    	public function test_replace_recipe_variables_VIEWPOST() {
        
    		$test_post = array(
    			'post_title'   => 'Test Post 1',
    			'post_content' => 'No content',
    			'post_status'  => 'publish',
    			'post_author'  => get_current_user_id(),
    		);
    
    		$post_id = wp_insert_post( $test_post );
    
    		$attachment = add_dummy_featured_image( $post_id );
    
    		$recipe_id = $this->importer->import_from_file( dirname( __FILE__ ) . '/recipes/VIEWPOST-CREATEPOST.json' );
    
    		$args = array(
    			'code'    => 'VIEWPOST',
    			'meta'    => 'WPPOST',
    			'post_id' => $post_id,
    			'user_id' => get_current_user_id(),
    		);
    
    		Automator()->process->user->maybe_add_trigger_entry( $args, true );
    
    		$recent_post = get_last_post( 'post' );
    
    		$this->assertStringContainsString( 'Post Title: Test Post 1', $recent_post['post_content'] );
    		$this->assertStringContainsString( 'Image URL: ' . $attachment['url'], $recent_post['post_content'] );
    		$this->assertStringContainsString( 'Image ID: ' . $attachment['attachment_id'], $recent_post['post_content'] );
    
    	}
    
    	function mock_learndash_enabled( $value, $option ) {
    		return array('sfwd-lms/sfwd_lms.php');
    	}
    
    
    }
    

    Methods Methods