Newer
Older
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
{
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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;
}
/**
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
$this->entryGeneratorFactory(),
$this->entryValuesGeneratorFactory(),
$this->getWPDB()
);
}
/**
* Use $wpdb->get_results() to do a SQL query directly.
*
* @param $sql
* @return object|null
*/
protected function queryWithWPDB( $sql )
{
global $wpdb;
return $wpdb->get_results( $sql );
}
/**
*
*/
protected function deleteAllEntriesForMockForm()
{
$this->entryDeleteGeneratorFactory()->deleteByFormId($this->mock_form_id);
}
/**
* @return array
*/
protected function createEntryWithMockForm()
{
return $this->create_entry( $this->mock_form );
}
/**
* @return int
*/
protected function createEntryWithMockFormAndGetEntryId()
{
$details = $this->create_entry( $this->mock_form );
return $details[ 'id' ];
}