Newer
Older
1
2
3
4
5
6
7
8
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
<?php
namespace calderawp\CalderaFormsQuery\Tests\Traits;
/**
* Trait CreatesEntryWithEmailField
*
* Helper functions for testing entry by email
*/
trait CanCreateEntryWithEmailField
{
use \Caldera_Forms_Has_Mock_Form;
/**
* Create an entry associated with an email
*
* @param string $email
*
* @return int
*/
protected function createEntryWithEmail( $email = 'hiroy@hiroy.club' )
{
$fieldData = [];
$emailFieldConfig = $this->getEmailField();
foreach( $this->mock_form[ 'fields' ] as $fieldId => $fieldConfig ){
if ( $fieldId === $emailFieldConfig[ 'ID'] ) {
$fieldData[ $fieldId ] = $email;
} else {
$fieldData[ $fieldId ] = rand() . $fieldId;
}
}
return \Caldera_Forms_Save_Final::create_entry( $this->mock_form, $fieldData );
}
/**
* Get the email field's config array
*
* @return array|bool
*/
protected function getEmailField()
{
return \Caldera_Forms_Field_Util::get_field_by_slug( 'email', $this->mock_form );
}
/**
* Get slug of email field
*
* @return string
*/
protected function getEmailFieldSlug()
{
return $this->getEmailField()[ 'slug' ];
}
}