diff --git a/addons/analytics.php b/addons/analytics.php index aff3017..a9cc31c 100644 --- a/addons/analytics.php +++ b/addons/analytics.php @@ -4,6 +4,7 @@ if(!defined('ABSPATH')) exit; add_action('admin_menu', 'vk_analytics_admin_page'); +require_once(__DIR__. '/mockClasses/mailingsHelpers.php'); function vk_analytics_admin_page() { add_menu_page( @@ -18,10 +19,10 @@ function vk_analytics_admin_page() { } function vk_analytics_admin_page_render() { - global $vk_mailings; + global $vk_mailings, $mh; // Calculate distributions - $distributions = $vk_mailings->get_distributions(); + $distributions = $vk_mailings->get_distributions(0, 0); foreach ($distributions['campaigns'] as &$campaign) { unset($campaign['fields']); } @@ -33,7 +34,7 @@ function vk_analytics_admin_page_render() { //$fields = $campaign['fields']; // $url = get_permalink($id); $limit_per_campaign = round($campaign['share'] * $limit_per_day); - $campaign['num_fresh_ids'] = sizeof($vk_mailings->get_fresh_subscribers_for_campaign($id, $limit_per_campaign)); + $campaign['num_fresh_ids'] = sizeof($mh->get_fresh_subscribers_for_campaign($id, $limit_per_campaign, 0)); } // Render diff --git a/addons/distributions.php b/addons/distributions.php index 9a403e8..aa61ae3 100644 --- a/addons/distributions.php +++ b/addons/distributions.php @@ -31,7 +31,7 @@ function vk_distributions_admin_page_render() { ); // Calculate distributions - $distributions = $vk_mailings->get_distributions(); + $distributions = $vk_mailings->get_distributions(0, 0); foreach ($distributions['campaigns'] as &$campaign) { unset($campaign['fields']); } diff --git a/addons/insider-view.php b/addons/insider-view.php new file mode 100644 index 0000000..5c79c6e --- /dev/null +++ b/addons/insider-view.php @@ -0,0 +1,115 @@ +each_mailing_distribution(0, 0); + foreach ($distributions['campaigns'] as &$campaign) { + unset($campaign['fields']); + } + + $limit_per_day = get_option('subscribed_users') / 7; + + foreach ($distributions['campaigns'] as &$campaign) { + $id = $campaign['id']; + //$fields = $campaign['fields']; + // $url = get_permalink($id); + $limit_per_campaign = round($campaign['share'] * $limit_per_day); + $campaign['num_fresh_ids'] = sizeof($mh->get_fresh_subscribers_for_campaign($id, $limit_per_campaign, 0)); + } + + // Render + ?> + + + +

Num subscribers in VK list:

+

Max limit to mail per day:

+ +

+ Current Campaigns +

+ + + + + + + + + + + + + + + + + + + + + + + + + + $b['rate'] ? -1 : 1); }); + foreach($campaign['subjects'] as $subject) { ?> + + + + + + + + + + + + + +
Campaign idName/subjectEmails sentConversionsLossesSuccess RateCurrent share of emails# users for next mailing
+ + 'campaign', - 'post_status' => 'publish', - )); - foreach ($results->posts as $campaign) { - $id = $campaign->ID; - $campaigns[$id] = array( - 'conversions' => 0, - 'fields' => get_fields($id), - 'id' => $id, - 'losses' => 0, - 'sent' => 0, - 'subjects' => array(), - 'title' => $campaign->post_title, - 'valid' => true, - ); - // Get all subjects - $subjects = $campaigns[$id]['fields']['subjects']; - for ($i = 0; $i < count($subjects); $i++) { - $campaigns[$id]['subjects'][$i] = array( - 'conversions' => 0, - 'losses' => 0, - 'sent' => 0, - ); - } - } + //**********investigate what comes back from wp_query_posts + $results = $mh->wp_query_posts($mh_mock); + + // $results1 = trim(preg_replace('/\s+/', ' ',var_export( $results, true))); + // var_dump($results1); + + // var_dump($mh); + $campaigns = $mh->setUpCampaigns($results, $campaigns, $mh_mock); // Get campaign performance $overall = array( @@ -59,19 +48,13 @@ function get_distributions() 'losses' => 0, 'sent' => 0, ); - $mailings = $wpdb->get_results(' - SELECT - vkm.campaign_id, - vkm.variation_subject, - SUM(vkm.conversions) as conversions, - SUM(vkm.losses) as losses, - SUM(vkm.sent) as sent - FROM - vk_mailing AS vkm - GROUP BY - vkm.campaign_id, vkm.variation_subject - ', ARRAY_A); + $mailings = $mh->get_mailings_results_wpdb($wpdb); + $mailingsPrint = trim(preg_replace('/\s+/', ' ',var_export( $mailings, true))); + + // need to print error log here + // $mailingsPrint = trim(preg_replace('/\s+/', ' ',var_export( $mailings, true))); + // error_log('$$$line 54 return value of get_results '.$mailingsPrint); foreach ($mailings as $mailing) { $id = $mailing['campaign_id']; @@ -80,7 +63,7 @@ function get_distributions() if (!isset($campaigns[$id])) { continue; } - + $overall['conversions'] += $mailing['conversions']; $overall['losses'] += $mailing['losses']; $overall['sent'] += $mailing['sent']; @@ -90,35 +73,58 @@ function get_distributions() $campaigns[$id]['sent'] += $mailing['sent']; $subject = $mailing['variation_subject']; + $campaigns[$id]['subjects'][$subject] = array( 'conversions' => +$mailing['conversions'], 'losses' => +$mailing['losses'], 'sent' => +$mailing['sent'], ); } + // $campaignsPrint = trim(preg_replace('/\s+/', ' ',var_export( $campaigns, true))); + // error_log('$$$line 54 return value of get_results '.$campaignsPrint); + echo $mailingsPrint; + // $campaignsPrint = trim(preg_replace('/\s+/', ' ',var_export( $campaigns, true))); + // error_log('$$$line 84 value of campaigns after loop '.$campaignsPrint); // This allows brand new campaigns to have a chance to succeed. // It probably is not needed if we are going to be sending each new campaign to more than several hundred people, // but it helps for testing with smaller amounts of people because it basically starts off the campaign at the same // rate as the overall campaign success rate and slightly adjusts from there - $boost = 500.0; + // $boost = BOOST; + $boost = get_option('boost'); + + if ($boost_test_value) { + $boost = $boost_test_value; + } + + echo '####'; + echo $boost; + $overall['boost'] = $boost; // Overall rate $overall['rate'] = ($overall['conversions'] - $overall['losses'] + $boost) / ($overall['sent'] + $boost); + + // $camp = trim(preg_replace('/\s+/', ' ',var_export( $campaigns, true))); + // error_log('line 199 campaigns setting stats overall with boost '.$camp); + // $arrayThing = ARRAY_A; + // $aThing = trim(preg_replace('/\s+/', ' ',var_export( $arrayThing, true))); + // error_log('line 80 Array_A value '.$aThing); + if ($overall['rate'] < 0) { $overall['rate'] = 0; // TODO: why would we not track negative results? } // Calculate shares $campaign_rate_sum = 0; + foreach ($campaigns as $campaign_index => &$campaign) { // Subjects $fields = $campaign['fields']; $subject_rate_sum = 0; $valid_subjects = 0; - - foreach ($campaign['subjects'] as $subject_index => &$subject) { + + foreach ($campaign['subjects'] as $subject_index => &$subject) { $enabled = $fields['subjects'][$subject_index]['enabled']; $subject['title'] = $fields['subjects'][$subject_index]['subject']; if (!$enabled) { @@ -184,27 +190,39 @@ function get_distributions() // Limit share percentages, based on subscriber availability $campaign_share_sum = 1; $limit_per_day = get_option('subscribed_users') / 7; - + foreach ($campaigns as $campaign_index => &$campaign) { + $limit_per_campaign = round($campaign['share'] * $limit_per_day); - $fresh_ids = count($this->get_fresh_subscribers_for_campaign($campaign['id'], $limit_per_campaign)); - + // $limit = trim(preg_replace('/\s+/', ' ',var_export($limit_per_campaign, true))); + // error_log('line 192 limit_per_campaign '.$limit); + $fresh_ids = count($mh->get_fresh_subscribers_for_campaign($campaign['id'], $limit_per_campaign, $wpdb_mock)); // Plenty? Great. + //fresh ids should not be 0 + if ($fresh_ids >= $limit_per_campaign) { $campaign['limit'] = $limit_per_campaign; continue; } - // Shortage of fresh IDs. Calculations are required. $campaign['limit'] = $fresh_ids; + //CURRENTLY RETURNING 0 FOR $SHARE THIS IS MAKING A NAN VALUE $share = $fresh_ids / $limit_per_day; + $campaign_share_sum += $share - $campaign['share']; + $campaign['share'] = $share; + + // $campShare = $campaign['share']; + // $allsql = trim(preg_replace('/\s+/', ' ',var_export( $campShare, true))); + // error_log('line 225 $campaign_share_sum '.$campaign_share_sum); + // error_log('line 226 variable campaing[share] '.$share); } + foreach ($campaigns as $campaign_index => &$campaign) { $campaign['share'] = $campaign['share'] / $campaign_share_sum; } - + usort($campaigns, function($a, $b) { $difference = $b['share'] - $a['share']; if ($difference == 0) { @@ -219,39 +237,232 @@ function get_distributions() return array( 'campaigns' => $campaigns, 'overall' => $overall, + 'boost@@@' => $boost_test_value, ); } - // Get all subscribers who have not been mailed for this campaign AND have not been mailed for any campaign within the last week - function get_fresh_subscribers_for_campaign($campaign_id, $limit) + function get_distributions($wpdb_mock, $mh_mock, $boost_test_value) { global $wpdb; + global $mh; + + if($wpdb_mock){ + $wpdb = $wpdb_mock; + $mh = $mh_mock; + } - $sql = " - SELECT - vks.ak_user_id - FROM - vk_subscriber AS vks - LEFT JOIN - vk_subscriber_mailing AS vksm - ON - vks.ak_user_id = vksm.ak_user_id AND - ( - vksm.campaign_id = $campaign_id - OR - vksm.created_at > DATE_SUB(NOW(), INTERVAL 1 WEEK) - ) - WHERE - vksm.ak_user_id IS NULL - LIMIT $limit; - "; - $response = $wpdb->get_col($sql, 0); - $ids = array_map(function($el) { - return +$el; - }, $response); - return $ids; + if (!get_option('subscribed_users')) { + // no subscribed users in DB yet + return array('campaigns' => array(), 'overall' => array()); + } + + // Get active campaigns + $campaigns = array(); + + //**********investigate what comes back from wp_query_posts + $results = $mh->wp_query_posts($mh_mock); + + // $results1 = trim(preg_replace('/\s+/', ' ',var_export( $results, true))); + // var_dump($results1); + + // var_dump($mh); + $campaigns = $mh->setUpCampaigns($results, $campaigns, $mh_mock); + + // Get campaign performance + $overall = array( + 'conversions' => 0, + 'losses' => 0, + 'sent' => 0, + ); + + $mailings = $mh->get_mailings_results_wpdb($wpdb); + $mailingsPrint = trim(preg_replace('/\s+/', ' ',var_export( $mailings, true))); + + // need to print error log here + // $mailingsPrint = trim(preg_replace('/\s+/', ' ',var_export( $mailings, true))); + // error_log('$$$line 277 return value of get_results '.$mailingsPrint); + foreach ($mailings as $mailing) { + $id = $mailing['campaign_id']; + + // Make sure to only include currently published campaigns in overall data + // TODO: why not just check for campaign published in query above? + if (!isset($campaigns[$id])) { + continue; + } + + $overall['conversions'] += $mailing['conversions']; + $overall['losses'] += $mailing['losses']; + $overall['sent'] += $mailing['sent']; + + $campaigns[$id]['conversions'] += $mailing['conversions']; + $campaigns[$id]['losses'] += $mailing['losses']; + $campaigns[$id]['sent'] += $mailing['sent']; + + $subject = $mailing['variation_subject']; + + $campaigns[$id]['subjects'][$subject] = array( + 'conversions' => +$mailing['conversions'], + 'losses' => +$mailing['losses'], + 'sent' => +$mailing['sent'], + ); + } + // $campaignsPrint = trim(preg_replace('/\s+/', ' ',var_export( $campaigns, true))); + // error_log('$$$line 54 return value of get_results '.$campaignsPrint); + // echo $mailingsPrint; + // $campaignsPrint = trim(preg_replace('/\s+/', ' ',var_export( $campaigns, true))); + // error_log('$$$line 84 value of campaigns after loop '.$campaignsPrint); + + // This allows brand new campaigns to have a chance to succeed. + // It probably is not needed if we are going to be sending each new campaign to more than several hundred people, + // but it helps for testing with smaller amounts of people because it basically starts off the campaign at the same + // rate as the overall campaign success rate and slightly adjusts from there + $boost = get_option('boost'); + + if($boost_test_value){ + $boost = $boost_test_value; + } + + $overall['boost'] = $boost; + + // Overall rate + $overall['rate'] = ($overall['conversions'] - $overall['losses'] + $boost) / ($overall['sent'] + $boost); + + // $camp = trim(preg_replace('/\s+/', ' ',var_export( $campaigns, true))); + // error_log('line 199 campaigns setting stats overall with boost '.$camp); + // $arrayThing = ARRAY_A; + // $aThing = trim(preg_replace('/\s+/', ' ',var_export( $arrayThing, true))); + // error_log('line 80 Array_A value '.$aThing); + + if ($overall['rate'] < 0) { + $overall['rate'] = 0; // TODO: why would we not track negative results? + } + + // Calculate shares + $campaign_rate_sum = 0; + + foreach ($campaigns as $campaign_index => &$campaign) { + // Subjects + $fields = $campaign['fields']; + $subject_rate_sum = 0; + $valid_subjects = 0; + + foreach ($campaign['subjects'] as $subject_index => &$subject) { + $enabled = $fields['subjects'][$subject_index]['enabled']; + $subject['title'] = $fields['subjects'][$subject_index]['subject']; + if (!$enabled) { + $subject['rate'] = 0; + continue; + } + + $valid_subjects++; + + $rate = ( + ($subject['conversions'] - $subject['losses'] + $boost * $overall['rate']) + / + ($subject['sent'] + $boost) + ); + + if ($rate < 0) { + $subject['rate'] = 0; // TODO: why not track negative rates? + continue; + } + + $subject['rate'] = $rate; + $subject_rate_sum += $rate; // TODO: why not track negative rates? + } + + // If no enabled subjects skip this campaign + if ($valid_subjects == 0) { + $campaign['valid'] = false; + continue; + } + + foreach ($campaign['subjects'] as $subject_index => &$subject) { + $share = $subject_rate_sum ? $subject['rate'] / $subject_rate_sum : 0; + $subject['share'] = $share; + } + + // Campaign + $rate = ( + ($campaign['conversions'] - $campaign['losses'] + $boost * $overall['rate']) + / + ($campaign['sent'] + $boost) + ); + + if ($rate < 0) { + $campaign['rate'] = 0; // TODO: why not track negative rates? + continue; + } + + $campaign['rate'] = $rate; + $campaign_rate_sum += $rate; + } + + // Filter out invalid campaigns + $campaigns = array_filter($campaigns, function($campaign) { + return $campaign['valid']; + }); + + // Get share percentages + foreach ($campaigns as $campaign_index => &$campaign) { + $share = $campaign_rate_sum ? $campaign['rate'] / $campaign_rate_sum : 0; + $campaign['share'] = $share; + } + + // Limit share percentages, based on subscriber availability + $campaign_share_sum = 1; + $limit_per_day = get_option('subscribed_users') / 7; + + foreach ($campaigns as $campaign_index => &$campaign) { + + $limit_per_campaign = round($campaign['share'] * $limit_per_day); + // $limit = trim(preg_replace('/\s+/', ' ',var_export($limit_per_campaign, true))); + // error_log('line 192 limit_per_campaign '.$limit); + $fresh_ids = count($mh->get_fresh_subscribers_for_campaign($campaign['id'], $limit_per_campaign, $wpdb_mock)); + // Plenty? Great. + //fresh ids should not be 0 + + if ($fresh_ids >= $limit_per_campaign) { + $campaign['limit'] = $limit_per_campaign; + continue; + } + // Shortage of fresh IDs. Calculations are required. + $campaign['limit'] = $fresh_ids; + //CURRENTLY RETURNING 0 FOR $SHARE THIS IS MAKING A NAN VALUE + $share = $fresh_ids / $limit_per_day; + + $campaign_share_sum += $share - $campaign['share']; + + $campaign['share'] = $share; + + // $campShare = $campaign['share']; + // $allsql = trim(preg_replace('/\s+/', ' ',var_export( $campShare, true))); + // error_log('line 225 $campaign_share_sum '.$campaign_share_sum); + // error_log('line 226 variable campaing[share] '.$share); + } + + foreach ($campaigns as $campaign_index => &$campaign) { + $campaign['share'] = $campaign['share'] / $campaign_share_sum; + } + + usort($campaigns, function($a, $b) { + $difference = $b['share'] - $a['share']; + if ($difference == 0) { + return 0; + } else if ($difference > 0) { + return 1; + } else { + return -1; + } + }); + + return array( + 'campaigns' => $campaigns, + 'overall' => $overall, + ); } + // Update conversion stats from ActionKit for a campaign mailing function get_mailing_stats_from_ak($ak_mailing_id) { @@ -295,86 +506,6 @@ function get_mailing_stats_from_ak($ak_mailing_id) 'sent' => $sent, ); } - - function render($params) - { - $html = file_get_contents(dirname(__FILE__) . '/email-template.html'); - $html = str_replace('$body', $params['body'], $html); // Turn newlines into in body - $html = str_replace('$petition_headline', $params['petition_headline'], $html); - $html = str_replace('$salutation', $params['salutation'], $html); - $html = str_replace('$url', $params['url'], $html); - - if (!isset($params['wrap'])) { - return $html; - } - - $wrapper = file_get_contents(dirname(__FILE__) . '/email-template-wrapper.html'); - $html = str_replace('$content', $html, $wrapper); - - return $html; - } - - function send($params) - { - // Verify targeting - if ( - !$params['subscribers'] - || - !is_array($params['subscribers']) - || - count($params['subscribers']) < 1 - ) { - return; - } - - // Render - $html = $this->render($params); - - global $ak; - $response = $ak->request(array( - 'path' => 'mailer', - 'method' => 'post', - 'data' => array( - 'fromline' => "/rest/v1/fromline/{$params['from_line']}/", - 'subjects' => array($params['subject']), - 'notes' => 'Generated by VictoryKit', - 'emailwrapper' => 27, // Demand Progress wrapper - 'includes' => array( - 'lists' => array(26), // VK list. TODO: store this as a constant somewhere - 'users' => $params['subscribers'], // Subscribers - ), - 'limit' => $params['limit'], // Limit users per mailing - // 'excludes' => array( - // 'mailings' => $mailings, // Array of mailing IDs, for avoiding multiple sends - // ), - 'tags' => array('victorykit'), - 'html' => $html, - 'sort_by' => 'random', - ), - )); - - $location = $response['headers']->getAll()['location']; - preg_match('%/(\d+)/$%', $location, $matches); - $ak_mailing_id = +$matches[1]; - - $response = $ak->request(array( - 'path' => "mailer/$ak_mailing_id/rebuild", - 'method' => 'post', - 'data' => array(), - )); - - $response['ak_mailing_id'] = $ak_mailing_id; - - global $wpdb; - $wpdb->insert('vk_mailing', array( - 'ak_mailing_id' => $ak_mailing_id, - 'campaign_id' => $params['campaign_id'], - 'status' => 'rebuilding', - 'variation_subject' => $params['variation_subject'], - )); - - return $response; - } } /**************** Actions *****************/ @@ -382,16 +513,18 @@ function send($params) // Update total count of subscribers in VictoryKit list // Run every 12 hours function vk_mailings_update_subscribed_users_count_action() { + global $ak; + $sql = " SELECT COUNT(DISTINCT cs.id) AS user_count FROM core_subscription AS cs WHERE - cs.list_id = 26 - "; + cs.list_id =".VK_LIST_ID; $response = $ak->query($sql); + if ($response['success']) { $count = $response['data']['user_count']; } else { @@ -416,8 +549,8 @@ function vk_mailings_sync_subscribers_action() { FROM core_subscription AS cs WHERE - cs.list_id = 26 - '; + cs.list_id ='.VK_LIST_ID + ; $response = $ak->query($sql, true); $ids = array_map(function($el) { return +$el['user_id']; @@ -478,19 +611,37 @@ function vk_mailings_update_mailing_stats_action() { // Create new mailings based on the currently running campaigns // Run once a day at 8am -function vk_mailings_create_new_mailings_action() { - global $vk_mailings, $wpdb; - - $limit_per_day = get_option('subscribed_users') / 7; - $distributions = $vk_mailings->get_distributions(); - +function vk_mailings_create_new_mailings_action($vk_mailings_mock=0, $wpdb_mock=0, $mhMock=0) { + global $vk_mailings, $wpdb, $mh; + + if($vk_mailings_mock){ + $vk_mailings = $vk_mailings_mock; + $wpdb = $wpdb_mock; + $mh = $mhMock; + } + + $limit_per_day = $mh->getoption(); + + $distributions = $vk_mailings->get_distributions($vk_mailings_mock, $wpdb_mock, $mhMock); + $distributions_results = trim(preg_replace('/\s+/', ' ',var_export( $distributions, true))); + $paramsList = Array(); + // $distributions_results = sizeof($distributions_results); + // error_log('distribution results two campaigns '.$distributions_results); foreach ($distributions['campaigns'] as $campaign) { $id = $campaign['id']; $fields = $campaign['fields']; - $url = get_permalink($id); + $url = $mh->get_url($id); + //need to print out why $limit_per_campaign NAN -> this is breaking everything + // $allsql = trim(preg_replace('/\s+/', ' ',var_export( $campaign, true))); + // error_log('%%%%%%%%%%% '); + // error_log('line 531 $campaign '.$allsql); + $shares = $campaign['share']; + // $sCamp = trim(preg_replace('/\s+/', ' ',var_export( $shares, true))); + // error_log('line 535 campaign[share] variable '.$sCamp); $limit_per_campaign = round($campaign['share'] * $limit_per_day); - $fresh_ids = $vk_mailings->get_fresh_subscribers_for_campaign($id, $limit_per_campaign); - + + $fresh_ids = $mh->get_fresh_subscribers_for_campaign($id, $limit_per_campaign, $wpdb); + // Out of users to send to? if (count($fresh_ids) == 0) { continue; @@ -499,12 +650,12 @@ function vk_mailings_create_new_mailings_action() { // Send mailing for each enabled subject foreach ($campaign['subjects'] as $index => $subject) { $share = round($subject['share'] * $limit_per_campaign); - + // Skip disabled subjects if ($share == 0) { continue; } - + // Claim IDs $subscribers = array_splice($fresh_ids, 0, $share); @@ -521,13 +672,21 @@ function vk_mailings_create_new_mailings_action() { 'url' => $url, 'variation_subject' => $index, ); - - $response = $vk_mailings->send($params); - + + array_push($paramsList,$params); + // $allsql = trim(preg_replace('/\s+/', ' ',var_export( $params, true))); + // error_log('s line 563: '.$allsql); + // $sCamp = trim(preg_replace('/\s+/', ' ',var_export( $params, true))); + // error_log('$$$$$$$$'); + // error_log('line 550 $subject variable '.$sCamp); + $response = $mh->send($params); + // Save mailing records for VK $ak_mailing_id = $response['ak_mailing_id']; $subscriber_chunks = array_chunk($subscribers, 1000); // Chunk so SQL queries dont get too big + foreach ($subscriber_chunks as $subscriber_chunk) { + $values = array(); foreach ($subscriber_chunk as $subscriber) { $values[] = "($subscriber, $ak_mailing_id, $id)"; @@ -542,8 +701,10 @@ function vk_mailings_create_new_mailings_action() { $wpdb->query($sql); } } - } + } + return $paramsList; } + add_action('vk_mailings_create_new_mailings', 'vk_mailings_create_new_mailings_action'); @@ -701,6 +862,10 @@ function vk_mailings_complete_mailings_action() { "; $response = $ak->query($sql); + $responseLog = trim(preg_replace('/\s+/', ' ',var_export( $response, true))); + error_log('line 861 response from query from ak->query '.$responseLog); + + if (!$response['data']) { continue; } @@ -730,9 +895,13 @@ function vk_mailings_complete_mailings_action() { add_action('vk_mailings_complete_mailings', 'vk_mailings_complete_mailings_action'); -function vk_mailings_cron_test_action() { - $count = get_option('cron_test', 0); - update_option('cron_test', $count + 1); +function vk_mailings_cron_test_action($thing=1, $thing2=2) { + $numargs = func_num_args(); + error_log("Number of arguments: $numargs \n"); + error_log("something :" .var_export($thing, true)); + error_log("something2 :" .var_export($thing2, true)); + // $count = get_option('cron_test', 0); + // update_option('cron_test', $count + 1); } add_action('vk_mailings_cron_test', 'vk_mailings_cron_test_action'); @@ -747,4 +916,9 @@ function create_mailings_instance() { return $vk_mailings; } + create_mailings_instance(); + +// do_action('vk_mailings_create_new_mailings'); +// $allsql = trim(preg_replace('/\s+/', ' ',var_export( $mailings, true))); +// error_log('sql mailing_stats line 468: '.$allsql); \ No newline at end of file diff --git a/addons/mockClasses/mailingsHelpers.php b/addons/mockClasses/mailingsHelpers.php new file mode 100644 index 0000000..9cf98eb --- /dev/null +++ b/addons/mockClasses/mailingsHelpers.php @@ -0,0 +1,207 @@ + 'campaign', + 'post_status' => 'publish', + )); + } + + function getFields($id, $mh_mock){ + if($mh_mock){ + return array('subjects' => array()); + } else { + return get_fields($id); + } + } + + function setUpCampaigns($results, $campaigns, $mh_mock){ + + $campaigns = $campaigns; + foreach ($results->posts as $campaign) { + $id = $campaign->ID; + $campaigns[$id] = array( + 'conversions' => 0, + 'fields' => $this->getFields($id, $mh_mock), + 'id' => $id, + 'losses' => 0, + 'sent' => 0, + 'subjects' => array(), + 'title' => $campaign->post_title, + 'valid' => true, + ); + + // Get all subjects + $subjects = $campaigns[$id]['fields']['subjects']; + for ($i = 0; $i < count($subjects); $i++) { + $campaigns[$id]['subjects'][$i] = array( + 'conversions' => 0, + 'losses' => 0, + 'sent' => 0, + ); + } + } + return $campaigns; + } + + function get_mailings_results_wpdb($db){ + return $db->get_results(' + SELECT + vkm.campaign_id, + vkm.variation_subject, + SUM(vkm.conversions) as conversions, + SUM(vkm.losses) as losses, + SUM(vkm.sent) as sent + FROM + vk_mailing AS vkm + GROUP BY + vkm.campaign_id, vkm.variation_subject + ', ARRAY_A); + } + + // Get all subscribers who have not been mailed for this campaign AND have not been mailed for any campaign within the last week + function get_fresh_subscribers_for_campaign($campaign_id, $limit, $wpdb_mock) + { + global $wpdb; + + if($wpdb_mock){ + $wpdb = $wpdb_mock; + } + + $sql = " + SELECT + vks.ak_user_id + FROM + vk_subscriber AS vks + LEFT JOIN + vk_subscriber_mailing AS vksm + ON + vks.ak_user_id = vksm.ak_user_id AND + ( + vksm.campaign_id = $campaign_id + OR + vksm.created_at > DATE_SUB(NOW(), INTERVAL 1 WEEK) + ) + WHERE + vksm.ak_user_id IS NULL + LIMIT $limit; + "; + + // $allsql = trim(preg_replace('/\s+/', ' ',var_export( $sql, true))); + // error_log('line 260 sql query '.$allsql); + + $response = $wpdb->get_col($sql, 0); + + $ids = array_map(function($el) { + return +$el; + }, $response); + + return $ids; + } + + function render($params) + { + $html = file_get_contents(dirname(__FILE__) . '/email-template.html'); + $html = str_replace('$body', $params['body'], $html); // Turn newlines into in body + $html = str_replace('$petition_headline', $params['petition_headline'], $html); + $html = str_replace('$salutation', $params['salutation'], $html); + $html = str_replace('$url', $params['url'], $html); + + if (!isset($params['wrap'])) { + return $html; + } + + $wrapper = file_get_contents(dirname(__FILE__) . '/email-template-wrapper.html'); + $html = str_replace('$content', $html, $wrapper); + + return $html; + } + + function send($params) + { + // Verify targeting + if ( + !$params['subscribers'] + || + !is_array($params['subscribers']) + || + count($params['subscribers']) < 1 + ) { + return; + } + // $distributions_results = trim(preg_replace('/\s+/', ' ',var_export( $params, true))); + // error_log('@@@ line 359 '.$distributions_results); + // Render + $html = $this->render($params); + + global $ak; + + // error_log('@@@ limit_per_day variable '.$ak); + $response = $ak->request(array( + 'path' => 'mailer', + 'method' => 'post', + 'data' => array( + 'fromline' => "/rest/v1/fromline/{$params['from_line']}/", + 'subjects' => array($params['subject']), + 'notes' => 'Generated by VictoryKit', + 'emailwrapper' => 27, // Demand Progress wrapper + 'includes' => array( + 'lists' => array(VK_LISTS), // VK list. TODO: store this as a constant somewhere + 'users' => $params['subscribers'], // Subscribers + ), + 'limit' => $params['limit'], // Limit users per mailing + // 'excludes' => array( + // 'mailings' => $mailings, // Array of mailing IDs, for avoiding multiple sends + // ), + 'tags' => array('victorykit'), + 'html' => $html, + 'sort_by' => 'random', + ), + )); + + $mailingsPrint = trim(preg_replace('/\s+/', ' ',var_export( $response, true))); + $location = $response['headers']->getAll()['location']; + preg_match('%/(\d+)/$%', $location, $matches); + $ak_mailing_id = +$matches[1]; + + $response = $ak->request(array( + 'path' => "mailer/$ak_mailing_id/rebuild", + 'method' => 'post', + 'data' => array(), + )); + + $response['ak_mailing_id'] = $ak_mailing_id; + + global $wpdb; + $wpdb->insert('vk_mailing', array( + 'ak_mailing_id' => $ak_mailing_id, + 'campaign_id' => $params['campaign_id'], + 'status' => 'rebuilding', + 'variation_subject' => $params['variation_subject'], + )); + + return $response; + } + + function get_url($id){ + return get_permalink($id); + } + + function getoption(){ + return get_option('subscribed_users') / 7; + } +} + +function mh() { + global $mh; + + if(!isset($mh)) { + $mh = new mailingsHelpers(); + } + + return $mh; +} + +// Initialize +mh(); \ No newline at end of file diff --git a/addons/post-type-campaign.php b/addons/post-type-campaign.php index a83d75a..4dc0306 100644 --- a/addons/post-type-campaign.php +++ b/addons/post-type-campaign.php @@ -2,7 +2,7 @@ // Exit if accessed directly if(!defined('ABSPATH')) exit; - +require_once(__DIR__. '/../constants.php'); // Register post type add_action( 'init', 'register_post_type_campaign' ); function register_post_type_campaign() { @@ -114,7 +114,7 @@ function after_saving_campaign($post_id, $post, $update) { 'description' => 'Sample description', 'facebook_image_url' => 'https://s3.amazonaws.com/demandprogress/images/add-your-name.png', ), - 'list' => '/rest/v1/list/26/', // VictoryKit + 'list' => '/rest/v1/list/'.VK_LIST_ID.'/', // VictoryKit 'title' => '(VK) ' . $post->post_title, 'name' => $ak_page_short_name, 'tags' => array( @@ -220,13 +220,16 @@ function after_saving_campaign($post_id, $post, $update) { 'url' => "$permalink?phase=thanks", 'send_email' => true, 'email_from_line' => "/rest/v1/fromline/$from_line/", - 'email_wrapper' => 2, // default after action wrapper in ActionKit + 'email_wrapper' => 27, // default after action wrapper in ActionKit 'email_subject' => $email_subject, 'email_body' => $followup_email_body, 'taf_body' => $email_sharing_body ), )); +$mailingsPrint = trim(preg_replace('/\s+/', ' ',var_export( $response, true))); +error_log('$$$response line 231 '.$mailingsPrint); + if ($response['error']) { return; } diff --git a/addons/tests/mailing_test.php b/addons/tests/mailing_test.php new file mode 100644 index 0000000..2cf65a3 --- /dev/null +++ b/addons/tests/mailing_test.php @@ -0,0 +1,1573 @@ +createMock(Mailings::class); + $wpdb_mock = $this->createMock(wpdb::class); + $mhMock= $this->createMock(MailingsHelpers::class); + + $vk_mailings_mock->expects($this->once()) + ->method('get_distributions') + ->willReturn($TwoCampaigns); + + $mhMock->expects($this->exactly(2)) + ->method('get_fresh_subscribers_for_campaign') + ->willReturn(array( 0 => 6630470, 1 => 6630472,)); + + $mhMock->expects($this->once()) + ->method('getoption') + ->willReturn(4); + + $mhMock->expects($this->exactly(3)) + ->method('send'); + + $wpdb_mock->expects($this->exactly(1)) + ->method('query'); + + vk_mailings_create_new_mailings_action($vk_mailings_mock, $wpdb_mock, $mhMock); + } + + public function test_vk_mailings_create_new_mailings_action_one_campaigns(): void + { + global $singleCampaign; + + $vk_mailings_mock = $this->createMock(Mailings::class); + $wpdb_mock = $this->createMock(wpdb::class); + $mhMock = $this->createMock(MailingsHelpers::class); + + $vk_mailings_mock->expects($this->once()) + ->method('get_distributions') + ->willReturn($singleCampaign); + + $mhMock->expects($this->exactly(1)) + ->method('get_fresh_subscribers_for_campaign') + ->willReturn(array( 0 => 6630470, 1 => 6630472,)); + + $mhMock->expects($this->once()) + ->method('getoption') + ->willReturn(4); + + $mhMock->expects($this->exactly(2)) + ->method('send'); + + $wpdb_mock->expects($this->exactly(1)) + ->method('query'); + + vk_mailings_create_new_mailings_action($vk_mailings_mock, $wpdb_mock, $mhMock); + } + + public function test_get_distribution_two_subject_campaign(): void + { + global $twoSubjectCampaign; + + $vk_mailings_mock = $this->createMock(Mailings::class); + $wpdb_mock = $this->createMock(wpdb::class); + $mhMock = $this->createMock(MailingsHelpers::class); + + $vk_mailings_mock->expects($this->once()) + ->method('get_distributions') + ->willReturn($twoSubjectCampaign); + + $mhMock->expects($this->once()) + ->method('get_fresh_subscribers_for_campaign') + ->willReturn(array( 0 => 6630470, 1 => 6630472,)); + + $mhMock->expects($this->once()) + ->method('getoption') + ->willReturn(4); + + $mhMock->expects($this->once()) + ->method('send') + ->willReturn(array ( 'ak_mailing_id' => 1)); + + $wpdb_mock->expects($this->once()) + ->method('query'); + + vk_mailings_create_new_mailings_action($vk_mailings_mock, $wpdb_mock, $mhMock); + } + + public function test_mailingsHelpers_wp_query_posts_method(): void + { + $mailingsMock = new Mailings(); + $wpdb = new wpdb(); + $postObject = new stdClass(); + $boost_test_value = 500; + $postObject->posts = array(0 => (object) ['ID' => '', 'post_title'=> '']); + + $mhMock= $this->getMockBuilder(MailingsHelpers::class) + ->setMethods(['wp_query_posts']) + ->getMock(); + + $mhMock->expects($this->once()) + ->method('wp_query_posts') + ->will($this->returnValue($postObject)); + + $mailingsMock->get_distributions($wpdb, $mhMock, $boost_test_value); + } + + public function test_get_fields(): void + { + $wpdb = new wpdb(); + $postObject = new stdClass(); + $boost_test_value = 500; + $postObject->posts = array(0 => (object) ['ID' => '', 'post_title'=> '']); + + $mhMock= $this->getMockBuilder(MailingsHelpers::class) + ->setMethods(['wp_query_posts', 'getFields']) + ->getMock(); + + $mhMock->expects($this->once()) + ->method('wp_query_posts') + ->will($this->returnValue($postObject)); + + $mhMock->expects($this->once()) + ->method('getFields'); + + $subject = new Mailings(); + + $subject->get_distributions($wpdb, $mhMock, $boost_test_value); + } + + public function test_mailingsHelpers_setUpCampaigns(): void + { + $wpdb = new wpdb(); + $boost_test_value = 500; + // $postObject = new stdClass(); + $postObject = array(0 => (object) ['ID' => '', 'post_title'=> '']); + $campaigns = array( 0 => array( 'fields'=> '', 'campaign_id' => '', 'subjects' => array())); + + $mhMock= $this->getMockBuilder(MailingsHelpers::class) + ->setMethods(['wp_query_posts', 'setUpCampaigns']) + ->getMock(); + + $mhMock->expects($this->once()) + ->method('wp_query_posts') + ->will($this->returnValue($postObject)); + + $mhMock->expects($this->once()) + ->method('setUpCampaigns') + ->will($this->returnValue($campaigns)); + + $subject = new Mailings(); + + $subject->get_distributions($wpdb, $mhMock, $boost_test_value); + } + + public function test_mailingsHelpers_get_mailings_results_wpdb(): void + { + $wpdb = new wpdb(); + $boost_test_value = 500; + // $postObject = new stdClass(); + $postObject = array( 0 => array( 'campaign_id' => '1')); + + $mhMock= $this->getMockBuilder(MailingsHelpers::class) + ->setMethods(['get_mailings_results_wpdb']) + ->getMock(); + + $mhMock->expects($this->once()) + ->method('get_mailings_results_wpdb') + ->will($this->returnValue($postObject)); + + $subject = new Mailings(); + + $subject->get_distributions($wpdb, $mhMock, $boost_test_value); + } + + public function test_mailings_distribution_post_method(): void + { + $mailings = new Mailings(); + $wpdb = new wpdb(); + $postObject = new stdClass(); + $boost_test_value = 500; + + $postObject->posts = array ( 0 => (object)(array( 'ID' => 263, 'post_author' => '8', 'post_date' => '2018-06-26 20:10:27', 'post_date_gmt' => '2018-06-26 20:10:27', 'post_content' => '', 'post_title' => 'No wall testing', 'post_excerpt' => '', 'post_status' => 'publish', 'comment_status' => 'closed', 'ping_status' => 'closed', 'post_password' => '', 'post_name' => 'no-wall-testing-2', 'to_ping' => '', 'pinged' => '', 'post_modified' => '2018-06-28 17:54:34', 'post_modified_gmt' => '2018-06-28 17:54:34', 'post_content_filtered' => '', 'post_parent' => 0, 'guid' => 'https://victorykit.local/?post_type=campaign&p=263', 'menu_order' => 0, 'post_type' => 'campaign', 'post_mime_type' => '', 'comment_count' => '0', 'filter' => 'raw', )), ); + + //** must update return value from campaigns + + $campaigns = array( + 263 => array( + "conversions" => 0, + "fields" => array( + "subjects" => array ( 0 => array ( 'subject' => 'Tell Senate: No attacks on immigrants', 'enabled' => true, ), 1 => array ( 'subject' => "Block Trump's attacks on immigrants", 'enabled' => true, ),) + ), + "id" => 263, + "losses" => 0, + "sent" => 0, + "subjects" => array (), + "title" => "No wall testing", + "valid" => true + ) + ); + // $postObject->posts = array(0 => (object) ['ID' => '', 'post_title'=> '']); + + $mailings_stats = array(0 => [ + 'campaign_id' => 263, + 'conversions' => 0, + 'losses' => 0, + 'sent' => 0, + 'variation_subject' => 0 + ]); + + $mhMock= $this->getMockBuilder(MailingsHelpers::class) + ->setMethods(['wp_query_posts', 'setUpCampaigns', 'get_mailings_results_wpdb', 'get_fresh_subscribers_for_campaign']) + ->getMock(); + + $mhMock->expects($this->once()) + ->method('wp_query_posts') + ->will($this->returnValue($postObject)); + + $mhMock->expects($this->once()) + ->method('setUpCampaigns') + ->will($this->returnValue($campaigns)); + + $mhMock->expects($this->once()) + ->method('get_mailings_results_wpdb') + ->will($this->returnValue($mailings_stats)); + + $mhMock->expects($this->once()) + ->method('get_fresh_subscribers_for_campaign') + ->will($this->returnValue(['6630475', '6630477', '6630478','6630479'])); + + $this->assertEquals(array( + 'campaigns' => Array( + 0 => Array( + 'conversions' => 0, + 'fields' => Array( + 'subjects' => Array( + 0 => Array( + 'subject' => 'Tell Senate: No attacks on immigrants', + 'enabled' => true + ), + 1 => Array( + 'subject' => "Block Trump's attacks on immigrants", + 'enabled' => true + ) + ) + ), + 'id' => 263, + 'losses' => 0, + 'sent' => 0, + 'subjects' => Array( + 0 => Array( + 'conversions' => 0, + 'losses' => 0, + 'sent' => 0, + 'title' => 'Tell Senate: No attacks on immigrants', + 'rate' => 1, + 'share' => 1 + ) + ), + 'title' => 'No wall testing', + 'valid' => true, + 'rate' => 1, + 'share' => 1, + 'limit' => 4.0 + ) + ), + 'overall' => Array( + 'conversions' => 0, + 'losses' => 0, + 'sent' => 0, + 'boost' => 500, + 'rate' => 1 + ) + ), $mailings->get_distributions($wpdb, $mhMock, $boost_test_value)); + } + + public function test_get_distributions_one_campaign_method(): void + { + $mailings = new Mailings(); + $wpdb = new wpdb(); + $postObject = new stdClass(); + $boost_test_value = 500; + $postObject->posts = array (); + + //** must update return value from campaigns + + $campaigns = array( + 263 => array( + "conversions" => 0, + "fields" => array( + "subjects" => array ( 0 => array ( 'subject' => 'Tell Senate: No attacks on immigrants', 'enabled' => true, ), 1 => array ( 'subject' => "Block Trump's attacks on immigrants", 'enabled' => true, ),) + ), + "id" => 263, + "losses" => 0, + "sent" => 0, + "subjects" => array (), + "title" => "No wall testing", + "valid" => true + ) + ); + // $postObject->posts = array(0 => (object) ['ID' => '', 'post_title'=> '']); + + $mailings_stats = array ( + 0 => array ( + 'campaign_id' => '263', + 'variation_subject' => '0', + 'conversions' => '1', + 'losses' => '0', + 'sent' => '2', ), + 1 => array ( + 'campaign_id' => '263', + 'variation_subject' => '1', + 'conversions' => '1', + 'losses' => '0', + 'sent' => '2', ) + ); + + $mhMock= $this->getMockBuilder(MailingsHelpers::class) + ->setMethods(['wp_query_posts', 'setUpCampaigns', 'get_mailings_results_wpdb', 'get_fresh_subscribers_for_campaign']) + ->getMock(); + + $mhMock->expects($this->once()) + ->method('wp_query_posts') + ->will($this->returnValue($postObject)); + + $mhMock->expects($this->once()) + ->method('setUpCampaigns') + ->will($this->returnValue($campaigns)); + + $mhMock->expects($this->once()) + ->method('get_mailings_results_wpdb') + ->will($this->returnValue($mailings_stats)); + + $mhMock->expects($this->once()) + ->method('get_fresh_subscribers_for_campaign') + ->will($this->returnValue(['6630475', '6630477', '6630478','6630479'])); + + $this->assertEquals(array( + 'campaigns' => Array( + 0 => Array( + 'conversions' => 2, + 'fields' => Array( + 'subjects' => Array( + 0 => Array( + 'subject' => 'Tell Senate: No attacks on immigrants', + 'enabled' => true + ), + 1 => Array( + 'subject' => "Block Trump's attacks on immigrants", + 'enabled' => true + ) + ) + ), + 'id' => 263, + 'losses' => 0, + 'sent' => 4, + 'subjects' => Array( + 0 => Array( + 'conversions' => 1, + 'losses' => 0, + 'sent' => 2, + 'title' => 'Tell Senate: No attacks on immigrants', + 'rate' => 0.994055523936002, + 'share' => 0.5 + ), + 1 => Array( + 'conversions' => 1, + 'losses' => 0, + 'sent' => 2, + 'title' => "Block Trump's attacks on immigrants", + 'rate' => 0.994055523936002, + 'share' => 0.5 + ) + ), + 'title' => 'No wall testing', + 'valid' => true, + 'rate' => 0.9920949861426052, + 'share' => 1.0, + 'limit' => 4.0 + ) + ), + 'overall' => Array( + 'conversions' => 2, + 'losses' => 0, + 'sent' => 4, + 'boost' => 500, + 'rate' => 0.996031746031746 + ) + ), $mailings->get_distributions($wpdb, $mhMock, $boost_test_value)); + } + public function test_get_distributions_one_campaign_one_greater_conversions_method(): void + { + $mailings = new Mailings(); + $wpdb = new wpdb(); + $postObject = new stdClass(); + $boost_test_value = 500; + + $postObject->posts = array (); + + //** must update return value from campaigns + + $campaigns = array( + 263 => array( + "conversions" => 0, + "fields" => array( + "subjects" => array ( 0 => array ( 'subject' => 'Tell Senate: No attacks on immigrants', 'enabled' => true, ), 1 => array ( 'subject' => "Block Trump's attacks on immigrants", 'enabled' => true, ),) + ), + "id" => 263, + "losses" => 0, + "sent" => 0, + "subjects" => array (), + "title" => "No wall testing", + "valid" => true + ) + ); + // $postObject->posts = array(0 => (object) ['ID' => '', 'post_title'=> '']); + + $mailings_stats = array ( + 0 => array ( + 'campaign_id' => '263', + 'variation_subject' => '0', + 'conversions' => '2', + 'losses' => '0', + 'sent' => '2', ), + 1 => array ( + 'campaign_id' => '263', + 'variation_subject' => '1', + 'conversions' => '0', + 'losses' => '0', + 'sent' => '2', ) + ); + + $mhMock= $this->getMockBuilder(MailingsHelpers::class) + ->setMethods(['wp_query_posts', 'setUpCampaigns', 'get_mailings_results_wpdb', 'get_fresh_subscribers_for_campaign']) + ->getMock(); + + $mhMock->expects($this->once()) + ->method('wp_query_posts') + ->will($this->returnValue($postObject)); + + $mhMock->expects($this->once()) + ->method('setUpCampaigns') + ->will($this->returnValue($campaigns)); + + $mhMock->expects($this->once()) + ->method('get_mailings_results_wpdb') + ->will($this->returnValue($mailings_stats)); + + $mhMock->expects($this->once()) + ->method('get_fresh_subscribers_for_campaign') + ->will($this->returnValue(['6630475', '6630477', '6630478','6630479'])); + + $this->assertEquals(array( + 'campaigns' => Array( + 0 => Array( + 'conversions' => 2, + 'fields' => Array( + 'subjects' => Array( + 0 => Array( + 'subject' => 'Tell Senate: No attacks on immigrants', + 'enabled' => true + ), + 1 => Array( + 'subject' => "Block Trump's attacks on immigrants", + 'enabled' => true + ) + ) + ), + 'id' => 263, + 'losses' => 0, + 'sent' => 4, + 'subjects' => Array( + 0 => Array( + 'conversions' => 2, + 'losses' => 0, + 'sent' => 2, + 'title' => 'Tell Senate: No attacks on immigrants', + 'rate' => 0.996047555808512, + 'share' => 0.501001972135632 + ), + 1 => Array( + 'conversions' => 0, + 'losses' => 0, + 'sent' => 2, + 'title' => "Block Trump's attacks on immigrants", + 'rate' => 0.9920634920634921, + 'share' => 0.498998027864368 + ) + ), + 'title' => 'No wall testing', + 'valid' => true, + 'rate' => 0.9920949861426052, + 'share' => 1.0, + 'limit' => 4.0 + ) + ), + 'overall' => Array( + 'conversions' => 2, + 'losses' => 0, + 'sent' => 4, + 'boost' => 500, + 'rate' => 0.996031746031746 + ) + ), $mailings->get_distributions($wpdb, $mhMock, $boost_test_value)); + } + + public function test_send_function_with_one_campaign_one_subject_greater_conversion(): void + { + $vk_mailings_mock = $this->createMock(Mailings::class); + $wpdb_mock = $this->createMock(wpdb::class); + $mhMock = $this->createMock(MailingsHelpers::class); + + $vk_mailings_mock->expects($this->once()) + ->method('get_distributions') + ->willReturn(Array( + 'campaigns' => Array( + 0 => Array( + 'conversions' => 2, + 'fields' => Array( + 'subjects' => Array( + 0 => Array( + 'subject' => 'Tell Senate: No attacks on immigrants', + 'enabled' => true + ), + 1 => Array( + 'subject' => "Block Trump's attacks on immigrants", + 'enabled' => true + ) + ), + 'from_line' => '41', + 'body' => '

When he ran for president, Trump promised to harass and terrorize immigrants. Now he is doing everything he can to fulfill those promises.

', + 'petition_headline' => 'Senate Democrats: Block Trump’s attacks on immigrants', + 'salutation' => '{{ user.first_name|default:"Hi" }},', + + ), + 'id' => 263, + 'losses' => 0, + 'sent' => 4, + 'subjects' => Array( + 0 => Array( + 'conversions' => 2, + 'losses' => 0, + 'sent' => 2, + 'title' => 'Tell Senate: No attacks on immigrants', + 'rate' => 0.996047555808512, + 'share' => 0.501001972135632 + ), + 1 => Array( + 'conversions' => 0, + 'losses' => 0, + 'sent' => 2, + 'title' => "Block Trump's attacks on immigrants", + 'rate' => 0.9920634920634921, + 'share' => 0.498998027864368 + ) + ), + 'title' => 'No wall testing', + 'valid' => true, + 'rate' => 0.9920949861426052, + 'share' => 1.0, + 'limit' => 4.0 + ) + ), + 'overall' => Array( + 'conversions' => 2, + 'losses' => 0, + 'sent' => 4, + 'boost' => 500, + 'rate' => 0.996031746031746 + ) + ) + ); + + $mhMock->expects($this->once()) + ->method('getoption') + ->willReturn(3.5714285714285716); + + $mhMock->expects($this->once()) + ->method('get_url') + ->willReturn('https://victorykit.local/c/no-wall-testing-2/'); + + + $mhMock->expects($this->exactly(1)) + ->method('get_fresh_subscribers_for_campaign') + ->willReturn(array( 0 => 6630470, 1 => 6630472, 2 => 6630478, + 3 => 6630479)); + + $mhMock->expects($this->exactly(2)) + ->method('send'); + + vk_mailings_create_new_mailings_action($vk_mailings_mock, $wpdb_mock, $mhMock); + } + + public function test_get_distributions_one_campaign_one_succesful_subject_method(): void + { + $mailings = new Mailings(); + $wpdb = new wpdb(); + $postObject = new stdClass(); + $boost_test_value = 500; + $postObject->posts = array (); + + //** must update return value from campaigns + + $campaigns = array( + 263 => array( + "conversions" => 0, + "fields" => array( + "subjects" => array ( + 0 => array ( 'subject' => 'Tell Senate: No attacks on immigrants', 'enabled' => true, ), + 1 => array ( 'subject' => "Block Trump's attacks on immigrants", 'enabled' => true, ), + ) + ), + "id" => 263, + "losses" => 0, + "sent" => 0, + "subjects" => array (), + "title" => "No wall testing", + "valid" => true + ) + ); + // $postObject->posts = array(0 => (object) ['ID' => '', 'post_title'=> '']); + + $mailings_stats = array ( + 0 => array ( + 'campaign_id' => '263', + 'variation_subject' => '0', + 'conversions' => '500', + 'losses' => '0', + 'sent' => '500', ), + 1 => array ( + 'campaign_id' => '263', + 'variation_subject' => '1', + 'conversions' => '0', + 'losses' => '0', + 'sent' => '500', ) + ); + + $mhMock= $this->getMockBuilder(MailingsHelpers::class) + ->setMethods(['wp_query_posts', 'setUpCampaigns', 'get_mailings_results_wpdb', 'get_fresh_subscribers_for_campaign']) + ->getMock(); + + $mhMock->expects($this->once()) + ->method('wp_query_posts') + ->will($this->returnValue($postObject)); + + $mhMock->expects($this->once()) + ->method('setUpCampaigns') + ->will($this->returnValue($campaigns)); + + $mhMock->expects($this->once()) + ->method('get_mailings_results_wpdb') + ->will($this->returnValue($mailings_stats)); + + $mhMock->expects($this->once()) + ->method('get_fresh_subscribers_for_campaign') + ->will($this->returnValue(['6630475', '6630477', '6630478','6630479'])); + + $this->assertEquals(array( + 'campaigns' => Array( + 0 => Array( + 'conversions' => 500, + 'fields' => Array( + 'subjects' => Array( + 0 => Array( + 'subject' => 'Tell Senate: No attacks on immigrants', + 'enabled' => true + ), + 1 => Array( + 'subject' => "Block Trump's attacks on immigrants", + 'enabled' => true + ) + ) + ), + 'id' => 263, + 'losses' => 0, + 'sent' => 1000, + 'subjects' => Array( + 0 => Array( + 'conversions' => 500, + 'losses' => 0, + 'sent' => 500, + 'title' => 'Tell Senate: No attacks on immigrants', + 'rate' => 0.8333333333333333, + 'share' => 0.7142857142857143 + ), + 1 => Array( + 'conversions' => 0, + 'losses' => 0, + 'sent' => 500, + 'title' => "Block Trump's attacks on immigrants", + 'rate' => 0.3333333333333333, + 'share' => 0.28571428571428575 + ) + ), + 'title' => 'No wall testing', + 'valid' => true, + 'rate' => 0.5555555555555555, + 'share' => 1.0, + 'limit' => 4.0 + ) + ), + 'overall' => Array( + 'conversions' => 500, + 'losses' => 0, + 'sent' => 1000, + 'boost' => 500, + 'rate' => 0.6666666666666666 + ) + ), $mailings->get_distributions($wpdb, $mhMock, $boost_test_value)); + } + + public function test_create_mailings_mailing_no_conversions_only_losses(): void + { + $mailings = new Mailings(); + $wpdb = new wpdb(); + $postObject = new stdClass(); + $boost_test_value = 500; + $postObject->posts = array (); + + //** must update return value from campaigns + + $campaigns = array( + 263 => array( + "conversions" => 0, + "fields" => array( + "subjects" => array ( + 0 => array ( 'subject' => 'Tell Senate: No attacks on immigrants', 'enabled' => true, ), + 1 => array ( 'subject' => "Block Trump's attacks on immigrants", 'enabled' => true, ), + ) + ), + "id" => 263, + "losses" => 0, + "sent" => 0, + "subjects" => array (), + "title" => "No wall testing", + "valid" => true + ) + ); + $postObject->posts = array(0 => (object) ['ID' => '', 'post_title'=> '']); + + $mailings_stats = array ( + 0 => array ( + 'campaign_id' => '263', + 'variation_subject' => '0', + 'conversions' => '250', + 'losses' => '250', + 'sent' => '500', ), + 1 => array ( + 'campaign_id' => '263', + 'variation_subject' => '1', + 'conversions' => '0', + 'losses' => '0', + 'sent' => '500', ) + ); + + $mhMock= $this->getMockBuilder(MailingsHelpers::class) + ->setMethods(['wp_query_posts', 'setUpCampaigns', 'get_mailings_results_wpdb', 'get_fresh_subscribers_for_campaign']) + ->getMock(); + + $mhMock->expects($this->once()) + ->method('wp_query_posts') + ->will($this->returnValue($postObject)); + + $mhMock->expects($this->once()) + ->method('setUpCampaigns') + ->will($this->returnValue($campaigns)); + + $mhMock->expects($this->once()) + ->method('get_mailings_results_wpdb') + ->will($this->returnValue($mailings_stats)); + + $mhMock->expects($this->once()) + ->method('get_fresh_subscribers_for_campaign') + ->will($this->returnValue(['6630475', '6630477', '6630478','6630479'])); + + $this->assertEquals(array( + 'campaigns' => Array( + 0 => Array( + 'conversions' => 250, + 'fields' => Array( + 'subjects' => Array( + 0 => Array( + 'subject' => 'Tell Senate: No attacks on immigrants', + 'enabled' => true + ), + 1 => Array( + 'subject' => "Block Trump's attacks on immigrants", + 'enabled' => true + ) + ) + ), + 'id' => 263, + 'losses' => 250, + 'sent' => 1000, + 'subjects' => Array( + 0 => Array( + 'conversions' => 250, + 'losses' => 250, + 'sent' => 500, + 'title' => 'Tell Senate: No attacks on immigrants', + 'rate' => 0.16666666666666666, + 'share' => 0.5 + ), + 1 => Array( + 'conversions' => 0, + 'losses' => 0, + 'sent' => 500, + 'title' => "Block Trump's attacks on immigrants", + 'rate' => 0.16666666666666666, + 'share' => 0.5 + ) + ), + 'title' => 'No wall testing', + 'valid' => true, + 'rate' => 0.1111111111111111, + 'share' => 1.0, + 'limit' => 4.0 + ) + ), + 'overall' => Array( + 'conversions' => 250, + 'losses' => 250, + 'sent' => 1000, + 'boost' => 500, + 'rate' => 0.3333333333333333 + ) + ), $mailings->get_distributions($wpdb, $mhMock, $boost_test_value)); + } + + public function test_vk_mailings_create_new_mailings_action_return_value(): void + { + $vk_mailings_mock = $this->createMock(Mailings::class); + $wpdb = new wpdb(); + + $mhMock= $this->getMockBuilder(MailingsHelpers::class) + ->setMethods(['wp_query_posts', 'setUpCampaigns', 'get_mailings_results_wpdb', 'get_fresh_subscribers_for_campaign', 'send', 'get_url']) + ->getMock(); + + $mhMock->expects($this->once()) + ->method('get_fresh_subscribers_for_campaign') + ->will($this->returnValue(['6630475', '6630477', '6630478','6630479','6630475', '6630477', '6630478','6630479', '6630475', '6630477', '6630478','6630479', '6630475', '6630477', '6630478','6630479', '6630475', '6630477', '6630478','6630479'])); + + $mhMock->expects($this->exactly(2)) + ->method('send'); + + $mhMock->expects($this->once()) + ->method('get_url') + ->willReturn('https://victorykit.local/c/no-wall-testing-2/'); + + $vk_mailings_mock->expects($this->once()) + ->method('get_distributions') + ->will($this->returnValue(Array( + 'campaigns' => Array( + 0 => Array( + 'conversions' => 500, + 'fields' => Array( + 'subjects' => Array( + 0 => Array( + 'subject' => 'Tell Senate: No attacks on immigrants', + 'enabled' => true + ), + 1 => Array( + 'subject' => "Block Trump's attacks on immigrants", + 'enabled' => true + ), + ), + 'from_line' => 41, + 'body' => '

When he ran for president, Trump promised to harass and terrorize immigrants. Now he is doing everything he can to fulfill those promises.

', + 'petition_headline' => 'Senate Democrats: Block Trump’s attacks on immigrants', + 'salutation' => '{{ user.first_name|default:"Hi" }},', + ), + 'id' => 263, + 'losses' => 0, + 'sent' => 1000, + 'subjects' => Array( + 0 => Array( + 'conversions' => 500, + 'losses' => 0, + 'sent' => 500, + 'title' => 'Tell Senate: No attacks on immigrants', + 'rate' => 0.8333333333333333, + 'share' => 0.7142857142857143 + ), + 1 => Array( + 'conversions' => 0, + 'losses' => 0, + 'sent' => 500, + 'title' => "Block Trump's attacks on immigrants", + 'rate' => 0.3333333333333333, + 'share' => 0.28571428571428575 + ) + ), + 'title' => 'No wall testing', + 'valid' => true, + 'rate' => 0.5555555555555555, + 'share' => 1.0, + 'limit' => 4.0 + ) + ), + 'overall' => Array( + 'conversions' => 500, + 'losses' => 0, + 'sent' => 1000, + 'boost' => 500, + 'rate' => 0.6666666666666666 + ) + ) + ) + ); + $this->assertEquals(Array( + 0 => Array( + 'from_line' => 41, + 'body' => '

When he ran for president, Trump promised to harass and terrorize immigrants. Now he is doing everything he can to fulfill those promises.

', + 'petition_headline' => 'Senate Democrats: Block Trump’s attacks on immigrants', + 'campaign_id' => 263, + 'limit' => 3.0, + 'salutation' => '{{ user.first_name|default:"Hi" }},', + 'subject' => 'Tell Senate: No attacks on immigrants', + 'subscribers' => Array ( + 0 => '6630475', + 1 => '6630477', + 2 => '6630478' + ), + 'url' => 'https://victorykit.local/c/no-wall-testing-2/', + 'variation_subject' => 0 + ), + 1 => Array( + 'from_line' => 41, + 'body' => '

When he ran for president, Trump promised to harass and terrorize immigrants. Now he is doing everything he can to fulfill those promises.

', + 'petition_headline' => 'Senate Democrats: Block Trump’s attacks on immigrants', + 'campaign_id' => 263, + 'limit' => 1.0, + 'salutation' => '{{ user.first_name|default:"Hi" }},', + 'subject' => "Block Trump's attacks on immigrants", + 'subscribers' => Array ( + 0 => '6630479' + ), + 'url' => 'https://victorykit.local/c/no-wall-testing-2/', + 'variation_subject' => 1 + ) + ),vk_mailings_create_new_mailings_action($vk_mailings_mock, $wpdb, $mhMock)); + } + public function test_vk_mailings_create_new_mailings_both_mailings_failing(): void + { + $vk_mailings_mock = $this->createMock(Mailings::class); + $wpdb = new wpdb(); + + $mhMock= $this->getMockBuilder(MailingsHelpers::class) + ->setMethods(['wp_query_posts', 'setUpCampaigns', 'get_mailings_results_wpdb', 'get_fresh_subscribers_for_campaign', 'send', 'get_url']) + ->getMock(); + + $mhMock->expects($this->once()) + ->method('get_fresh_subscribers_for_campaign') + ->will($this->returnValue(['6630475', '6630477', '6630478','6630479','6630475', '6630477', '6630478','6630479', '6630475', '6630477', '6630478','6630479', '6630475', '6630477', '6630478','6630479', '6630475', '6630477', '6630478','6630479'])); + + $mhMock->expects($this->exactly(0)) + ->method('send'); + + $mhMock->expects($this->once()) + ->method('get_url') + ->willReturn('https://victorykit.local/c/no-wall-testing-2/'); + + $vk_mailings_mock->expects($this->once()) + ->method('get_distributions') + ->will($this->returnValue(Array( + 'campaigns' => Array( + 0 => Array( + 'conversions' => 0, + 'fields' => Array( + 'subjects' => Array( + 0 => Array( + 'subject' => 'Tell Senate: No attacks on immigrants', + 'enabled' => true + ), + 1 => Array( + 'subject' => "Block Trump's attacks on immigrants", + 'enabled' => true + ) + ) + ), + 'id' => 263, + 'losses' => 500, + 'sent' => 1000, + 'subjects' => Array( + 0 => Array( + 'conversions' => 0, + 'losses' => 0, + 'sent' => 500, + 'title' => 'Tell Senate: No attacks on immigrants', + 'rate' => 0, + 'share' => 0 + ), + 1 => Array( + 'conversions' => 0, + 'losses' => 500, + 'sent' => 500, + 'title' => "Block Trump's attacks on immigrants", + 'rate' => 0, + 'share' => 0 + ) + ), + 'title' => 'No wall testing', + 'valid' => true, + 'rate' => 0, + 'share' => 0, + 'limit' => 0.0 + ) + ), + 'overall' => Array( + 'conversions' => 0, + 'losses' => 500, + 'sent' => 1000, + 'boost' => 500, + 'rate' => 0 + ) + ) + ) + ); + $this->assertEquals(Array(),vk_mailings_create_new_mailings_action($vk_mailings_mock, $wpdb, $mhMock)); + } + + public function test_vk_mailings_create_new_mailings_action_one_subject_50_percent_success_rate(): void + { + $vk_mailings_mock = $this->createMock(Mailings::class); + $wpdb = new wpdb(); + + $mhMock= $this->getMockBuilder(MailingsHelpers::class) + ->setMethods(['wp_query_posts', 'setUpCampaigns', 'get_mailings_results_wpdb', 'get_fresh_subscribers_for_campaign', 'send', 'get_url']) + ->getMock(); + + $mhMock->expects($this->once()) + ->method('get_fresh_subscribers_for_campaign') + ->will($this->returnValue(['6630475', '6630477', '6630478','6630479','6630475', '6630477', '6630478','6630479', '6630475', '6630477', '6630478','6630479', '6630475', '6630477', '6630478','6630479', '6630475', '6630477', '6630478','6630479'])); + + $mhMock->expects($this->exactly(2)) + ->method('send'); + + $mhMock->expects($this->once()) + ->method('get_url') + ->willReturn('https://victorykit.local/c/no-wall-testing-2/'); + + $vk_mailings_mock->expects($this->once()) + ->method('get_distributions') + ->will($this->returnValue(Array( + 'campaigns' => Array( + 0 => Array( + 'conversions' => 250, + 'fields' => Array( + 'subjects' => Array( + 0 => Array( + 'subject' => 'Tell Senate: No attacks on immigrants', + 'enabled' => true + ), + 1 => Array( + 'subject' => "Block Trump's attacks on immigrants", + 'enabled' => true + ) + ), + 'from_line' => 41, + 'body' => '

When he ran for president, Trump promised to harass and terrorize immigrants. Now he is doing everything he can to fulfill those promises.

', + 'petition_headline' => 'Senate Democrats: Block Trump’s attacks on immigrants', + 'salutation' => '{{ user.first_name|default:"Hi" }},', + ), + 'id' => 263, + 'losses' => 250, + 'sent' => 1000, + 'subjects' => Array( + 0 => Array( + 'conversions' => 250, + 'losses' => 250, + 'sent' => 500, + 'title' => 'Tell Senate: No attacks on immigrants', + 'rate' => 0.16666666666666666, + 'share' => 0.5 + ), + 1 => Array( + 'conversions' => 0, + 'losses' => 0, + 'sent' => 500, + 'title' => "Block Trump's attacks on immigrants", + 'rate' => 0.16666666666666666, + 'share' => 0.5 + ) + ), + 'title' => 'No wall testing', + 'valid' => true, + 'rate' => 0.1111111111111111, + 'share' => 1.0, + 'limit' => 4.0 + ) + ), + 'overall' => Array( + 'conversions' => 250, + 'losses' => 250, + 'sent' => 1000, + 'boost' => 500, + 'rate' => 0.3333333333333333 + ) + ) + ) + ); + $this->assertEquals(Array( + 0 => Array( + 'from_line' => 41, + 'body' => '

When he ran for president, Trump promised to harass and terrorize immigrants. Now he is doing everything he can to fulfill those promises.

', + 'petition_headline' => 'Senate Democrats: Block Trump’s attacks on immigrants', + 'campaign_id' => 263, + 'limit' => 2.0, + 'salutation' => '{{ user.first_name|default:"Hi" }},', + 'subject' => 'Tell Senate: No attacks on immigrants', + 'subscribers' => Array ( + 0 => '6630475', + 1 => '6630477' + ), + 'url' => 'https://victorykit.local/c/no-wall-testing-2/', + 'variation_subject' => 0 + ), + 1 => Array( + 'from_line' => 41, + 'body' => '

When he ran for president, Trump promised to harass and terrorize immigrants. Now he is doing everything he can to fulfill those promises.

', + 'petition_headline' => 'Senate Democrats: Block Trump’s attacks on immigrants', + 'campaign_id' => 263, + 'limit' => 2.0, + 'salutation' => '{{ user.first_name|default:"Hi" }},', + 'subject' => "Block Trump's attacks on immigrants", + 'subscribers' => Array ( + 0 => '6630478', + 1 => '6630479' + ), + 'url' => 'https://victorykit.local/c/no-wall-testing-2/', + 'variation_subject' => 1 + ) + ),vk_mailings_create_new_mailings_action($vk_mailings_mock, $wpdb, $mhMock)); + } + + + public function test_create_mailings_mailing_two_campaigns(): void + { + $mailings = new Mailings(); + $wpdb = new wpdb(); + $postObject = new stdClass(); + $boost_test_value = 500; + $postObject->posts = array (); + + $campaigns = array( + 263 => array( + "conversions" => 0, + "fields" => array( + "subjects" => array ( + 0 => array ( 'subject' => 'Tell Senate: No attacks on immigrants', 'enabled' => true, ) + ) + ), + "id" => 263, + "losses" => 0, + "sent" => 0, + "subjects" => array (), + "title" => "No wall testing", + "valid" => true + ), + 267 => array( + "conversions" => 0, + "fields" => array( + "subjects" => array ( + 0 => array ( 'subject' => 'Tell Congress: Keep my boss out of my DNA!', 'enabled' => true, ) + ) + ), + "id" => 267, + "losses" => 0, + "sent" => 0, + "subjects" => array (), + "title" => 'Genetic testing', + "valid" => true + ) + ); + $postObject->posts = array(0 => (object) ['ID' => '', 'post_title'=> '']); + + $mailings_stats = array ( + 0 => array ( + 'campaign_id' => '263', + 'variation_subject' => '0', + 'conversions' => '500', + 'losses' => '0', + 'sent' => '500', ), + 1 => array ( + 'campaign_id' => '267', + 'variation_subject' => '0', + 'conversions' => '0', + 'losses' => '500', + 'sent' => '500', ) + ); + + $mhMock= $this->getMockBuilder(MailingsHelpers::class) + ->setMethods(['wp_query_posts', 'setUpCampaigns', 'get_mailings_results_wpdb', 'get_fresh_subscribers_for_campaign']) + ->getMock(); + + $mhMock->expects($this->once()) + ->method('wp_query_posts') + ->will($this->returnValue($postObject)); + + $mhMock->expects($this->once()) + ->method('setUpCampaigns') + ->will($this->returnValue($campaigns)); + + $mhMock->expects($this->once()) + ->method('get_mailings_results_wpdb') + ->will($this->returnValue($mailings_stats)); + + $mhMock->expects($this->exactly(2)) + ->method('get_fresh_subscribers_for_campaign') + ->will($this->returnValue(['6630475', '6630477', '6630478','6630479'])); + + $this->assertEquals(Array( + 'campaigns' => Array( + 0 => Array( + 'conversions' => 500, + 'fields' => Array( + 'subjects' => Array( + 0 => Array ( + 'subject' => 'Tell Senate: No attacks on immigrants', + 'enabled' => true + ) + ) + ), + 'id' => 263, + 'losses' => 0, + 'sent' => 500, + 'subjects' => Array( + 0 => Array( + 'conversions' => 500, + 'losses' => 0, + 'sent' => 500, + 'title' => 'Tell Senate: No attacks on immigrants', + 'rate' => 0.6666666666666666, + 'share' => 1.0 + ) + ), + 'title' => 'No wall testing', + 'valid' => true, + 'rate' => 0.6666666666666666, + 'share' => 1.0, + 'limit' => 4.0 + ), + 1 => Array( + 'conversions' => 0, + 'fields' => Array ( + 'subjects' => Array( + 0 => Array( + 'subject' => 'Tell Congress: Keep my boss out of my DNA!', + 'enabled' => true + ) + ) + ), + 'id' => 267, + 'losses' => 500, + 'sent' => 500, + 'subjects' => Array ( + 0 => Array( + 'conversions' => 0, + 'losses' => 500, + 'sent' => 500, + 'title' => 'Tell Congress: Keep my boss out of my DNA!', + 'rate' => 0, + 'share' => 0 + ) + ), + 'title' => 'Genetic testing', + 'valid' => true, + 'rate' => 0, + 'share' => 0.0, + 'limit' => 0.0 + ), + ), + 'overall' => Array( + 'conversions' => 500, + 'losses' => 500, + 'sent' => 1000, + 'boost' => 500, + 'rate' => 0.3333333333333333 + ) + ), $mailings->get_distributions($wpdb, $mhMock, $boost_test_value)); + } + + public function test_two_campaigns_one_subject_one_campaign_not_successful(): void + { + $vk_mailings_mock = $this->createMock(Mailings::class); + $wpdb = new wpdb(); + + $mhMock= $this->getMockBuilder(MailingsHelpers::class) + ->setMethods(['wp_query_posts', 'setUpCampaigns', 'get_mailings_results_wpdb', 'get_fresh_subscribers_for_campaign', 'send', 'get_url']) + ->getMock(); + + $mhMock->expects($this->exactly(2)) + ->method('get_fresh_subscribers_for_campaign') + ->will($this->returnValue(['6630475', '6630477', '6630478','6630479','6630475', '6630477', '6630478','6630479', '6630475', '6630477', '6630478','6630479', '6630475', '6630477', '6630478','6630479', '6630475', '6630477', '6630478','6630479'])); + + $mhMock->expects($this->once()) + ->method('send'); + + $mhMock->expects($this->exactly(2)) + ->method('get_url') + ->willReturn('https://victorykit.local/c/no-wall-testing-2/'); + + $vk_mailings_mock->expects($this->once()) + ->method('get_distributions') + ->will($this->returnValue( + Array('campaigns' => Array( + 0 => Array( + 'conversions' => 500, + 'fields' => Array( + 'from_line' => '41', + 'body' => '

When he ran for president, Trump promised to harass and terrorize immigrants. Now he is doing everything he can to fulfill those promises.

', + 'petition_headline' => 'Senate Democrats: Block Trump’s attacks on immigrants', + 'salutation' => '{{ user.first_name|default:"Hi" }},', + 'subjects' => Array( + 0 => Array ( + 'subject' => 'Tell Senate: No attacks on immigrants', + 'enabled' => true + ) + ) + ), + 'id' => 263, + 'losses' => 0, + 'sent' => 500, + 'subjects' => Array( + 0 => Array( + 'conversions' => 500, + 'losses' => 0, + 'sent' => 500, + 'title' => 'Tell Senate: No attacks on immigrants', + 'rate' => 0.6666666666666666, + 'share' => 1.0 + ) + ), + 'title' => 'No wall testing', + 'valid' => true, + 'rate' => 0.6666666666666666, + 'share' => 1.0, + 'limit' => 4.0 + ), + 1 => Array( + 'conversions' => 0, + 'fields' => Array ( + 'subjects' => Array( + 0 => Array( + 'subject' => 'Tell Congress: Keep my boss out of my DNA!', + 'enabled' => true + ) + ) + ), + 'id' => 267, + 'losses' => 500, + 'sent' => 500, + 'subjects' => Array ( + 0 => Array( + 'conversions' => 0, + 'losses' => 500, + 'sent' => 500, + 'title' => 'Tell Congress: Keep my boss out of my DNA!', + 'rate' => 0, + 'share' => 0 + ) + ), + 'title' => 'Genetic testing', + 'valid' => true, + 'rate' => 0, + 'share' => 0.0, + 'limit' => 0.0 + ), + ), + 'overall' => Array( + 'conversions' => 500, + 'losses' => 500, + 'sent' => 1000, + 'boost' => 500, + 'rate' => 0.3333333333333333 + ) + ) + ) + ); + $this->assertEquals(Array( + 0 => Array( + 'from_line' => '41', + 'body' => '

When he ran for president, Trump promised to harass and terrorize immigrants. Now he is doing everything he can to fulfill those promises.

', + 'petition_headline' => 'Senate Democrats: Block Trump’s attacks on immigrants', + 'campaign_id' => 263, + 'limit' => 4.0, + 'salutation' => '{{ user.first_name|default:"Hi" }},', + 'subject' => 'Tell Senate: No attacks on immigrants', + 'subscribers' => Array ( + 0 => '6630475', + 1 => '6630477', + 2 => '6630478', + 3 => '6630479' + ), + 'url' => 'https://victorykit.local/c/no-wall-testing-2/', + 'variation_subject' => 0 + + ) + ),vk_mailings_create_new_mailings_action($vk_mailings_mock, $wpdb, $mhMock)); + } + + public function test_two_campaigns_both_equally_successful(): void + { + $vk_mailings_mock = $this->createMock(Mailings::class); + $wpdb = new wpdb(); + + $mhMock= $this->getMockBuilder(MailingsHelpers::class) + ->setMethods(['wp_query_posts', 'setUpCampaigns', 'get_mailings_results_wpdb', 'get_fresh_subscribers_for_campaign', 'send', 'get_url']) + ->getMock(); + + $mhMock->expects($this->exactly(2)) + ->method('get_fresh_subscribers_for_campaign') + ->will($this->returnValue(['6630475', '6630477', '6630478','6630479','6630475', '6630477', '6630478','6630479', '6630475', '6630477', '6630478','6630479', '6630475', '6630477', '6630478','6630479', '6630475', '6630477', '6630478','6630479'])); + + $mhMock->expects($this->exactly(2)) + ->method('send'); + + $mhMock->expects($this->exactly(2)) + ->method('get_url') + ->willReturn('https://victorykit.local/c/no-wall-testing-2/'); + + $vk_mailings_mock->expects($this->once()) + ->method('get_distributions') + ->will($this->returnValue( + Array( + 'campaigns' => Array( + 0 => Array( + 'conversions' => 500, + 'fields' => Array( + 'from_line' => '41', + 'body' => '

When he ran for president, Trump promised to harass and terrorize immigrants. Now he is doing everything he can to fulfill those promises.

', + 'petition_headline' => 'Senate Democrats: Block Trump’s attacks on immigrants', + 'salutation' => '{{ user.first_name|default:"Hi" }},', + 'subjects' => Array( + 0 => Array ( + 'subject' => 'Tell Senate: No attacks on immigrants', + 'enabled' => true + ) + ) + ), + 'id' => 263, + 'losses' => 0, + 'sent' => 500, + 'subjects' => Array( + 0 => Array( + 'conversions' => 500, + 'losses' => 0, + 'sent' => 500, + 'title' => 'Tell Senate: No attacks on immigrants', + 'rate' => 1, + 'share' => 1 + ) + ), + 'title' => 'No wall testing', + 'valid' => true, + 'rate' => 1, + 'share' => 0.5, + 'limit' => 2.0 + ), + 1 => Array( + 'conversions' => 500, + 'fields' => Array ( + 'from_line' => '41', + 'body' => '

Imagine you just landed your dream job.

', + 'petition_headline' => 'Tell Congress: Keep my boss out of my DNA!', + 'salutation' => '{{ user.first_name|default:"Hi" }},', + 'subjects' => Array( + 0 => Array( + 'subject' => 'Tell Congress: Keep my boss out of my DNA!', + 'enabled' => true + ) + ) + ), + 'id' => 267, + 'losses' => 0, + 'sent' => 500, + 'subjects' => Array ( + 0 => Array( + 'conversions' => 500, + 'losses' => 0, + 'sent' => 500, + 'title' => 'Tell Congress: Keep my boss out of my DNA!', + 'rate' => 1, + 'share' => 1 + ) + ), + 'title' => 'Genetic testing', + 'valid' => true, + 'rate' => 1, + 'share' => 0.5, + 'limit' => 2.0 + ), + ), + 'overall' => Array( + 'conversions' => 1000, + 'losses' => 0, + 'sent' => 1000, + 'boost' => 500, + 'rate' => 1 + ) + ) + ) + ); + $this->assertEquals(Array( + 0 => Array( + 'from_line' => '41', + 'body' => '

When he ran for president, Trump promised to harass and terrorize immigrants. Now he is doing everything he can to fulfill those promises.

', + 'petition_headline' => 'Senate Democrats: Block Trump’s attacks on immigrants', + 'campaign_id' => 263, + 'limit' => 2.0, + 'salutation' => '{{ user.first_name|default:"Hi" }},', + 'subject' => 'Tell Senate: No attacks on immigrants', + 'subscribers' => Array ( + 0 => '6630475', + 1 => '6630477' + ), + 'url' => 'https://victorykit.local/c/no-wall-testing-2/', + 'variation_subject' => 0 + + ), + 1 => Array( + 'from_line' => '41', + 'body' => '

Imagine you just landed your dream job.

', + 'petition_headline' => 'Tell Congress: Keep my boss out of my DNA!', + 'campaign_id' => 267, + 'limit' => 2.0, + 'salutation' => '{{ user.first_name|default:"Hi" }},', + 'subject' => 'Tell Congress: Keep my boss out of my DNA!', + 'subscribers' => Array ( + 0 => '6630475', + 1 => '6630477' + ), + 'url' => 'https://victorykit.local/c/no-wall-testing-2/', + 'variation_subject' => 0 + + ) + ),vk_mailings_create_new_mailings_action($vk_mailings_mock, $wpdb, $mhMock)); + } + } \ No newline at end of file diff --git a/addons/tests/singleCampaign.php b/addons/tests/singleCampaign.php new file mode 100644 index 0000000..a950bc6 --- /dev/null +++ b/addons/tests/singleCampaign.php @@ -0,0 +1,118 @@ + array ( + 0 => array ( + 'conversions' => 0, + 'fields' => array ( + 'subjects' => array ( + 0 => array ( + 'subject' => 'Tell Senate: No attacks on immigrants', + 'enabled' => true, + ), + 1 => array ( + 'subject' => "Block Trump's attacks on immigrants", + 'enabled' => true, + ), + ), + 'salutation' => '{{ user.first_name|default:"Hi" }},', + 'body' => '

When he ran for president, Trump promised to harass and terrorize immigrants. Now he is doing everything he can to fulfill those promises.

Already he has banned Muslims and refugees, threatened sanctuary cities and criminalized millions of undocumented immigrants. His Immigration and Custom Enforcement (ICE) and Border Patrol agents are separating parents from their children, deporting innocent people and spreading fear in immigrant communities across the country. The budget he just released slashes funding for the social safety net in order to spend billions of dollars building his wall, increasing his deportation force and expediting deportations.

Senate Democrats have the power to block funding for Trump’s wall and his massive deportation force. Recent reports show they may be willing to fight to stop Trump’s hateful agenda. Can you help make sure they stand strong?

We cannot let any Senate Democrat cave to political pressure from the right-wing and give Republicans the 60 votes they need to fund Trump’s hate. That is where progressives come in. We have to show Democratic senators that we will have their backs if they act boldly and that we will hold them accountable if they fail to stand up for immigrants.

Tell Senate Democrats: Block funding for Trump’s attacks on immigrants. Click here to sign the petition.

Trump wants to harass, deport and reject people who have come or are dreaming of coming to the United States seeking refuge from conflict, lives free from persecution and better economic opportunities for their families. For as long as Trump is president and extremist right-wing Republicans are willing to enable his agenda, Senate Democrats will have a choice: enable Trump’s agenda of criminalization and deportations, or resist and obstruct his racist regime at every turn. It is up to make sure they do the right thing.

Tell Senate Democrats: Block funding for Trump’s attacks on immigrants.

', + 'petition_text' => '

“Block funding for Trump’s attacks on immigrants, including his deportation force and his border wall. “

', + 'disclaimer' => '

We do not share your email address without your permission. We may send you updates on this and other important campaigns by email. If at any time you would like to unsubscribe from our email list, you may do so.

', + 'share_titles' => array ( + 0 => array ( + 'title' => 'Senate Democrats: Block Trump’s attacks on immigrants', + 'enabled' => true, + ), + 1 => array ( + 'title' => 'Block the border wall!', + 'enabled' => true, + ), + ), + 'share_descriptions' => array ( + 0 => array ( + 'description' => "There's new legislation to block Trump's border wall -- tell the Senate to pass it.", + 'enabled' => true, ), + 1 => array ( + 'description' => "The Senate can block Trump's anti-immigrant agenda, including the border wall.", + 'enabled' => true, + ), + ), + 'share_images' => array ( + 0 => array ( + 'image' => array ( + 'ID' => 203, + 'id' => 203, + 'title' => 'Logo-square', + 'filename' => 'Logo-square.png', + 'url' => 'https://victorykit.local/wp-content/uploads/2016/11/Logo-square.png', + 'alt' => '', + 'author' => '5', + 'description' => '', + 'caption' => '', + 'name' => 'logo-square', + 'date' => '2017-03-01 04:24:22', + 'modified' => '2017-03-01 04:24:22', + 'mime_type' => 'image/png', + 'type' => 'image', + 'icon' => 'http://victorykit.local/wp-includes/images/media/default.png', + 'width' => 132, + 'height' => 125, + 'sizes' => array ( + 'thumbnail' => 'https://victorykit.local/wp-content/uploads/2016/11/Logo-square.png', + 'thumbnail-width' => 132, + 'thumbnail-height' => 125, + 'medium' => 'https://victorykit.local/wp-content/uploads/2016/11/Logo-square.png', + 'medium-width' => 132, + 'medium-height' => 125, + 'medium_large' => 'https://victorykit.local/wp-content/uploads/2016/11/Logo-square.png', + 'medium_large-width' => 132, + 'medium_large-height' => 125, + 'large' => 'https://victorykit.local/wp-content/uploads/2016/11/Logo-square.png', + 'large-width' => 132, + 'large-height' => 125, + ), + ), + 'enabled' => true, + ), + ), + 'petition_headline' => 'Senate Democrats: Block Trump’s attacks on immigrants', + 'from_line' => '41', + 'landing_page_body' => '', + 'after_action_email_content' => '

Thank you for taking action. Now please share this important campaign with your friends, and ask them to join in it. This will make it much more likely we can win!

', + ), + 'id' => 263, + 'losses' => 0, + 'sent' => 0, + 'subjects' => array ( + 0 => array ( + 'conversions' => 0, + 'losses' => 0, + 'sent' => 0, + 'title' => 'Tell Senate: No attacks on immigrants', + 'rate' => 1.0, + 'share' => 0.5, + ), + 1 => array ( + 'conversions' => 0, + 'losses' => 0, + 'sent' => 0, + 'title' => "Block Trump's attacks on immigrants", + 'rate' => 1.0, + 'share' => 0.5, + ), + ), + 'title' => 'No wall testing', + 'valid' => true, + 'rate' => 1.0, + 'share' => 1.0, + 'limit' => 4.0, + ), + ), + 'overall' => array ( + 'conversions' => 0, + 'losses' => 0, + 'sent' => 0, + 'boost' => 500.0, + 'rate' => 1.0, + ), + ); \ No newline at end of file diff --git a/addons/tests/twoCampaigns.php b/addons/tests/twoCampaigns.php new file mode 100644 index 0000000..5baf521 --- /dev/null +++ b/addons/tests/twoCampaigns.php @@ -0,0 +1,188 @@ + + array ( + 0 => array ( + 'conversions' => 0, + 'fields' => array ( + 'petition_headline' => 'Senate Democrats: Block Trump’s attacks on immigrants', + 'from_line' => '41', + 'subjects' => array ( + 0 => array ( + 'subject' => 'Tell Senate: No attacks on immigrants', + 'enabled' => true, + ), 1 => array ( + 'subject' => "Block Trump's attacks on immigrants", + 'enabled' => true, + ), 2 => array ( + 'subject' => 'Protect immigrants', + 'enabled' => true, + ) + ), 'salutation' => '{{ user.first_name|default:"Hi" }},', + 'body' => '

bodyText

', + 'petition_text' => '

“Block funding for Trump’s attacks on immigrants, including his deportation force and his border wall. “

', + 'disclaimer' => '

disclaimer text

', + 'share_titles' => array ( + 0 => array ( + 'title' => 'Senate Democrats: Block Trump’s attacks on immigrants', + 'enabled' => true, + ), 1 => array ( + 'title' => 'Block the border wall!', + 'enabled' => true, ) + ), + 'share_descriptions' => array ( + 0 => array ( + 'description' => "There's new legislation to block Trump's border wall -- tell the Senate to pass it.", + 'enabled' => true, + ), 1 => array ( + 'description' => "The Senate can block Trump's anti-immigrant agenda, including the border wall.", + 'enabled' => true, ), + ), + 'share_images' => array ( + 0 => array ( + 'image' => array ( + 'ID' => 203, + 'id' => 203, + 'title' => 'Logo-square', + 'filename' => 'Logo-square.png', + 'url' => 'https://victorykit.local/wp-content/uploads/2016/11/Logo-square.png', 'alt' => '', + 'author' => '5', + 'description' => '', + 'caption' => '', + 'name' => 'logo-square', + 'date' => '2017-03-01 04:24:22', + 'modified' => '2017-03-01 04:24:22', + 'mime_type' => 'image/png', + 'type' => 'image', + 'icon' => 'http://victorykit.local/wp-includes/images/media/default.png', 'width' => 132, + 'height' => 125, + 'sizes' => array ( + 'thumbnail' => 'https://victorykit.local/wp-content/uploads/2016/11/Logo-square.png', 'thumbnail-width' => 132, + 'thumbnail-height' => 125, + 'medium' => 'https://victorykit.local/wp-content/uploads/2016/11/Logo-square.png', 'medium-width' => 132, + 'medium-height' => 125, + 'medium_large' => 'https://victorykit.local/wp-content/uploads/2016/11/Logo-square.png', 'medium_large-width' => 132, + 'medium_large-height' => 125, + 'large' => 'https://victorykit.local/wp-content/uploads/2016/11/Logo-square.png', 'large-width' => 132, + 'large-height' => 125, + ), + ), 'enabled' => true, + ), + ), + 'after_action_email_content' => '

Thank you for taking action. Now please share this important campaign with your friends, and ask them to join in it. This will make it much more likely we can win!

', + ), + 'id' => 219, + 'losses' => 0, + 'sent' => 4, + 'subjects' => array ( + 0 => array ( + 'conversions' => 0, + 'losses' => 0, + 'sent' => 2, + 'title' => 'Tell Senate: No attacks on immigrants', + 'rate' => 0.98615439233166335, + 'share' => 0.33288948069241009, + ), 1 => array ( + 'conversions' => 0, + 'losses' => 0, + 'sent' => 2, + 'title' => "Block Trump's attacks on immigrants", + 'rate' => 0.98615439233166335, + 'share' => 0.33288948069241009, ), + 2 => array ( + 'conversions' => 0, + 'losses' => 0, + 'sent' => 0, + 'title' => 'Protect immigrants', + 'rate' => 0.99009900990099009, + 'share' => 0.33422103861517977, + ), + ), + 'title' => 'No wall testing', + 'valid' => true, + 'rate' => 0.9822410812509822, + 'share' => 10.0, + 'limit' => 0, + ), 1 => array ( + 'conversions' => 0, + 'fields' => array ( + 'subjects' => array ( + 0 => array ( + 'subject' => 'Protect the Supreme Court', + 'enabled' => true, ), + 1 => array ( + 'subject' => "Stop Trump's takeover of the Supreme Court", + 'enabled' => true, ), + ), + 'salutation' => '{{ user.first_name|default:"Hi" }','body' => '

bodyText

', 'call_to_action_intro' => '

Submit a public comment to the CFPB: Issue the strongest possible rules to crack down on predatory payday lenders!

', + 'call_to_action_button' => 'SIGN NOW', 'petition_text' => '

“Defend the Supreme Court from Donald Trump’s racist, fascist agenda. Do not vote to confirm Neil Gorsuch or for cloture to end Sen. Merkley’s filibuster of his confirmation.”

', + 'statement_headline' => '', + 'statement_text' => '', + 'form_headline' => '', + 'disclaimer' => '', + 'share_titles' => array ( + 0 => array ( + 'title' => 'Tell the Senate: Block Gorsuch!', + 'enabled' => true, + ), 1 => array ( + 'title' => "Stop Trump's takeover of the Supreme Court!", + 'enabled' => true, + ), 2 => array ( + 'title' => 'Block Gorsuch!', 'enabled' => true, + ), 3 => array ( + 'title' => "Tell the Senate: Stop Trump's takeover of the Supreme Court!", + 'enabled' => true, ), + ), + 'share_descriptions' => array ( + 0 => array ( + 'description' => 'Neil Gorsuch will swing the Supreme Court to the far right. We can stop him.', + 'enabled' => true, + ), 1 => array ( + 'description' => 'Democrats need to stand strong and prevent the Supreme Court from taking a sharp right turn', 'enabled' => true, ), + ), + 'share_images' => + array ( + 0 => array ( + 'image' => false, + 'enabled' => true, + ), + ), + 'petition_headline' => 'Testing', + 'from_line' => '41', + 'after_action_email_content' => '

Thank you for taking action. Now please share this important campaign with your friends, and ask them to join in it. This will make it much more likely we can win!

', + ), + 'id' => 212, + 'losses' => 0, + 'sent' => 1, + 'subjects' => array ( + 0 => array ( + 'conversions' => 0, + 'losses' => 0, + 'sent' => 1, + 'title' => 'Protect the Supreme Court', + 'rate' => 0.98812276437224555, + 'share' => 0.49950049950049946, + ), + 1 => array ( + 'conversions' => 0, + 'losses' => 0, + 'sent' => 0, + 'title' => "Stop Trump's takeover of the Supreme Court", + 'rate' => 0.99009900990099009, + 'share' => 0.50049950049950054, + ), + ), + 'title' => 'stop the fcc', + 'valid' => true, 'rate' => 0.98812276437224555, 'share' => 0.0, + 'limit' => 0, + ), + ), + 'overall' => + array ( + 'conversions' => 0, + 'losses' => 0, + 'sent' => 5, + 'boost' => 500, + 'rate' => 0.99009900990099009, + ), + ); \ No newline at end of file diff --git a/addons/tests/twoSubjectCampaign.php b/addons/tests/twoSubjectCampaign.php new file mode 100644 index 0000000..7eb92d4 --- /dev/null +++ b/addons/tests/twoSubjectCampaign.php @@ -0,0 +1,118 @@ + array ( + 0 => array ( + 'conversions' => 0, + 'fields' => array ( + 'subjects' => array ( + 0 => array ( + 'subject' => 'Tell Senate: No attacks on immigrants', + 'enabled' => true, + ), + 1 => array ( + 'subject' => "Block Trump's attacks on immigrants", + 'enabled' => true, + ), + ), + 'salutation' => '{{ user.first_name|default:"Hi" }},', + 'body' => '

When he ran for president, Trump promised to harass and terrorize immigrants. Now he is doing everything he can to fulfill those promises.

Already he has banned Muslims and refugees, threatened sanctuary cities and criminalized millions of undocumented immigrants. His Immigration and Custom Enforcement (ICE) and Border Patrol agents are separating parents from their children, deporting innocent people and spreading fear in immigrant communities across the country. The budget he just released slashes funding for the social safety net in order to spend billions of dollars building his wall, increasing his deportation force and expediting deportations.

Senate Democrats have the power to block funding for Trump’s wall and his massive deportation force. Recent reports show they may be willing to fight to stop Trump’s hateful agenda. Can you help make sure they stand strong?

We cannot let any Senate Democrat cave to political pressure from the right-wing and give Republicans the 60 votes they need to fund Trump’s hate. That is where progressives come in. We have to show Democratic senators that we will have their backs if they act boldly and that we will hold them accountable if they fail to stand up for immigrants.

Tell Senate Democrats: Block funding for Trump’s attacks on immigrants. Click here to sign the petition.

Trump wants to harass, deport and reject people who have come or are dreaming of coming to the United States seeking refuge from conflict, lives free from persecution and better economic opportunities for their families. For as long as Trump is president and extremist right-wing Republicans are willing to enable his agenda, Senate Democrats will have a choice: enable Trump’s agenda of criminalization and deportations, or resist and obstruct his racist regime at every turn. It is up to make sure they do the right thing.

Tell Senate Democrats: Block funding for Trump’s attacks on immigrants.

', + 'petition_text' => '

“Block funding for Trump’s attacks on immigrants, including his deportation force and his border wall. “

', + 'disclaimer' => '

We do not share your email address without your permission. We may send you updates on this and other important campaigns by email. If at any time you would like to unsubscribe from our email list, you may do so.

', + 'share_titles' => array ( + 0 => array ( + 'title' => 'Senate Democrats: Block Trump’s attacks on immigrants', + 'enabled' => true, + ), + 1 => array ( + 'title' => 'Block the border wall!', + 'enabled' => true, + ), + ), + 'share_descriptions' => array ( + 0 => array ( + 'description' => "There's new legislation to block Trump's border wall -- tell the Senate to pass it.", + 'enabled' => true, ), + 1 => array ( + 'description' => "The Senate can block Trump's anti-immigrant agenda, including the border wall.", + 'enabled' => true, + ), + ), + 'share_images' => array ( + 0 => array ( + 'image' => array ( + 'ID' => 203, + 'id' => 203, + 'title' => 'Logo-square', + 'filename' => 'Logo-square.png', + 'url' => 'https://victorykit.local/wp-content/uploads/2016/11/Logo-square.png', + 'alt' => '', + 'author' => '5', + 'description' => '', + 'caption' => '', + 'name' => 'logo-square', + 'date' => '2017-03-01 04:24:22', + 'modified' => '2017-03-01 04:24:22', + 'mime_type' => 'image/png', + 'type' => 'image', + 'icon' => 'http://victorykit.local/wp-includes/images/media/default.png', + 'width' => 132, + 'height' => 125, + 'sizes' => array ( + 'thumbnail' => 'https://victorykit.local/wp-content/uploads/2016/11/Logo-square.png', + 'thumbnail-width' => 132, + 'thumbnail-height' => 125, + 'medium' => 'https://victorykit.local/wp-content/uploads/2016/11/Logo-square.png', + 'medium-width' => 132, + 'medium-height' => 125, + 'medium_large' => 'https://victorykit.local/wp-content/uploads/2016/11/Logo-square.png', + 'medium_large-width' => 132, + 'medium_large-height' => 125, + 'large' => 'https://victorykit.local/wp-content/uploads/2016/11/Logo-square.png', + 'large-width' => 132, + 'large-height' => 125, + ), + ), + 'enabled' => true, + ), + ), + 'petition_headline' => 'Senate Democrats: Block Trump’s attacks on immigrants', + 'from_line' => '41', + 'landing_page_body' => '', + 'after_action_email_content' => '

Thank you for taking action. Now please share this important campaign with your friends, and ask them to join in it. This will make it much more likely we can win!

', + ), + 'id' => 263, + 'losses' => 0, + 'sent' => 0, + 'subjects' => array ( + 0 => array ( + 'conversions' => 0, + 'losses' => 0, + 'sent' => 0, + 'title' => 'Tell Senate: No attacks on immigrants', + 'rate' => 1.0, + 'share' => 0, + ), + 1 => array ( + 'conversions' => 0, + 'losses' => 0, + 'sent' => 0, + 'title' => "Block Trump's attacks on immigrants", + 'rate' => 1.0, + 'share' => 0.5, + ), + ), + 'title' => 'No wall testing', + 'valid' => true, + 'rate' => 1.0, + 'share' => 1.0, + 'limit' => 4.0, + ), + ), + 'overall' => array ( + 'conversions' => 0, + 'losses' => 0, + 'sent' => 0, + 'boost' => 500.0, + 'rate' => 1.0, + ), + ); \ No newline at end of file diff --git a/constants.php b/constants.php new file mode 100644 index 0000000..53b3bd5 --- /dev/null +++ b/constants.php @@ -0,0 +1,3 @@ +Hi Francine,

"; // TODO: Salutation doesnt seem to actually be used anywhere $fields['body'] = get_field('body', $post->ID); $fields['petition_headline'] = get_post_meta($post->ID, 'petition_headline', true); -$html = $vk_mailings->render($fields); +$html = $mh->render($fields); echo $html; ?> diff --git a/single-campaign.php b/single-campaign.php index 454230d..c725a4e 100644 --- a/single-campaign.php +++ b/single-campaign.php @@ -1,6 +1,7 @@ ID, 'ak_page_short_name', true); +$VK_LIST_ID = VK_LIST_ID; + $source = 'website'; if (isset($_GET['source'])) { $source = htmlspecialchars($_GET['source']);