update_settings() static public method

static public update_settings ( $new_settings )
 function test_detects_if_exceeded_queue_size_limit_and_oldest_item_gt_15_mins()
 {
     $this->listener->get_sync_queue()->reset();
     // first, let's try overriding the default queue limit
     $this->assertEquals(Jetpack_Sync_Defaults::$default_max_queue_size, $this->listener->get_queue_size_limit());
     $this->assertEquals(Jetpack_Sync_Defaults::$default_max_queue_lag, $this->listener->get_queue_lag_limit());
     // set max queue size to 2 items
     Jetpack_Sync_Settings::update_settings(array('max_queue_size' => 2));
     // set max queue age to 3 seconds
     Jetpack_Sync_Settings::update_settings(array('max_queue_lag' => 3));
     $this->listener->set_defaults();
     // should pick up new queue size limit
     $this->assertEquals(2, $this->listener->get_queue_size_limit());
     $this->assertEquals(3, $this->listener->get_queue_lag_limit());
     $this->assertEquals(0, $this->listener->get_sync_queue()->size());
     // now let's try exceeding the new limit
     add_action('my_action', array($this->listener, 'action_handler'));
     $this->listener->force_recheck_queue_limit();
     do_action('my_action');
     $this->assertEquals(1, $this->listener->get_sync_queue()->size());
     $this->listener->force_recheck_queue_limit();
     do_action('my_action');
     $this->assertEquals(2, $this->listener->get_sync_queue()->size());
     $this->listener->force_recheck_queue_limit();
     do_action('my_action');
     $this->assertEquals(3, $this->listener->get_sync_queue()->size());
     // sleep for 3 seconds, so the oldest item in the queue is at least 3 seconds old -
     // now our queue limit should kick in
     sleep(3);
     $this->listener->force_recheck_queue_limit();
     do_action('my_action');
     $this->assertEquals(3, $this->listener->get_sync_queue()->size());
     remove_action('my_action', array($this->listener, 'action_handler'));
 }
 function test_settings_disable_enqueue_and_clears_queue()
 {
     $event = $this->server_event_storage->reset();
     // create a post - this will end up in the queue before data is sent
     $post_id = $this->factory->post->create();
     $this->assertTrue($this->listener->get_sync_queue()->size() > 0);
     Jetpack_Sync_Settings::update_settings(array('disable' => 1));
     // generating posts should no longer affect queue size
     $this->assertEquals(0, $this->listener->get_sync_queue()->size());
     $post_id = $this->factory->post->create();
     $this->assertEquals(0, $this->listener->get_sync_queue()->size());
     // syncing sends no data
     $this->sender->do_sync();
     $this->assertFalse($this->server_event_storage->get_most_recent_event('wp_insert_post'));
     Jetpack_Sync_Settings::update_settings(array('disable' => 0));
 }
 function test_does_not_publicize_blacklisted_post_types()
 {
     register_post_type('dont_publicize_me', array('public' => true, 'label' => 'Filter Me'));
     $post_id = $this->factory->post->create(array('post_type' => 'dont_publicize_me'));
     $this->assertTrue(apply_filters('publicize_should_publicize_published_post', true, get_post($post_id)));
     Jetpack_Sync_Settings::update_settings(array('post_types_blacklist' => array('dont_publicize_me')));
     $this->assertFalse(apply_filters('publicize_should_publicize_published_post', true, get_post($post_id)));
     $good_post_id = $this->factory->post->create(array('post_type' => 'post'));
     $this->assertTrue(apply_filters('publicize_should_publicize_published_post', true, get_post($good_post_id)));
 }
 protected function result()
 {
     $args = $this->input();
     require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-settings.php';
     $sync_settings = Jetpack_Sync_Settings::get_settings();
     foreach ($args as $key => $value) {
         if ($value !== false) {
             if (is_numeric($value)) {
                 $value = (int) $value;
             }
             // special case for sending empty arrays - a string with value 'empty'
             if ($value === 'empty') {
                 $value = array();
             }
             $sync_settings[$key] = $value;
         }
     }
     Jetpack_Sync_Settings::update_settings($sync_settings);
     // re-fetch so we see what's really being stored
     return Jetpack_Sync_Settings::get_settings();
 }
 public function test_sync_whitelisted_comment_meta()
 {
     Jetpack_Sync_Settings::update_settings(array('comment_meta_whitelist' => array()));
     $this->setSyncClientDefaults();
     // check that these values exists in the whitelist options
     $white_listed_comment_meta = Jetpack_Sync_Defaults::$comment_meta_whitelist;
     $comment_ids = $this->factory->comment->create_post_comments($this->post_id);
     // update all the comment meta
     foreach ($white_listed_comment_meta as $meta_key) {
         add_comment_meta($comment_ids[0], $meta_key, 'foo', 'comment');
     }
     $this->sender->do_sync();
     foreach ($white_listed_comment_meta as $meta_key) {
         $this->assertOptionIsSynced($meta_key, 'foo', 'comment', $comment_ids[0]);
     }
     $whitelist = Jetpack_Sync_Settings::get_setting('comment_meta_whitelist');
     $whitelist_and_option_keys_difference = array_diff($whitelist, $white_listed_comment_meta);
     // Are we testing all the options
     $unique_whitelist = array_unique($whitelist);
     $this->assertEquals(count($unique_whitelist), count($whitelist), 'The duplicate keys are: ' . print_r(array_diff_key($whitelist, array_unique($whitelist)), 1));
     $this->assertTrue(empty($whitelist_and_option_keys_difference), 'Some whitelisted options don\'t have a test: ' . print_r($whitelist_and_option_keys_difference, 1));
 }
 function test_full_sync_stops_enqueuing_at_max_queue_size()
 {
     Jetpack_Sync_Settings::update_settings(array('max_queue_size_full_sync' => 2, 'max_enqueue_full_sync' => 10));
     // this should become three items
     $synced_post_ids = $this->factory->post->create_many(25);
     $this->full_sync->start(array('posts' => true));
     // full_sync_start plus 10 posts
     $this->assertEquals(2, $this->sender->get_full_sync_queue()->size());
     // attempting to continue enqueuing shouldn't work because the queue is at max size
     $this->full_sync->continue_enqueuing();
     $this->assertEquals(2, $this->sender->get_full_sync_queue()->size());
     // flush the queue
     $this->sender->do_full_sync();
     $this->assertEquals(0, $this->sender->get_full_sync_queue()->size());
     // continue enqueuing and hit the limit again - 2 more sets of posts (10 and 5)
     $this->full_sync->continue_enqueuing();
     $this->assertEquals(2, $this->sender->get_full_sync_queue()->size());
     $this->sender->do_full_sync();
     // last one - this time just sending full_sync_end
     $this->full_sync->continue_enqueuing();
     $this->assertEquals(1, $this->sender->get_full_sync_queue()->size());
     $this->sender->do_full_sync();
     // full sync is done, continuing should do nothing
     $this->full_sync->continue_enqueuing();
     $this->assertEquals(0, $this->sender->get_full_sync_queue()->size());
 }