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()); }