| | 72 | |
| | 73 | /** |
| | 74 | * @ticket https://core.trac.wordpress.org/ticket/34335 |
| | 75 | */ |
| | 76 | public function test_fetch_of_provider_with_url() { |
| | 77 | |
| | 78 | $this->_provider_url = null; |
| | 79 | add_filter( 'pre_http_request', array( $this, '_http_mock_response' ), 10, 3 ); |
| | 80 | |
| | 81 | //Discovered endpoint contains an url query variable, this should be used instead of the passed url |
| | 82 | $this->oembed->fetch( 'discovered.com/provider/endpoint?url=discovered.com/post', 'original.url', array( |
| | 83 | 'discovered' => true |
| | 84 | ) ); |
| | 85 | |
| | 86 | remove_filter( 'pre_http_request', array( $this, '_http_mock_response' ) ); |
| | 87 | |
| | 88 | //Confirm that |
| | 89 | $provider_parts = parse_url( $this->_provider_url ); |
| | 90 | parse_str( $provider_parts['query'], $query_variables ); |
| | 91 | $this->assertEquals( 'discovered.com/post', $query_variables['url'] ); |
| | 92 | } |
| | 93 | |
| | 94 | /** |
| | 95 | * @ticket https://core.trac.wordpress.org/ticket/34335 |
| | 96 | */ |
| | 97 | public function test_fetch_of_provider_without_url() { |
| | 98 | |
| | 99 | $this->_provider_url = null; |
| | 100 | add_filter( 'pre_http_request', array( $this, '_http_mock_response' ), 10, 3 ); |
| | 101 | |
| | 102 | //Discovered endpoint does not contain an url query variable, we should insert the passed url |
| | 103 | $this->oembed->fetch( 'discovered.com/provider/endpoint', 'original.url', array( |
| | 104 | 'discovered' => true |
| | 105 | ) ); |
| | 106 | |
| | 107 | remove_filter( 'pre_http_request', array( $this, '_http_mock_response' ) ); |
| | 108 | |
| | 109 | //Confirm that |
| | 110 | $provider_parts = parse_url( $this->_provider_url ); |
| | 111 | parse_str( $provider_parts['query'], $query_variables ); |
| | 112 | $this->assertEquals( 'original.url', $query_variables['url'] ); |
| | 113 | } |
| | 114 | |
| | 115 | public function _http_mock_response( $response, $request_args, $request_url ) { |
| | 116 | $this->_provider_url = $request_url; |
| | 117 | return array( |
| | 118 | 'headers' => array(), |
| | 119 | 'body' => '', |
| | 120 | 'response' => array( |
| | 121 | 'code' => 200, |
| | 122 | 'message' => '', |
| | 123 | ), |
| | 124 | 'cookies' => array(), |
| | 125 | 'filename' => false, |
| | 126 | ); |
| | 127 | } |