Skip to content

Commit f09204c

Browse files
committed
Test fix
1 parent a754379 commit f09204c

File tree

4 files changed

+74
-63
lines changed

4 files changed

+74
-63
lines changed

tests/CPClientTest.php

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -275,34 +275,40 @@ public function testRevokeTokenBadResponse(): void
275275

276276
public function testGetUser(): void
277277
{
278-
$handler = $this->createMockResponse(200, '{
279-
"data": {
280-
"userIdentity": {
281-
"id": 12345,
282-
"activeContact": {
283-
"id": 263425,
284-
"firstName": "Alice",
285-
"lastName": "Bob",
286-
"email": "[email protected]",
287-
"isWptPaidUser": true,
288-
"isWptAccountVerified": true,
289-
"companyName": null
290-
},
291-
"levelSummary": {
292-
"levelId": 3,
293-
"isWptEnterpriseClient": false
278+
$handler = $this->createMockResponse(
279+
200,
280+
'{
281+
"data": {
282+
"userIdentity": {
283+
"id": 12345,
284+
"activeContact": {
285+
"id": 263425,
286+
"firstName": "Alice",
287+
"lastName": "Bob",
288+
"email": "[email protected]",
289+
"isWptPaidUser": true,
290+
"isWptAccountVerified": true,
291+
"companyName": null
292+
},
293+
"levelSummary": {
294+
"levelId": 3,
295+
"isWptEnterpriseClient": false
296+
}
297+
},
298+
"wptCustomer": {
299+
"remainingRuns": 300,
300+
"monthlyRuns": 3000,
301+
"subscriptionId": "518235",
302+
"planRenewalDate": "2125-12-25",
303+
"status": "ACTIVE",
304+
"vatNumber": null
305+
},
306+
"wptIsPreviewEnabled": {
307+
"enabled": false
308+
}
294309
}
295-
},
296-
"wptCustomer": {
297-
"remainingRuns": 300,
298-
"monthlyRuns": 3000,
299-
"subscriptionId": "518235",
300-
"planRenewalDate": "2125-12-25",
301-
"status": "ACTIVE",
302-
"vatNumber": null
303-
}
304-
}
305-
}');
310+
}'
311+
);
306312
$host = "http://webpagetest.org";
307313
$client = new CPClient($host, array(
308314
'auth_client_options' => [
@@ -513,18 +519,18 @@ public function testGetWptPlans(): void
513519
}
514520
}');
515521

516-
$host = "http://webpagetest.org";
517-
$client = new CPClient($host, array(
518-
'auth_client_options' => [
519-
'client_id' => '123',
520-
'client_secret' => '345',
521-
'grant_type' => 'these are good to have',
522-
'handler' => $handler
523-
]
524-
));
522+
$host = "http://webpagetest.org";
523+
$client = new CPClient($host, array(
524+
'auth_client_options' => [
525+
'client_id' => '123',
526+
'client_secret' => '345',
527+
'grant_type' => 'these are good to have',
528+
'handler' => $handler
529+
]
530+
));
525531

526-
$plans = $client->getWptPlans();
527-
$this->assertEquals(3, count($plans));
532+
$plans = $client->getWptPlans();
533+
$this->assertEquals(3, count($plans));
528534
}
529535

530536

tests/RequestContextTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ public function testSetGetClient(): void
3636
$client = new CPClient($host);
3737
$request = new RequestContext($global_req);
3838
$request->setClient($client);
39-
$this->assertEquals($host, $request->getClient()->host);
39+
$this->assertEquals($host, $request->getClient()->getHost());
4040
}
4141
}

www/src/CPClient.php

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ public function isAuthenticated(): bool
102102
return !!$this->access_token;
103103
}
104104

105+
public function getHost(): ?string
106+
{
107+
return $this->host;
108+
}
109+
105110
public function login(string $code, string $code_verifier, string $redirect_uri): AuthToken
106111
{
107112
if (is_null($this->client_id) || is_null($this->client_secret)) {
@@ -316,19 +321,19 @@ public function getFullWptPlanSet(): PlanListSet
316321
return new Plan($options);
317322
}, $results->getData()['wptPlan'] ?? []);
318323

319-
$current_plans = array_filter($all_plans, function (Plan $plan) {
320-
/** This is a bit of a hack for now. These are our approved plans for new
321-
* customers to be able to use. We will better handle this from the backend
322-
* */
323-
return strtolower($plan->getId()) == 'ap5' ||
324-
strtolower($plan->getId()) == 'ap6' ||
325-
strtolower($plan->getId()) == 'ap7' ||
326-
strtolower($plan->getId()) == 'ap8' ||
327-
strtolower($plan->getId()) == 'mp5' ||
328-
strtolower($plan->getId()) == 'mp6' ||
329-
strtolower($plan->getId()) == 'mp7' ||
330-
strtolower($plan->getId()) == 'mp8';
331-
});
324+
$current_plans = array_filter($all_plans, function (Plan $plan) {
325+
/** This is a bit of a hack for now. These are our approved plans for new
326+
* customers to be able to use. We will better handle this from the backend
327+
* */
328+
return strtolower($plan->getId()) == 'ap5' ||
329+
strtolower($plan->getId()) == 'ap6' ||
330+
strtolower($plan->getId()) == 'ap7' ||
331+
strtolower($plan->getId()) == 'ap8' ||
332+
strtolower($plan->getId()) == 'mp5' ||
333+
strtolower($plan->getId()) == 'mp6' ||
334+
strtolower($plan->getId()) == 'mp7' ||
335+
strtolower($plan->getId()) == 'mp8';
336+
});
332337
$set = new PlanListSet();
333338
$set->setAllPlans(new PlanList(...$all_plans));
334339
$set->setCurrentPlans(new PlanList(...$current_plans));
@@ -1070,18 +1075,18 @@ public function updatePlan(string $subscription_id, string $next_plan_handle, bo
10701075
public function updatePaymentMethod(string $token, ShippingAddress $address): bool
10711076
{
10721077
$gql = (new Mutation('wptUpdateSubscriptionPayment'))
1073-
->setVariables([
1074-
new Variable('paymentToken', 'String', true),
1075-
new Variable('shippingAddress', 'ChargifyAddressInputType', true)
1076-
])
1077-
->setArguments([
1078-
'paymentToken' => '$paymentToken',
1079-
'shippingAddress' => '$shippingAddress'
1080-
]);
1078+
->setVariables([
1079+
new Variable('paymentToken', 'String', true),
1080+
new Variable('shippingAddress', 'ChargifyAddressInputType', true)
1081+
])
1082+
->setArguments([
1083+
'paymentToken' => '$paymentToken',
1084+
'shippingAddress' => '$shippingAddress'
1085+
]);
10811086

10821087
$variables = [
1083-
'paymentToken' => $token,
1084-
'shippingAddress' => $address->toArray()
1088+
'paymentToken' => $token,
1089+
'shippingAddress' => $address->toArray()
10851090
];
10861091

10871092
$results = $this->graphql_client->runQuery($gql, true, $variables);

www/templates/layouts/includes/wpt-header.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function addTab($tabName, $tabUrl, $addClass = '')
5050
$is_logged_in = Util::getSetting('cp_auth') && (!is_null($request_context)) && (!is_null($request_context->getClient()) && $request_context->getClient()->isAuthenticated());
5151
$user = !is_null($request_context) ? $request_context->getUser() : null;
5252

53-
if ($request_context->isReadOnly()) {
53+
if (isset($request_context) && $request_context->isReadOnly()) {
5454

5555
?>
5656
<wpt-header style='margin-bottom: -1rem;'>

0 commit comments

Comments
 (0)