| 1 |
<?php |
| 2 |
/** |
| 3 |
* Class SampleTest |
| 4 |
* |
| 5 |
* @package |
| 6 |
*/ |
| 7 |
|
| 8 |
/** |
| 9 |
* Sample test case. |
| 10 |
*/ |
| 11 |
class SampleTest extends WP_UnitTestCase { |
| 12 |
public $apikey = 'a885bcc7f6edcd28f0060ac9b336312d-us3'; |
| 13 |
public $list_id = ''; |
| 14 |
|
| 15 |
function test_missing_apikey() { |
| 16 |
$apikey = 'asdf'; |
| 17 |
$api = new MailChimp_API($apikey); |
| 18 |
$key = mailchimpSF_verify_key($api); |
| 19 |
|
| 20 |
$this->assertTrue(is_wp_error($key)); |
| 21 |
} |
| 22 |
|
| 23 |
function test_correct_apikey() { |
| 24 |
$apikey = $this->apikey; // REMOVE ME. |
| 25 |
try { |
| 26 |
$api = new MailChimp_API($apikey); |
| 27 |
$value = true; |
| 28 |
} catch (Exception $e) { |
| 29 |
$value = false; |
| 30 |
} |
| 31 |
|
| 32 |
$this->assertTrue($value); |
| 33 |
} |
| 34 |
|
| 35 |
function test_missing_required_merge_vars() { |
| 36 |
$fname = array( |
| 37 |
'tag' => 'FNAME', |
| 38 |
'name' => 'First Name', |
| 39 |
'type' => 'text', |
| 40 |
'required' => 'Y' |
| 41 |
); |
| 42 |
|
| 43 |
$merge_vars[] = $fname; |
| 44 |
|
| 45 |
$submit = mailchimpSF_merge_submit($merge_vars); |
| 46 |
|
| 47 |
// Merge value defaults to empty string, which should error |
| 48 |
$this->assertTrue(is_wp_error($submit)); |
| 49 |
$this->assertTrue(is_object($submit)); |
| 50 |
} |
| 51 |
|
| 52 |
function test_required_merge_var() { |
| 53 |
$name = 'mc_mv_FNAME'; |
| 54 |
$fname = array( |
| 55 |
'tag' => 'FNAME', |
| 56 |
'name' => 'First Name', |
| 57 |
'type' => 'text', |
| 58 |
'required' => 'Y' |
| 59 |
); |
| 60 |
$merge_vars[] = $fname; |
| 61 |
$_POST[$name] = 'Hello World'; |
| 62 |
|
| 63 |
$submit = mailchimpSF_merge_submit($merge_vars); |
| 64 |
|
| 65 |
$this->assertFalse(is_wp_error($submit)); |
| 66 |
$this->assertTrue(is_object($submit)); |
| 67 |
} |
| 68 |
|
| 69 |
function test_invalid_phone_number() { |
| 70 |
$var['name'] = 'Phone'; |
| 71 |
$value = array('asd','555','1234'); |
| 72 |
$phone = mailchimpSF_merge_validate_phone($value, $var); |
| 73 |
|
| 74 |
$this->assertTrue(is_wp_error($phone)); |
| 75 |
$this->assertTrue(is_object($phone)); |
| 76 |
} |
| 77 |
|
| 78 |
function test_valid_phone_number() { |
| 79 |
$var['name'] = 'Phone'; |
| 80 |
$value = array('123','456','7890'); |
| 81 |
$phone = mailchimpSF_merge_validate_phone($value, $var); |
| 82 |
|
| 83 |
$this->assertFalse(is_wp_error($phone)); |
| 84 |
$this->assertTrue(is_string($phone)); |
| 85 |
} |
| 86 |
|
| 87 |
function test_invalid_address() { |
| 88 |
$var = array( |
| 89 |
'tag' => 'ADDRESS', |
| 90 |
'name' => 'Address', |
| 91 |
'type' => 'Address', |
| 92 |
'required' => 'Y' |
| 93 |
); |
| 94 |
$value = array( |
| 95 |
'addr1' => '123 Magic Street' |
| 96 |
); |
| 97 |
$submit = mailchimpSF_merge_validate_address($value, $var); |
| 98 |
|
| 99 |
$this->assertTrue(is_wp_error($submit)); |
| 100 |
$this->assertTrue(is_object($submit)); |
| 101 |
} |
| 102 |
|
| 103 |
function test_remove_empty_merge_feilds() { |
| 104 |
$merge = new StdClass(); |
| 105 |
$merge->fname = 'test'; |
| 106 |
$merge->test = ' '; |
| 107 |
$merge->hello = null; |
| 108 |
|
| 109 |
$submit = mailchimpSF_merge_remove_empty($merge); |
| 110 |
|
| 111 |
$this->assertTrue($merge->fname === $submit->fname); |
| 112 |
$this->assertTrue(empty($submit->test)); |
| 113 |
$this->assertTrue(empty($submit->hello)); |
| 114 |
} |
| 115 |
|
| 116 |
function test_delete_everything() { |
| 117 |
$fname = array( |
| 118 |
'tag' => 'FNAME', |
| 119 |
'name' => 'First Name', |
| 120 |
'type' => 'text', |
| 121 |
'required' => 'Y' |
| 122 |
); |
| 123 |
|
| 124 |
$ig = array( |
| 125 |
'id' => '123' |
| 126 |
); |
| 127 |
|
| 128 |
$igs[] = $ig; |
| 129 |
|
| 130 |
update_option('mc_list_id', '123'); |
| 131 |
update_option('mc_list_name', 'asdf'); |
| 132 |
update_option('mc_interest_groups', $igs); |
| 133 |
update_option('mc_merge_vars', array($fname)); |
| 134 |
update_option('mc_show_interest_groups_123', 'on'); |
| 135 |
update_option('mc_mv_FNAME', $fname); |
| 136 |
|
| 137 |
$this->assertTrue(is_string(get_option('mc_list_id'))); |
| 138 |
$this->assertTrue(is_string(get_option('mc_list_name'))); |
| 139 |
$this->assertTrue(is_string(get_option('mc_show_interest_groups_123'))); |
| 140 |
$this->assertTrue(is_array(get_option('mc_mv_FNAME'))); |
| 141 |
|
| 142 |
mailchimpSF_delete_setup(); |
| 143 |
|
| 144 |
$this->assertFalse(get_option('mc_list_id')); |
| 145 |
$this->assertFalse(get_option('mc_list_name')); |
| 146 |
$this->assertFalse(get_option('mc_show_interest_groups_123')); |
| 147 |
$this->assertFalse(get_option('mc_mv_FNAME')); |
| 148 |
} |
| 149 |
|
| 150 |
function test_add_email_field() { |
| 151 |
$merge = array( |
| 152 |
array( |
| 153 |
'tag' => 'TEST', |
| 154 |
'name' => 'test', |
| 155 |
'type' => 'text', |
| 156 |
'required' => false, |
| 157 |
'public' => true, |
| 158 |
'display_order' => 2, |
| 159 |
'default_value' => null |
| 160 |
) |
| 161 |
); |
| 162 |
$merge = mailchimpSF_add_email_field($merge); |
| 163 |
|
| 164 |
$this->assertTrue($merge[0]['tag'] == 'EMAIL'); |
| 165 |
} |
| 166 |
|
| 167 |
} |