Fix issues with retrieving google maps API key#217
Conversation
|
nice! - thank you for this. I hadn't yet tested against the 4.x version directly however this is a spot that potentially touches the UI code that would have been affected. |
|
Happy to create tests. Do you use mock servers in the testing? Or can you give me the URLs of live servers? Otherwise I can just mock some data and test against that. |
|
in the phpunit unit tests they are just mocked. there is an integration test suite that uses testcafe + mockoon to emulate the BMLT api, but that might take a bit more to get your head around. just do the unit ones and i can look at the integration tests as I'll create a 4.x endpoint to test against. |
|
Will do! |
|
I need some help on how to mock this, because I can't seem to mock the internal calls to Here's what I have in IntegrationTest.php: public function test_getGmapsKey() {
$mock_body_v3 = '<html>...stuff...\n "google_api_key":"test-api-key",\n...more stuff...\n</html>,';
$mock_body_v4 = '<html>...stuff...\n googleApiKey: \'test-api-key\',\n...more stuff...\n</html>,';
$mock_body_bad = 'something unexpected';
Functions\when('get_option')->justReturn('');
Functions\when('\update_option')->justReturn(true);
Functions\when('authenticateRootServerv2')->justReturn('ok');
Functions\when('getv2')->justReturn('ok');
Functions\when('\wp_remote_retrieve_body')->justReturn($mock_body_bad);
$integration = new Integration(true, "3.0.0", 'token', time()+2000);
$result = $integration->getGmapsKey();
$this->assertEquals('', $result);
Functions\when('\wp_remote_retrieve_body')->justReturn($mock_body_v3);
$integration = new Integration(true, "3.0.0", 'token', time()+2000);
$result = $integration->getGmapsKey();
$this->assertEquals('test-api-key', $result);
Functions\when('\wp_remote_retrieve_body')->justReturn($mock_body_v4);
$integration = new Integration(true, "4.0.0", 'token', time()+2000);
$result = $integration->getGmapsKey();
$this->assertEquals('test-api-key', $result);
} |
|
The issue is you can't mock the internal calls directly, but you can mock the subsequent wordpress calls with Functions\when. The other issue you have (which is not your fault :) is that there's some smarts being done to mock out the authentication retrieval. Use something like this to get around it: |
The response to the get call is not a string; its body is a string.
Now we look for a pattern that matches both old and new server versions.
3e03f71 to
454b333
Compare
|
Thanks, that was the advice I needed! Tests are now added and I think this is ready to merge. |
nigel-bmlt
left a comment
There was a problem hiding this comment.
awesome! thank you for this!
There are two issues in v1.1.34 with retrieving the Google Maps API key from the BMLT server: