assertSame( $expected, $file->headers[ $header_field ] );
}
/**
* Provide test cases for `test_header_parsing()`.
*
* @return array
*/
public function data_header_parsing() {
return array(
'single content type header works' => array(
'mocked_response_single_header_values',
'content-type',
'application/rss+xml; charset=UTF-8',
),
'single generic header works' => array(
'mocked_response_single_header_values',
'link',
'; rel="https://api.w.org/"',
),
'only the final content-type header should be used' => array(
'mocked_response_multiple_header_values',
'content-type',
'application/rss+xml; charset=UTF-8',
),
'multiple generic header values should be merged into a comma separated string' => array(
'mocked_response_multiple_header_values',
'link',
'; rel="https://api.w.org/", ; rel="alternate"; type="application/json"',
),
);
}
/**
* Mock a feed HTTP response where headers only have one value.
*/
public function mocked_response_single_header_values() {
$single_value_headers = array(
'content-type' => 'application/rss+xml; charset=UTF-8',
'link' => '; rel="https://api.w.org/"',
);
return array(
'headers' => new Requests_Utility_CaseInsensitiveDictionary( $single_value_headers ),
'body' => file_get_contents( DIR_TESTDATA . '/feed/wordpress-org-news.xml' ),
'response' => array(
'code' => 200,
'message' => 'OK',
),
'cookies' => array(),
'filename' => null,
);
}
/**
* Mock a feed HTTP response where headers have multiple values.
*/
public function mocked_response_multiple_header_values() {
$response = $this->mocked_response_single_header_values();
$multiple_value_headers = array(
'content-type' => array(
'application/rss+xml; charset=ISO-8859-2',
'application/rss+xml; charset=UTF-8',
),
'link' => array(
'; rel="https://api.w.org/"',
'; rel="alternate"; type="application/json"',
),
);
$response['headers'] = new Requests_Utility_CaseInsensitiveDictionary( $multiple_value_headers );
return $response;
}
}