Newer
Older
<?php
namespace calderawp\CalderaFormsQuery\Tests\Integration;
use calderawp\CalderaFormsQuery\EntryQueries;
use calderawp\CalderaFormsQuery\Tests\Traits\CanCreateEntryWithEmailField;
9
10
11
12
13
14
15
16
17
18
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
60
61
use calderawp\CalderaFormsQuery\Tests\Traits\HasFactories;
use calderawp\CalderaFormsQuery\Tests\Traits\UsersMockFormAsDBForm;
class EntryQueriesTest extends IntegrationTestCase
{
use UsersMockFormAsDBForm;
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();
}
/**
* Test that getResults method runs queries against WordPress correctly
*
* @covers EntryQueries::getResults()
*/
public function testGetResultsCanDoSQL(){
$details = $this->create_entry( $this->mock_form );
$details = $this->create_entry( $this->mock_form );
global $wpdb;
$sql = $wpdb->prepare( "SELECT COUNT(`id`) AS `total` FROM `" . $wpdb->prefix . "cf_form_entries` WHERE `form_id` = %s", $this->mock_form_id );
$results = $this->entryQueriesFactory()->getResults( $sql );
$this->assertTrue( ! empty( $results ) );
$this->assertEquals( 2, $results[0]->total);
$wpdbDirectResults = $wpdb->get_results( $sql );
$this->assertEquals( 2, $wpdbDirectResults[0]->total);
}
/**
* Test that we can run queries and the environment can update DB
*
* @covers EntryQueries::getResults()
*/
public function testCanQuery()
{
global $wpdb;
$sql = $wpdb->prepare( "SELECT COUNT(`id`) AS `total` FROM `" . $wpdb->prefix . "cf_form_entries` WHERE `form_id` = %s", $this->mock_form_id );
$resultsOne = $this->entryQueriesFactory()->getResults( $sql );
$this->assertTrue( ! empty( $resultsOne ) );
$entry_details = $this->create_entry( $this->mock_form );
$sql = $wpdb->prepare("SELECT * FROM `" . $wpdb->prefix . "cf_form_entries` WHERE `id` = %s", $entry_details['id'] );
$resultsTwo = $this->entryQueriesFactory()->getResults( $sql );
$this->assertTrue( ! empty( $resultsTwo ), var_export( $resultsTwo, true ) );
}