/**
  * @covers FrmDb::migrate_to_17
  */
 function test_migrate_from_12_to_17()
 {
     $this->frm_install();
     update_option('frm_db_version', 12);
     $form = FrmForm::getOne('contact-db12');
     $this->assertNotEmpty($form);
     $this->assertTrue(is_numeric($form->id));
     $notification = array(0 => array('email_to' => '*****@*****.**', 'also_email_to' => array(1, 2), 'reply_to' => '*****@*****.**', 'reply_to_name' => 'Reply to me', 'cust_reply_to' => '', 'cust_reply_to_name' => '', 'plain_text' => 1, 'email_message' => 'This is my email message. [default-message]', 'email_subject' => 'The subject', 'update_email' => 2, 'inc_user_info' => 1));
     $form->options['notification'] = $notification;
     global $wpdb;
     $updated = $wpdb->update($wpdb->prefix . 'frm_forms', array('options' => maybe_serialize($form->options)), array('id' => $form->id));
     FrmForm::clear_form_cache();
     $this->assertEquals($updated, 1);
     $form = FrmForm::getOne('contact-db12');
     $this->assertNotEmpty($form->options, 'The form settings are empty');
     $this->assertTrue(isset($form->options['notification']), 'The old notification settings are missing');
     $this->assertEquals($form->options['notification'][0]['email_to'], '*****@*****.**');
     // migrate data
     FrmAppController::install();
     $form_actions = FrmFormAction::get_action_for_form($form->id, 'email');
     foreach ($form_actions as $action) {
         $this->assertTrue(strpos($action->post_content['email_to'], '*****@*****.**') !== false);
     }
 }
 /**
  * Migrate settings from form->options into new action.
  */
 public function migrate_to_2($form, $update = 'update')
 {
     $action = $this->prepare_new($form->id);
     $form->options = maybe_unserialize($form->options);
     // fill with existing options
     foreach ($action->post_content as $name => $val) {
         if (isset($form->options[$name])) {
             $action->post_content[$name] = $form->options[$name];
             unset($form->options[$name]);
         }
     }
     $action = $this->migrate_values($action, $form);
     // check if action already exists
     $post_id = get_posts(array('name' => $action->post_name, 'post_type' => FrmFormActionsController::$action_post_type, 'post_status' => $action->post_status, 'numberposts' => 1));
     if (empty($post_id)) {
         // create action now
         $post_id = $this->save_settings($action);
     }
     if ($post_id && 'update' == $update) {
         global $wpdb;
         $form->options = maybe_serialize($form->options);
         // update form options
         $wpdb->update($wpdb->prefix . 'frm_forms', array('options' => $form->options), array('id' => $form->id));
         FrmForm::clear_form_cache();
     }
     return $post_id;
 }