/** * Purge the whole cache. * * @since 1.0.0. * * @param array $purge_args Additional args to pass to the purge request. * @return array|bool|WP_Error The purge response. */ function purgely_purge_all($purge_args = array()) { $purgely = new Purgely_Purge(); $purge_args = array_merge(array('allow-all' => Purgely_Settings::get_setting('allow_purge_all')), $purge_args); $purgely->purge('all', '', $purge_args); return $purgely->get_result(); }
/** * Purge the whole cache. * * @since 1.0.0. * * @param array $purge_args Additional args to pass to the purge request. * @return array|bool|WP_Error The purge response. */ function purgely_purge_all($purge_args = array()) { $purgely = new Purgely_Purge(); $purge_args = array_merge(array('allow-all' => PURGELY_ALLOW_PURGE_ALL), $purge_args); $purgely->purge('all', '', $purge_args); return $purgely->get_result(); }
public function test_successful_purge_request_for_all_items() { $expected_result = MockData::purge_all_response_200(); $request_url = PURGELY_API_ENDPOINT . '/service/' . PURGELY_FASTLY_SERVICE_ID . '/purge_all'; // Mock the remote request \WP_Mock::wpFunction('wp_remote_request', array('args' => array($request_url, array('method' => 'POST', 'headers' => array('Fastly-Key' => PURGELY_FASTLY_KEY, 'Fastly-Soft-Purge' => 1))), 'times' => 1, 'return' => $expected_result)); \WP_Mock::wpFunction('trailingslashit', array('args' => array(PURGELY_API_ENDPOINT), 'times' => 1, 'return' => PURGELY_API_ENDPOINT . '/')); $purge = new Purgely_Purge(); $actual_result = $purge->purge('all', '', array('allow-all' => true)); $this->assertEquals($expected_result, $actual_result); $this->assertEquals($expected_result, $purge->get_response()); // The request is successful so ensure is_wp_error returns false \WP_Mock::wpFunction('is_wp_error', array('args' => array($expected_result), 'times' => 1, 'return' => false)); \WP_Mock::wpFunction('wp_remote_retrieve_response_code', array('args' => array($expected_result), 'times' => 1, 'return' => '200')); $this->assertEquals('success', $purge->get_result()); }