/** * @see Plugin::init() */ function test_init() { $plugin = get_plugin_instance(); $plugin->init(); $this->assertEquals(11, has_action('wp_default_scripts', array($plugin, 'register_scripts'))); $this->assertEquals(11, has_action('wp_default_styles', array($plugin, 'register_styles'))); }
/** * Test init. * * @see Plugin::init() */ function test_init() { $plugin = get_plugin_instance(); $plugin->init(); $this->assertEquals(11, has_action('wp_default_scripts', array($plugin, 'register_scripts'))); $this->assertEquals(11, has_action('wp_default_styles', array($plugin, 'register_styles'))); $this->assertInstanceOf('CustomizeSnapshots\\Customize_Snapshot_Manager', $plugin->customize_snapshot_manager); }
/** * Test for init() method. * * @see Plugin::init() */ public function test_init() { $plugin = get_plugin_instance(); add_filter('customize_pane_resizer_plugin_config', array($this, 'filter_config'), 10, 2); $plugin->init(); $this->assertInternalType('array', $plugin->config); $this->assertArrayHasKey('foo', $plugin->config); $this->assertEquals(10, has_action('customize_controls_enqueue_scripts', array($plugin, 'enqeue_scripts_styles'))); }
/** * Convenience function to get the current snapshot UUID. * * @see Customize_Snapshot_Manager::$current_snapshot_uuid * * @return string|null The current snapshot UUID or null if no snapshot. */ function current_snapshot_uuid() { $customize_snapshot_uuid = get_plugin_instance()->customize_snapshot_manager->current_snapshot_uuid; if (empty($customize_snapshot_uuid)) { return null; } else { return $customize_snapshot_uuid; } }
/** * Test for init() method. * * @see Plugin::init() */ public function test_init() { $plugin = get_plugin_instance(); add_filter('customize_rest_resources_plugin_config', array($this, 'filter_config'), 10, 2); $plugin->init(); $this->assertInternalType('array', $plugin->config); $this->assertArrayHasKey('foo', $plugin->config); $this->assertEquals(11, has_action('wp_default_scripts', array($plugin, 'register_scripts'))); $this->assertEquals(11, has_action('wp_default_styles', array($plugin, 'register_styles'))); }
/** * Set up the test fixture. */ public function setUp() { parent::setUp(); $this->plugin = get_plugin_instance(); require_once ABSPATH . WPINC . '/class-wp-customize-manager.php'; $GLOBALS['wp_customize'] = new \WP_Customize_Manager(); $this->plugin->customize_concurrency->customize_manager = $GLOBALS['wp_customize']; wp_set_current_user($this->factory->user->create(array('role' => 'administrator'))); $_SERVER['REQUEST_METHOD'] = 'POST'; $_REQUEST['wp_customize'] = 'on'; }
/** * Set up. */ function setUp() { parent::setUp(); $this->plugin = get_plugin_instance(); $this->plugin->customize_snapshot_manager->post_type->register(); $snapshot_data = array(array('status' => 'draft', 'date_gmt' => '2010-01-01 00:00:00'), array('status' => 'pending', 'date_gmt' => '2010-01-01 00:00:00'), array('status' => 'publish', 'date_gmt' => '2010-01-01 00:00:00'), array('status' => 'future', 'date_gmt' => gmdate('Y-m-d H:i:s', time() + 24 * 3600))); foreach ($snapshot_data as $i => $snapshot_params) { $user_id = $this->factory()->user->create(array('role' => 'administrator')); $post_id = $this->plugin->customize_snapshot_manager->post_type->save(array_merge($snapshot_params, array('uuid' => Customize_Snapshot_Manager::generate_uuid(), 'author' => $user_id, 'data' => array('blogname' => array('value' => "Snapshot {$i}"))))); $this->snapshot_by_status[$snapshot_params['status']] = $post_id; } global $wp_rest_server; $wp_rest_server = null; $this->server = rest_get_server(); }
/** * Set up. */ function setUp() { parent::setUp(); $this->plugin = get_plugin_instance(); require_once ABSPATH . WPINC . '/class-wp-customize-manager.php'; $GLOBALS['wp_customize'] = new \WP_Customize_Manager(); // WPCS: override ok. $this->snapshot_manager = new Customize_Snapshot_Manager($this->plugin); $this->wp_customize = $GLOBALS['wp_customize']; wp_set_current_user($this->factory()->user->create(array('role' => 'administrator'))); $this->wp_customize->add_setting('foo', array('default' => 'foo_default')); $this->wp_customize->add_setting('bar', array('default' => 'bar_default')); $this->foo = $this->wp_customize->get_setting('foo'); $this->bar = $this->wp_customize->get_setting('bar'); }
function setUp() { $this->plugin = get_plugin_instance(); remove_action('widgets_init', 'twentyfourteen_widgets_init'); remove_action('customize_register', 'twentyfourteen_customize_register'); remove_all_actions('send_headers'); // prevent X-hacker header in VIP Quickstart // For why these hooks have to be removed, see https://github.com/Automattic/nginx-http-concat/issues/5 $this->css_concat_init_priority = has_action('init', 'css_concat_init'); if ($this->css_concat_init_priority) { remove_action('init', 'css_concat_init', $this->css_concat_init_priority); } $this->js_concat_init_priority = has_action('init', 'js_concat_init'); if ($this->js_concat_init_priority) { remove_action('init', 'js_concat_init', $this->js_concat_init_priority); } parent::setUp(); }
function setUp() { parent::setUp(); $this->plugin = get_plugin_instance(); require_once ABSPATH . WPINC . '/class-wp-customize-manager.php'; $GLOBALS['wp_customize'] = new \WP_Customize_Manager(); $this->plugin->customize_concurrency->customize_manager = $GLOBALS['wp_customize']; $this->user_id = $this->factory->user->create(array('role' => 'administrator')); remove_action('after_setup_theme', 'twentyfifteen_setup'); // For why these hooks have to be removed, see https://github.com/Automattic/nginx-http-concat/issues/5 $this->css_concat_init_priority = has_action('init', 'css_concat_init'); if ($this->css_concat_init_priority) { remove_action('init', 'css_concat_init', $this->css_concat_init_priority); } $this->js_concat_init_priority = has_action('init', 'js_concat_init'); if ($this->js_concat_init_priority) { remove_action('init', 'js_concat_init', $this->js_concat_init_priority); } }
/** * Testing schedule Snapshot */ function test_ajax_update_snapshot_schedule() { unset($GLOBALS['wp_customize']); remove_all_actions('wp_ajax_' . Customize_Snapshot_Manager::AJAX_ACTION); $post_type_obj = get_post_type_object(Post_Type::SLUG); $setting_key = 'anyonecanedit'; $tomorrow = date('Y-m-d H:i:s', time() + 86400); $this->set_current_user('administrator'); $this->assertTrue(current_user_can($post_type_obj->cap->publish_posts)); $this->set_input_vars(array('action' => Customize_Snapshot_Manager::AJAX_ACTION, 'nonce' => wp_create_nonce(Customize_Snapshot_Manager::AJAX_ACTION), 'customize_snapshot_uuid' => self::UUID, 'customized' => wp_json_encode(array($setting_key => 'Hello')), 'status' => 'future', 'publish_date' => $tomorrow)); $this->plugin = new Plugin(); $this->plugin->init(); $this->add_setting(); $this->make_ajax_call(Customize_Snapshot_Manager::AJAX_ACTION); $post_id = get_plugin_instance()->customize_snapshot_manager->post_type->find_post(self::UUID); $expected_results = array('success' => true, 'data' => array('errors' => null, 'setting_validities' => array($setting_key => true), 'edit_link' => get_edit_post_link($post_id, 'raw'), 'snapshot_publish_date' => $tomorrow)); require_once ABSPATH . WPINC . '/class-wp-customize-manager.php'; if (!method_exists('WP_Customize_Manager', 'prepare_setting_validity_for_js')) { unset($expected_results['data']['setting_validities']); } // Get the results. $response = json_decode($this->_last_response, true); $this->assertSame($expected_results, $response); $this->assertEquals('future', get_post_status($post_id)); }
protected function setUp() { $this->instance = get_plugin_instance("intercom"); $this->instance->icfg = array('channel' => '#test'); }
/** * Test prepare_snapshot_post_content_for_publish. * * @covers CustomizeSnapshots\Customize_Snapshot_Manager::prepare_snapshot_post_content_for_publish() */ public function test_prepare_snapshot_post_content_for_publish() { $snapshot_manager = get_plugin_instance()->customize_snapshot_manager; $data = array('blogdescription' => array('value' => 'Snapshot blog'), 'foo' => array('value' => 'bar', 'publish_error' => 'unrecognized_setting'), 'baz' => array('value' => null, 'publish_error' => 'null_value')); $validate_data = array('blogdescription' => array('value' => 'Snapshot blog'), 'foo' => array('value' => 'bar'), 'baz' => array('value' => null)); $data_without_errors = $this->manager->prepare_snapshot_post_content_for_publish(array('post_type' => Post_Type::SLUG, 'post_content' => Customize_Snapshot_Manager::encode_json($data), 'post_status' => 'publish')); $this->assertEquals($validate_data, json_decode(wp_unslash($data_without_errors['post_content']), true)); }
function setUp() { parent::setUp(); $this->plugin = get_plugin_instance(); }
/** * Test constructor. * * @see Plugin::__construct() */ public function test_construct() { $plugin = get_plugin_instance(); $this->assertEquals(10, has_action('after_setup_theme', array($plugin, 'init'))); }
/** * Snapshot publish. * * @see Post_Type::save() */ function test_publish_snapshot() { $admin_user_id = $this->factory()->user->create(array('role' => 'administrator')); wp_set_current_user($admin_user_id); $post_type = get_plugin_instance()->customize_snapshot_manager->post_type; $post_type->register(); $tag_line = 'Snapshot blog'; $data = array('blogdescription' => array('value' => $tag_line), 'foo' => array('value' => 'bar'), 'baz' => array('value' => null)); $validated_content = array('blogdescription' => array('value' => $tag_line), 'foo' => array('value' => 'bar', 'publish_error' => 'unrecognized_setting'), 'baz' => array('value' => null, 'publish_error' => 'null_value')); /* * Ensure that directly updating a post succeeds with invalid settings * works because the post is a draft. Note that if using * Customize_Snapshot::set() this would fail because it does validation. */ $post_id = $post_type->save(array('uuid' => Customize_Snapshot_Manager::generate_uuid(), 'data' => $data, 'status' => 'draft')); wp_update_post(array('ID' => $post_id, 'post_status' => 'draft')); $content = $post_type->get_post_content(get_post($post_id)); $this->assertEquals($data, $content); /* * Ensure that attempting to publish a snapshot with invalid settings * will get the publish_errors added as well as kick it back to pending. */ remove_all_filters('redirect_post_location'); $post_id = $post_type->save(array('uuid' => Customize_Snapshot_Manager::generate_uuid(), 'data' => $data, 'status' => 'draft')); wp_publish_post($post_id); $snapshot_post = get_post($post_id); $content = $post_type->get_post_content($snapshot_post); $this->assertEquals('pending', $snapshot_post->post_status); $this->assertEquals($validated_content, $content); $this->assertContains('snapshot_error_on_publish=1', apply_filters('redirect_post_location', get_edit_post_link($snapshot_post->ID), $snapshot_post->ID)); /* * Remove invalid settings and now attempt publish. */ remove_all_filters('redirect_post_location'); unset($data['foo']); unset($data['baz']); $post_id = $post_type->save(array('uuid' => Customize_Snapshot_Manager::generate_uuid(), 'data' => $data, 'status' => 'draft')); wp_publish_post($post_id); $snapshot_post = get_post($post_id); $content = $post_type->get_post_content($snapshot_post); $this->assertEquals('publish', $snapshot_post->post_status); $this->assertEquals($data, $content); $this->assertEquals($tag_line, get_bloginfo('description')); $this->assertNotContains('snapshot_error_on_publish=1', apply_filters('redirect_post_location', get_edit_post_link($snapshot_post->ID), $snapshot_post->ID)); }