WP_Ajax_UnitTestCase::setUp PHP Method

setUp() public method

Override wp_die(), pretend to be ajax, and suppres E_WARNINGs
public setUp ( )
    public function setUp()
    {
        parent::setUp();
        add_filter('wp_die_ajax_handler', array($this, 'getDieHandler'), 1, 1);
        set_current_screen('ajax');
        // Clear logout cookies
        add_action('clear_auth_cookie', array($this, 'logout'));
        // Suppress warnings from "Cannot modify header information - headers already sent by"
        $this->_error_level = error_reporting();
        error_reporting($this->_error_level & ~E_WARNING);
        // Make some posts
        self::factory()->post->create_many(5);
    }

Usage Example

 /**
  * Set up the test fixture
  */
 public function setUp()
 {
     parent::setUp();
     $post_id = self::factory()->post->create();
     $this->_comments = self::factory()->comment->create_post_comments($post_id, 15);
     $this->_comments = array_map('get_comment', $this->_comments);
 }
All Usage Examples Of WP_Ajax_UnitTestCase::setUp