/** * Test save_settings_with_publish_snapshot. * * @covers CustomizeSnapshots\Customize_Snapshot_Manager::save_settings_with_publish_snapshot() */ public function test_save_settings_with_publish_snapshot() { $post_type = $this->manager->post_type; $data = array('blogdescription' => array('value' => 'Snapshot blog'), 'unknown_setting_foo' => array('value' => 'bar'), 'null_value_baz' => array('value' => null), 'foo' => array('value' => 'foo')); $validate_data = array('blogdescription' => array('value' => 'Snapshot blog'), 'unknown_setting_foo' => array('value' => 'bar', 'publish_error' => 'unrecognized_setting'), 'null_value_baz' => array('value' => null, 'publish_error' => 'null_value'), 'foo' => array('value' => 'foo')); if (method_exists('WP_Customize_Setting', 'validate')) { $validate_data['foo']['publish_error'] = 'you_shell_not_pass'; add_filter('customize_validate_foo', function ($validity) { $validity->add('you_shell_not_pass', 'Testing invalid setting while publishing snapshot'); return $validity; }, 10, 1); } $post_id = $post_type->save(array('uuid' => self::UUID, 'data' => $data, 'status' => 'draft')); // Test invalid settings. $post = get_post($post_id); $this->manager->save_settings_with_publish_snapshot('publish', 'draft', $post); $post = get_post($post_id); $this->assertEquals($validate_data, json_decode(wp_unslash($post->post_content), true)); $this->assertEquals('pending', $post->post_status); // Test valid settings. unset($data['unknown_setting_foo'], $data['null_value_baz'], $data['foo']); $post_id = $post_type->save(array('uuid' => self::UUID, 'data' => $data, 'status' => 'publish')); $this->assertEquals('publish', get_post_status($post_id)); $this->assertEquals('Snapshot blog', get_bloginfo('description')); }