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 @@ + + +// Exit if accessed directly +if(!defined('ABSPATH')) exit; + +add_action('admin_menu', 'vk_analytics_admin_page_copy'); +require_once(__DIR__. '/mockClasses/mailingsHelpers.php'); + +function vk_analytics_admin_page_copy() { + add_menu_page( + 'Insider View Page', + 'Insider View', + 'manage_options', + 'vk-insider-view', + 'vk_insider_view_admin_page_render', + 'dashicons-chart-bar', + 7 + ); +} +// 'Distributions Page', +// 'Distributions', +// 'manage_options', +// 'vk-distributions', +// 'vk_distributions_admin_page_render', +// 'dashicons-chart-bar', +// 7 + +function vk_insider_view_admin_page_render() { + global $vk_mailings, $mh; + + // Calculate distributions + $distributions = $vk_mailings->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: = get_option('subscribed_users') ?>
+Max limit to mail per day: = round($limit_per_day) ?>
+ +| Campaign id | +Name/subject | +Emails sent | +Conversions | +Losses | +Success Rate | +Current share of emails | +# users for next mailing | +
|---|---|---|---|---|---|---|---|
| = $campaign['id'] ?> | += $campaign['title'] ?> | += $campaign['sent'] ?> | += $campaign['conversions'] ?> | += $campaign['losses'] ?> | += round($campaign['rate'], 4) ?> | += round($campaign['share'], 4) ?> | += $campaign['num_fresh_ids'] ?> | +
| + | = $subject['title'] ?> | += $subject['sent'] ?> | += $subject['conversions'] ?> | += $subject['losses'] ?> | += round($subject['rate'], 4) ?> | += round($subject['share'], 4) ?> | += round($campaign['num_fresh_ids'] * $subject['share']) ?> | +
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 @@ + +$singleCampaign = 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, + ), + ), + '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 @@ + +$TwoCampaigns = array ( + 'campaigns' => + 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 @@ + +$twoSubjectCampaign = 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, + ), + ), + '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 @@ + + define('VK_LIST_ID', '25'); + define('VK_LISTS', 'VictoryKit Test'); \ No newline at end of file diff --git a/functions.php b/functions.php index 992c46d..a8c5190 100644 --- a/functions.php +++ b/functions.php @@ -15,3 +15,11 @@ require_once('addons/post-type-campaign.php'); require_once('addons/remove-wp-extras.php'); require_once('addons/sharing.php'); + +// added to run cron request on flywheel +add_filter( 'cron_request', function( $args ) { + + $args['url'] = set_url_scheme( $args['url'], 'http' ); + return $args; + + } ); diff --git a/single-campaign-preview-email.php b/single-campaign-preview-email.php index 1226c44..86c601a 100644 --- a/single-campaign-preview-email.php +++ b/single-campaign-preview-email.php @@ -10,7 +10,7 @@ $fields['salutation'] = "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 @@ global $vk_sharing; +require_once('constants.php'); // Debug if (isset($_GET['topsecretdebug']) && function_exists('top_secret_debug_function')) { top_secret_debug_function(); @@ -9,6 +10,8 @@ // Custom fields $fields = get_fields(); $ak_page_short_name = get_post_meta($post->ID, 'ak_page_short_name', true); +$VK_LIST_ID = VK_LIST_ID; + $source = 'website'; if (isset($_GET['source'])) { $source = htmlspecialchars($_GET['source']);