/** * @param array $config */ public function __construct($config = array()) { // @todo If running unit tests, we can just skip adding this action $priority = 9; // because WP_Customize_Widgets::register_settings() happens at after_setup_theme priority 10 add_action('after_setup_theme', array($this, 'init'), $priority); parent::__construct(); // autoload classes and set $slug, $dir_path, and $dir_url vars $default_config = array('disable_widgets_init' => false, 'disable_widgets_factory' => false, 'active_modules' => array('non_autoloaded_widget_options' => !$this->is_wpcom_vip_prod(), 'widget_number_incrementing' => true, 'https_resource_proxy' => true, 'widget_posts' => true, 'optimized_widget_registration' => false, 'deferred_customize_widgets' => true), 'https_resource_proxy' => HTTPS_Resource_Proxy::default_config(), 'widget_posts' => Widget_Posts::default_config(), 'memory_limit' => '256M', 'max_memory_usage_percentage' => 0.75); $this->config = array_merge($default_config, $config); }
/** * @see HTTPS_Resource_Proxy::send_proxy_response() * @see HTTPS_Resource_Proxy::handle_proxy_request() */ function test_send_proxy_response_successes() { $instance = new HTTPS_Resource_Proxy($this->plugin); add_filter('https_resource_proxy_filtering_enabled', '__return_true'); $params = array('nonce' => wp_create_nonce(HTTPS_Resource_Proxy::MODULE_SLUG), 'host' => 'example.org', 'path' => '/main.js'); $this->filter_pre_http_request(array('headers' => array('content-type' => 'text/javascript', 'etag' => '"abc123"', 'last-modified' => gmdate('r', time() - 10), 'expires' => gmdate('r', time() + 10), 'x-foo' => 'bar'), 'body' => 'alert( 1 );')); $r1 = $instance->send_proxy_response($params); $this->assertArrayHasKey('response', $r1); $this->assertArrayHasKey('headers', $r1); $this->assertArrayHasKey('body', $r1); $this->assertEquals(200, wp_remote_retrieve_response_code($r1)); $this->assertNotEmpty(wp_remote_retrieve_body($r1)); $this->assertArrayHasKey('etag', $r1['headers']); $this->assertArrayNotHasKey('x-foo', $r1['headers']); remove_all_filters('pre_http_request'); add_filter('pre_http_request', function () { throw new Exception('pre_http_request should not have been called due to transient'); }); $r2 = $instance->send_proxy_response($params); $this->assertEquals($r1, $r2); $params['if_modified_since'] = $r1['headers']['last-modified']; $r3 = $instance->send_proxy_response($params); $this->assertEquals(304, wp_remote_retrieve_response_code($r3)); $this->assertEmpty(wp_remote_retrieve_body($r3)); unset($params['if_modified_since']); $params['if_none_match'] = '"abc123"'; $r4 = $instance->send_proxy_response($params); $this->assertEquals(304, wp_remote_retrieve_response_code($r4)); }