Skip to content
Snippets Groups Projects
IntegrationTestCase.php 1.95 KiB
<?php


namespace calderawp\CalderaFormsQuery\Tests\Integration;

use calderawp\CalderaFormsQuery\SelectQueries;
use calderawp\CalderaFormsQuery\Tests\Traits\HasFactories;
use calderawp\CalderaFormsQuery\Tests\Traits\UsersMockFormAsDBForm;

/**
 * Class IntegrationTestCase
 *
 * All integration tests MUST extend this class
 *
 * @package CalderaLearn\RestSearch\Tests\Integration
 */
abstract class IntegrationTestCase extends \WP_UnitTestCase
{
	use \Caldera_Forms_Has_Data, HasFactories;

	public function setUp()
	{
		global $wpdb;
		$tables = new \Caldera_Forms_DB_Tables($wpdb);
		$tables->add_if_needed();
		$this->set_mock_form();
		$this->mock_form_id = \Caldera_Forms_Forms::import_form( $this->mock_form );
		$this->mock_form = \Caldera_Forms_Forms::get_form( $this->mock_form_id );
		parent::setUp();
	}

	/** @inheritdoc */
	public function tearDown()
	{
		//Delete entries
		$this->deleteAllEntriesForMockForm();
		//Delete all forms
		$forms = \Caldera_Forms_Forms::get_forms();
		if (!empty($forms)) {
			foreach ($forms as $form_id => $config) {
				\Caldera_Forms_Forms::delete_form($form_id);
			}
		}

		parent::tearDown();
	}

	/**
	 * Gets a WPDB instance
	 *
	 * @return \wpdb
	 */
	protected function getWPDB()
	{
		global $wpdb;
		return $wpdb;
	}

	/**
	 * @return SelectQueries
	 */
	protected function selectQueriesFactory()
	{

		return new SelectQueries(
			$this->entryGeneratorFactory(),
			$this->entryValuesGeneratorFactory(),
			$this->getWPDB()
		);
	}