Created
April 6, 2015 16:34
-
-
Save joehoyle/0028c6a8444ad0af2aee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Test_Restrict_Articles extends WP_UnitTestCase { | |
function test_mr_get_article_stats_for_yahoo_ticker() { | |
add_filter( | |
'pre_http_request', | |
$this->get_http_request_overide( 'https://finance.yahoo.com/q?s=spy', | |
file_get_contents( __DIR__ . '/data/yahoo-finance-spy.html' ) | |
), 10, 3 ); | |
// this is doing a http request internally | |
$stats = mr_get_article_stats_for_yahoo_ticker(); | |
$this->assertEquals( 15, count( $stats ) ); | |
$this->assertEquals( 6, count( wp_list_filter( $stats, array( 'is_mr' => true ) ) ) ); | |
} | |
private function get_http_request_overide( $matched_url, $response_body ) { | |
$func = null; | |
return function( $return, $request, $url ) use ( $matched_url, $response_body, &$func ) { | |
remove_filter( 'pre_http_request', $func ); | |
if ( $url !== $matched_url ) { | |
return $return; | |
} | |
$response = array( | |
'headers' => array(), | |
'body' => $response_body, | |
'response' => 200, | |
); | |
return $response; | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment